Test Failed
Push — release/2.0 ( 6ea777...f7bd0b )
by Ravinder
05:21
created

admin-actions.php ➔ give_donation_import_callback()   D

Complexity

Conditions 9
Paths 80

Size

Total Lines 96
Code Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 69
nc 80
nop 0
dl 0
loc 96
rs 4.9572
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Admin Actions
4
 *
5
 * @package     Give
6
 * @subpackage  Admin/Actions
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Load wp editor by ajax.
19
 *
20
 * @since 1.8
21
 */
22
function give_load_wp_editor() {
23
	if ( ! isset( $_POST['wp_editor'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
24
		die();
25
	}
26
27
	$wp_editor                     = json_decode( base64_decode( $_POST['wp_editor'] ), true );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
28
	$wp_editor[2]['textarea_name'] = $_POST['textarea_name'];
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
29
30
	wp_editor( $wp_editor[0], $_POST['wp_editor_id'], $wp_editor[2] );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_POST
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
31
32
	die();
33
}
34
35
add_action( 'wp_ajax_give_load_wp_editor', 'give_load_wp_editor' );
36
37
38
/**
39
 * Redirect admin to clean url give admin pages.
40
 *
41
 * @since 1.8
42
 *
43
 * @return bool
44
 */
45
function give_redirect_to_clean_url_admin_pages() {
46
	// Give admin pages.
47
	$give_pages = array(
48
		'give-payment-history',
49
		'give-donors',
50
		'give-reports',
51
		'give-tools',
52
	);
53
54
	// Get current page.
55
	$current_page = isset( $_GET['page'] ) ? esc_attr( $_GET['page'] ) : '';
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
56
57
	// Bailout.
58
	if (
59
		empty( $current_page )
60
		|| empty( $_GET['_wp_http_referer'] )
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
61
		|| ! in_array( $current_page, $give_pages )
62
	) {
63
		return false;
64
	}
65
66
	/**
67
	 * Verify current page request.
68
	 *
69
	 * @since 1.8
70
	 */
71
	$redirect = apply_filters( "give_validate_{$current_page}", true );
72
73
	if ( $redirect ) {
74
		// Redirect.
75
		wp_redirect(
76
			remove_query_arg(
77
				array( '_wp_http_referer', '_wpnonce' ),
78
				wp_unslash( $_SERVER['REQUEST_URI'] )
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...
79
			)
80
		);
81
		exit;
82
	}
83
}
84
85
add_action( 'admin_init', 'give_redirect_to_clean_url_admin_pages' );
86
87
88
/**
89
 * Hide Outdated PHP Notice Shortly.
90
 *
91
 * This code is used with AJAX call to hide outdated PHP notice for a short period of time
92
 *
93
 * @since 1.8.9
94
 *
95
 * @return void
96
 */
97
function give_hide_outdated_php_notice() {
98
99
	if ( ! isset( $_POST['_give_hide_outdated_php_notices_shortly'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
100
		give_die();
101
	}
102
103
	// Transient key name.
104
	$transient_key = "_give_hide_outdated_php_notices_shortly";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal _give_hide_outdated_php_notices_shortly does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
105
106
	if ( Give_Cache::get( $transient_key, true ) ) {
107
		return;
108
	}
109
110
	// Hide notice for 24 hours.
111
	Give_Cache::set( $transient_key, true, DAY_IN_SECONDS, true );
112
113
	give_die();
114
115
}
116
117
add_action( 'wp_ajax_give_hide_outdated_php_notice', 'give_hide_outdated_php_notice' );
118
119
/**
120
 * Register admin notices.
121
 *
122
 * @since 1.8.9
123
 */
124
function _give_register_admin_notices() {
125
	// Bailout.
126
	if ( ! is_admin() ) {
127
		return;
128
	}
129
130
	// Bulk action notices.
131
	if (
132
		isset( $_GET['action'] ) &&
133
		! empty( $_GET['action'] )
134
	) {
135
136
		// Add payment bulk notice.
137
		if (
138
			current_user_can( 'edit_give_payments' ) &&
139
			isset( $_GET['payment'] ) &&
140
			! empty( $_GET['payment'] )
141
		) {
142
			$payment_count = isset( $_GET['payment'] ) ? count( $_GET['payment'] ) : 0;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
143
144
			switch ( $_GET['action'] ) {
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
145 View Code Duplication
				case 'delete':
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...
146
					Give()->notices->register_notice( array(
147
						'id'          => 'bulk_action_delete',
148
						'type'        => 'updated',
149
						'description' => sprintf(
150
							_n(
151
								'Successfully deleted one donation.',
152
								'Successfully deleted %d donations.',
153
								$payment_count,
154
								'give'
155
							),
156
							$payment_count ),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 24 spaces, but found 28.
Loading history...
157
						'show'        => true,
158
					) );
159
160
					break;
161
162 View Code Duplication
				case 'resend-receipt':
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...
163
					Give()->notices->register_notice( array(
164
						'id'          => 'bulk_action_resend_receipt',
165
						'type'        => 'updated',
166
						'description' => sprintf(
167
							_n(
168
								'Successfully sent email receipt to one recipient.',
169
								'Successfully sent email receipts to %d recipients.',
170
								$payment_count,
171
								'give'
172
							),
173
							$payment_count
174
						),
175
						'show'        => true,
176
					) );
177
					break;
178
179
				case 'set-status-publish' :
180
				case 'set-status-pending' :
181
				case 'set-status-processing' :
182
				case 'set-status-refunded' :
183
				case 'set-status-revoked' :
184
				case 'set-status-failed' :
185
				case 'set-status-cancelled' :
186
				case 'set-status-abandoned' :
187 View Code Duplication
				case 'set-status-preapproval' :
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...
188
					Give()->notices->register_notice( array(
189
						'id'          => 'bulk_action_status_change',
190
						'type'        => 'updated',
191
						'description' => _n(
192
							'Donation status updated successfully.',
193
							'Donation statuses updated successfully.',
194
							$payment_count,
195
							'give'
196
						),
197
						'show'        => true,
198
					) );
199
					break;
200
			}
201
		}
202
	}
203
204
	// Add give message notices.
205
	if ( ! empty( $_GET['give-message'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
206
		// Donation reports errors.
207
		if ( current_user_can( 'view_give_reports' ) ) {
208
			switch ( $_GET['give-message'] ) {
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
209 View Code Duplication
				case 'donation_deleted' :
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...
210
					Give()->notices->register_notice( array(
211
						'id'          => 'give-donation-deleted',
212
						'type'        => 'updated',
213
						'description' => __( 'The donation has been deleted.', 'give' ),
214
						'show'        => true,
215
					) );
216
					break;
217 View Code Duplication
				case 'email_sent' :
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...
218
					Give()->notices->register_notice( array(
219
						'id'          => 'give-payment-sent',
220
						'type'        => 'updated',
221
						'description' => __( 'The donation receipt has been resent.', 'give' ),
222
						'show'        => true,
223
					) );
224
					break;
225 View Code Duplication
				case 'refreshed-reports' :
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...
226
					Give()->notices->register_notice( array(
227
						'id'          => 'give-refreshed-reports',
228
						'type'        => 'updated',
229
						'description' => __( 'The reports cache has been cleared.', 'give' ),
230
						'show'        => true,
231
					) );
232
					break;
233 View Code Duplication
				case 'donation-note-deleted' :
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...
234
					Give()->notices->register_notice( array(
235
						'id'          => 'give-donation-note-deleted',
236
						'type'        => 'updated',
237
						'description' => __( 'The donation note has been deleted.', 'give' ),
238
						'show'        => true,
239
					) );
240
					break;
241
			}
242
		}
243
244
		// Give settings notices and errors.
245
		if ( current_user_can( 'manage_give_settings' ) ) {
246
			switch ( $_GET['give-message'] ) {
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
247 View Code Duplication
				case 'settings-imported' :
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...
248
					Give()->notices->register_notice( array(
249
						'id'          => 'give-settings-imported',
250
						'type'        => 'updated',
251
						'description' => __( 'The settings have been imported.', 'give' ),
252
						'show'        => true,
253
					) );
254
					break;
255 View Code Duplication
				case 'api-key-generated' :
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...
256
					Give()->notices->register_notice( array(
257
						'id'          => 'give-api-key-generated',
258
						'type'        => 'updated',
259
						'description' => __( 'API keys have been generated.', 'give' ),
260
						'show'        => true,
261
					) );
262
					break;
263 View Code Duplication
				case 'api-key-exists' :
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...
264
					Give()->notices->register_notice( array(
265
						'id'          => 'give-api-key-exists',
266
						'type'        => 'updated',
267
						'description' => __( 'The specified user already has API keys.', 'give' ),
268
						'show'        => true,
269
					) );
270
					break;
271 View Code Duplication
				case 'api-key-regenerated' :
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...
272
					Give()->notices->register_notice( array(
273
						'id'          => 'give-api-key-regenerated',
274
						'type'        => 'updated',
275
						'description' => __( 'API keys have been regenerated.', 'give' ),
276
						'show'        => true,
277
					) );
278
					break;
279 View Code Duplication
				case 'api-key-revoked' :
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...
280
					Give()->notices->register_notice( array(
281
						'id'          => 'give-api-key-revoked',
282
						'type'        => 'updated',
283
						'description' => __( 'API keys have been revoked.', 'give' ),
284
						'show'        => true,
285
					) );
286
					break;
287 View Code Duplication
				case 'sent-test-email' :
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...
288
					Give()->notices->register_notice( array(
289
						'id'          => 'give-sent-test-email',
290
						'type'        => 'updated',
291
						'description' => __( 'The test email has been sent.', 'give' ),
292
						'show'        => true,
293
					) );
294
					break;
295 View Code Duplication
				case 'matched-success-failure-page':
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...
296
					Give()->notices->register_notice( array(
297
						'id'          => 'give-matched-success-failure-page',
298
						'type'        => 'updated',
299
						'description' => __( 'You cannot set the success and failed pages to the same page', 'give' ),
300
						'show'        => true,
301
					) );
302
					break;
303
			}
304
		}
305
		// Payments errors.
306
		if ( current_user_can( 'edit_give_payments' ) ) {
307
			switch ( $_GET['give-message'] ) {
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
308 View Code Duplication
				case 'note-added' :
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...
309
					Give()->notices->register_notice( array(
310
						'id'          => 'give-note-added',
311
						'type'        => 'updated',
312
						'description' => __( 'The donation note has been added.', 'give' ),
313
						'show'        => true,
314
					) );
315
					break;
316 View Code Duplication
				case 'payment-updated' :
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...
317
					Give()->notices->register_notice( array(
318
						'id'          => 'give-payment-updated',
319
						'type'        => 'updated',
320
						'description' => __( 'The donation has been updated.', 'give' ),
321
						'show'        => true,
322
					) );
323
					break;
324
			}
325
		}
326
327
		// Donor Notices.
328
		if ( current_user_can( 'edit_give_payments' ) ) {
329
			switch ( $_GET['give-message'] ) {
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
330 View Code Duplication
				case 'donor-deleted' :
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...
331
					Give()->notices->register_notice( array(
332
						'id'          => 'give-donor-deleted',
333
						'type'        => 'updated',
334
						'description' => __( 'The selected donor(s) has been deleted.', 'give' ),
335
						'show'        => true,
336
					) );
337
					break;
338
339 View Code Duplication
				case 'donor-donations-deleted' :
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...
340
					Give()->notices->register_notice( array(
341
						'id'          => 'give-donor-donations-deleted',
342
						'type'        => 'updated',
343
						'description' => __( 'The selected donor(s) and its associated donations has been deleted.', 'give' ),
344
						'show'        => true,
345
					) );
346
					break;
347
348 View Code Duplication
				case 'confirm-delete-donor' :
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...
349
					Give()->notices->register_notice( array(
350
						'id'          => 'give-confirm-delete-donor',
351
						'type'        => 'updated',
352
						'description' => __( 'You must confirm to delete the selected donor(s).', 'give' ),
353
						'show'        => true,
354
					) );
355
					break;
356
357 View Code Duplication
				case 'invalid-donor-id' :
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...
358
					Give()->notices->register_notice( array(
359
						'id'          => 'give-invalid-donor-id',
360
						'type'        => 'updated',
361
						'description' => __( 'Invalid Donor ID.', 'give' ),
362
						'show'        => true,
363
					) );
364
					break;
365
366
				case 'donor-delete-failed' :
367
					Give()->notices->register_notice( array(
368
						'id'          => 'give-donor-delete-failed',
369
						'type'        => 'error',
370
						'description' => __( 'Unable to delete selected donor(s).', 'give' ),
371
						'show'        => true,
372
					) );
373
					break;
374
375 View Code Duplication
				case 'email-added' :
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...
376
					Give()->notices->register_notice( array(
377
						'id'          => 'give-donor-email-added',
378
						'type'        => 'updated',
379
						'description' => __( 'Donor email added.', 'give' ),
380
						'show'        => true,
381
					) );
382
					break;
383
384 View Code Duplication
				case 'email-removed' :
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...
385
					Give()->notices->register_notice( array(
386
						'id'          => 'give-donor-email-removed',
387
						'type'        => 'updated',
388
						'description' => __( 'Donor email removed.', 'give' ),
389
						'show'        => true,
390
					) );
391
					break;
392
393 View Code Duplication
				case 'email-remove-failed' :
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...
394
					Give()->notices->register_notice( array(
395
						'id'          => 'give-donor-email-remove-failed',
396
						'type'        => 'updated',
397
						'description' => __( 'Failed to remove donor email.', 'give' ),
398
						'show'        => true,
399
					) );
400
					break;
401
402 View Code Duplication
				case 'primary-email-updated' :
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...
403
					Give()->notices->register_notice( array(
404
						'id'          => 'give-donor-primary-email-updated',
405
						'type'        => 'updated',
406
						'description' => __( 'Primary email updated for donor.', 'give' ),
407
						'show'        => true,
408
					) );
409
					break;
410
411 View Code Duplication
				case 'primary-email-failed' :
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...
412
					Give()->notices->register_notice( array(
413
						'id'          => 'give-donor-primary-email-failed',
414
						'type'        => 'updated',
415
						'description' => __( 'Failed to set primary email.', 'give' ),
416
						'show'        => true,
417
					) );
418
					break;
419
420 View Code Duplication
				case 'reconnect-user' :
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...
421
					Give()->notices->register_notice( array(
422
						'id'          => 'give-donor-reconnect-user',
423
						'type'        => 'updated',
424
						'description' => __( 'User has been successfully connected with Donor.', 'give' ),
425
						'show'        => true,
426
					) );
427
					break;
428
429 View Code Duplication
				case 'profile-updated' :
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...
430
					Give()->notices->register_notice( array(
431
						'id'          => 'give-donor-profile-updated',
432
						'type'        => 'updated',
433
						'description' => __( 'Donor information updated successfully.', 'give' ),
434
						'show'        => true,
435
					) );
436
					break;
437
			}
438
		}
439
	}
440
}
441
442
add_action( 'admin_notices', '_give_register_admin_notices', - 1 );
443
444
445
/**
446
 * Display admin bar when active.
447
 *
448
 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference.
449
 *
450
 * @return bool
451
 */
452
function _give_show_test_mode_notice_in_admin_bar( $wp_admin_bar ) {
453
	$is_test_mode = ! empty( $_POST['test_mode'] ) ?
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
454
		give_is_setting_enabled( $_POST['test_mode'] ) :
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
455
		give_is_test_mode();
456
457
	if (
458
		! current_user_can( 'view_give_reports' ) ||
459
		! $is_test_mode
460
	) {
461
		return false;
462
	}
463
464
	// Add the main site admin menu item.
465
	$wp_admin_bar->add_menu( array(
466
		'id'     => 'give-test-notice',
467
		'href'   => admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways' ),
468
		'parent' => 'top-secondary',
469
		'title'  => __( 'Give Test Mode Active', 'give' ),
470
		'meta'   => array( 'class' => 'give-test-mode-active' ),
471
	) );
472
473
	return true;
474
}
475
476
add_action( 'admin_bar_menu', '_give_show_test_mode_notice_in_admin_bar', 1000, 1 );
477
478
/**
479
 * Add Link to Import page in from donation archive and donation single page
480
 *
481
 * @since 1.8.13
482
 */
483
function give_import_page_link_callback() {
484
	?>
485
	<a href="<?php echo esc_url( give_import_page_url() ); ?>"
486
	   class="page-import-action page-title-action"><?php _e( 'Import Donations', 'give' ); ?></a>
487
488
	<?php
489
	// Check if view donation single page only.
490
	if ( ! empty( $_REQUEST['view'] ) && 'view-payment-details' === (string) give_clean( $_REQUEST['view'] ) && 'give-payment-history' === give_clean( $_REQUEST['page'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
introduced by
Detected usage of a non-validated input variable: $_REQUEST
Loading history...
491
		?>
492
		<style type="text/css">
493
			.wrap #transaction-details-heading {
494
				display: inline-block;
495
			}
496
		</style>
497
		<?php
498
	}
499
}
500
501
add_action( 'give_payments_page_top', 'give_import_page_link_callback', 11 );
502
503
/**
504
 * Load donation import ajax callback
505
 * Fire when importing from CSV start
506
 *
507
 * @since  1.8.13
508
 *
509
 * @return json $json_data
510
 */
511
function give_donation_import_callback() {
512
	$import_setting = array();
513
	$fields         = isset( $_POST['fields'] ) ? $_POST['fields'] : null;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
514
515
	parse_str( $fields );
516
517
	$import_setting['create_user'] = $create_user;
518
	$import_setting['mode']        = $mode;
519
	$import_setting['delimiter']   = $delimiter;
520
	$import_setting['csv']         = $csv;
521
	$import_setting['delete_csv']  = $delete_csv;
522
523
	// Parent key id.
524
	$main_key = maybe_unserialize( $main_key );
525
526
	$current    = absint( $_REQUEST['current'] );
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_REQUEST
Loading history...
527
	$total_ajax = absint( $_REQUEST['total_ajax'] );
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_REQUEST
Loading history...
528
	$start      = absint( $_REQUEST['start'] );
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_REQUEST
Loading history...
529
	$end        = absint( $_REQUEST['end'] );
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_REQUEST
Loading history...
530
	$next       = absint( $_REQUEST['next'] );
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_REQUEST
Loading history...
531
	$total      = absint( $_REQUEST['total'] );
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_REQUEST
Loading history...
532
	$per_page   = absint( $_REQUEST['per_page'] );
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_REQUEST
Loading history...
533
	if ( empty( $delimiter ) ) {
534
		$delimiter = ',';
535
	}
536
537
	// Processing done here.
538
	$raw_data = give_get_donation_data_from_csv( $csv, $start, $end, $delimiter );
539
	$raw_key  = maybe_unserialize( $mapto );
540
541
	// Prevent normal emails.
542
	remove_action( 'give_complete_donation', 'give_trigger_donation_receipt', 999 );
543
	remove_action( 'give_insert_user', 'give_new_user_notification', 10 );
544
	remove_action( 'give_insert_payment', 'give_payment_save_page_data' );
545
546
	$current_key  = $start;
547
	foreach ( $raw_data as $row_data ) {
548
		$import_setting['donation_key']  = $current_key;
549
		give_save_import_donation_to_db( $raw_key, $row_data, $main_key, $import_setting );
550
		$current_key++;
551
	}
552
553
	// Check if function exists or not.
554
	if ( function_exists( 'give_payment_save_page_data' ) ) {
555
		add_action( 'give_insert_payment', 'give_payment_save_page_data' );
556
	}
557
	add_action( 'give_insert_user', 'give_new_user_notification', 10, 2 );
558
	add_action( 'give_complete_donation', 'give_trigger_donation_receipt', 999 );
559
560
	if ( $next == false ) {
0 ignored issues
show
introduced by
Found "== false". Use Yoda Condition checks, you must
Loading history...
561
		$json_data = array(
562
			'success' => true,
563
			'message' => __( 'All donation uploaded successfully!', 'give' ),
564
		);
565
	} else {
566
		$index_start = $start;
567
		$index_end   = $end;
568
		$last        = false;
569
		$next        = true;
570
		if ( $next ) {
571
			$index_start = $index_start + $per_page;
572
			$index_end   = $per_page + ( $index_start - 1 );
573
		}
574
		if ( $index_end >= $total ) {
575
			$index_end = $total;
576
			$last      = true;
577
		}
578
		$json_data = array(
579
			'raw_data' => $raw_data,
580
			'raw_key'  => $raw_key,
581
			'next'     => $next,
582
			'start'    => $index_start,
583
			'end'      => $index_end,
584
			'last'     => $last,
585
		);
586
	}
587
588
	$url              = give_import_page_url( array(
589
		'step'          => '4',
590
		'importer-type' => 'import_donations',
591
		'csv'           => $csv,
592
		'total'         => $total,
593
		'delete_csv'    => $import_setting['delete_csv'],
594
		'success'       => ( isset( $json_data['success'] ) ? $json_data['success'] : '' ),
595
	) );
596
	$json_data['url'] = $url;
597
598
	$current ++;
599
	$json_data['current'] = $current;
600
601
	$percentage              = ( 100 / ( $total_ajax + 1 ) ) * $current;
602
	$json_data['percentage'] = $percentage;
603
604
	$json_data = apply_filters( 'give_import_ajax_responces', $json_data, $fields );
605
	wp_die( json_encode( $json_data ) );
606
}
607
608
add_action( 'wp_ajax_give_donation_import', 'give_donation_import_callback' );
609
610
/**
611
 * Load core settings import ajax callback
612
 * Fire when importing from JSON start
613
 *
614
 * @since  1.8.17
615
 *
616
 * @return json $json_data
617
 */
618
619
function give_core_settings_import_callback() {
620
	$fields = isset( $_POST['fields'] ) ? $_POST['fields'] : null;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
621
	parse_str( $fields, $fields );
622
623
	$json_data['success'] = false;
624
625
	/**
626
	 * Filter to Modify fields that are being pass by the ajax before importing of the core setting start.
627
	 *
628
	 * @access public
629
	 *
630
	 * @since  1.8.17
631
	 *
632
	 * @param array $fields
633
	 *
634
	 * @return array $fields
635
	 */
636
	$fields = (array) apply_filters( 'give_import_core_settings_fields', $fields );
637
638
	$file_name = ( ! empty( $fields['file_name'] ) ? give_clean( $fields['file_name'] ) : false );
639
640
	if ( ! empty( $file_name ) ) {
641
		$type = ( ! empty( $fields['type'] ) ? give_clean( $fields['type'] ) : 'merge' );
642
643
		// Get the json data from the file and then alter it in array format
644
		$json_string   = give_get_core_settings_json( $file_name );
0 ignored issues
show
Bug introduced by
It seems like $file_name defined by !empty($fields['file_nam...s['file_name']) : false on line 638 can also be of type array; however, give_get_core_settings_json() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
645
		$json_to_array = json_decode( $json_string, true );
646
647
		// get the current settign from the options table.
648
		$host_give_options = get_option( 'give_settings', array() );
649
650
		// Save old settins for backup.
651
		update_option( 'give_settings_old', $host_give_options );
652
653
		/**
654
		 * Filter to Modify Core Settings that are being going to get import in options table as give settings.
655
		 *
656
		 * @access public
657
		 *
658
		 * @since  1.8.17
659
		 *
660
		 * @param array $json_to_array     Setting that are being going to get imported
661
		 * @param array $type              Type of Import
662
		 * @param array $host_give_options Setting old setting that used to be in the options table.
663
		 * @param array $fields            Data that is being send from the ajax
664
		 *
665
		 * @return array $json_to_array Setting that are being going to get imported
666
		 */
667
		$json_to_array = (array) apply_filters( 'give_import_core_settings_data', $json_to_array, $type, $host_give_options, $fields );
668
669
		update_option( 'give_settings', $json_to_array );
670
671
		$json_data['success'] = true;
672
	}
673
674
	$json_data['percentage'] = 100;
675
676
	/**
677
	 * Filter to Modify core import setting page url
678
	 *
679
	 * @access public
680
	 *
681
	 * @since  1.8.17
682
	 *
683
	 * @return array $url
684
	 */
685
	$json_data['url'] = give_import_page_url( (array) apply_filters( 'give_import_core_settings_success_url', array(
686
		'step'          => ( empty( $json_data['success'] ) ? '1' : '3' ),
687
		'importer-type' => 'import_core_setting',
688
		'success'       => ( empty( $json_data['success'] ) ? '0' : '1' ),
689
	) ) );
690
691
	wp_send_json( $json_data );
692
}
693
694
add_action( 'wp_ajax_give_core_settings_import', 'give_core_settings_import_callback' );
695
696
/**
697
 * Initializes blank slate content if a list table is empty.
698
 *
699
 * @since 1.8.13
700
 */
701
function give_blank_slate() {
702
	$blank_slate = new Give_Blank_Slate();
703
	$blank_slate->init();
704
}
705
706
add_action( 'current_screen', 'give_blank_slate' );
707
708
/**
709
 * Validate Fields of User Profile
710
 *
711
 * @param object   $errors Object of WP Errors.
712
 * @param int|bool $update True or False.
713
 * @param object   $user   WP User Data.
714
 *
715
 * @since 2.0
716
 *
717
 * @return mixed
718
 */
719
function give_validate_user_profile( $errors, $update, $user ) {
0 ignored issues
show
Unused Code introduced by
The parameter $update 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...
720
721
	if ( ! empty( $_POST['action'] ) && ( 'adduser' === $_POST['action'] || 'createuser' === $_POST['action'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
722
		return;
723
	}
724
725
	if ( ! empty( $user->ID ) ) {
726
		$donor = Give()->donors->get_donor_by( 'user_id', $user->ID );
727
728
		if ( $donor ) {
729
			// If Donor is attached with User, then validate first name.
730
			if ( empty( $_POST['first_name'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
731
				$errors->add(
732
					'empty_first_name',
733
					sprintf(
734
						'<strong>%1$s:</strong> %2$s',
735
						__( 'ERROR', 'give' ),
736
						__( 'Please enter your first name.', 'give' )
737
					)
738
				);
739
			}
740
		}
741
	}
742
743
}
744
745
add_action( 'user_profile_update_errors', 'give_validate_user_profile', 10, 3 );
746
747
/**
748
 * Show Donor Information on User Profile Page.
749
 *
750
 * @param object $user User Object.
751
 *
752
 * @since 2.0
753
 */
754
function give_donor_information_profile_fields( $user ) {
755
	$donor = Give()->donors->get_donor_by( 'user_id', $user->ID );
756
757
	// Display Donor Information, only if donor is attached with User.
758
	if ( ! empty( $donor->user_id ) ) {
759
		?>
760
		<table class="form-table">
761
			<tbody>
762
			<tr>
763
				<th scope="row"><?php _e( 'Donor', 'give' ); ?></th>
764
				<td>
765
					<a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ); ?>">
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'admin_url'
Loading history...
766
						<?php _e( 'View Donor Information', 'give' ); ?>
767
					</a>
768
				</td>
769
			</tr>
770
			</tbody>
771
		</table>
772
		<?php
773
	}
774
}
775
776
add_action( 'personal_options', 'give_donor_information_profile_fields' );
777
/**
778
 * Get Array of WP User Roles.
779
 *
780
 * @since 1.8.13
781
 *
782
 * @return array
783
 */
784
function give_get_user_roles() {
785
	$user_roles = array();
786
787
	// Loop through User Roles.
788
	foreach ( get_editable_roles() as $role_name => $role_info ):
789
		$user_roles[ $role_name ] = $role_info['name'];
790
	endforeach;
791
792
	return $user_roles;
793
}
794
795
796
/**
797
 * Ajax handle for donor address.
798
 *
799
 * @since 2.0
800
 *
801
 * @return string
802
 */
803
function __give_ajax_donor_manage_addresses() {
804
	// Bailout.
805
	if (
806
		empty( $_POST['form'] ) ||
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
807
		empty( $_POST['donorID'] )
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
808
	) {
809
		wp_send_json_error( array( 'error' => 1 ) );
810
	}
811
812
	$post                  = give_clean( wp_parse_args( $_POST ) );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
813
	$donorID               = absint( $post['donorID'] );
814
	$form_data             = give_clean( wp_parse_args( $post['form'] ) );
815
	$is_multi_address_type = ( 'billing' === $form_data['address-id'] || false !== strpos( $form_data['address-id'], '_' ) );
816
	$address_type          = false !== strpos( $form_data['address-id'], '_' ) ?
817
		array_shift( explode( '_', $form_data['address-id'] ) ) :
818
		$form_data['address-id'];
819
	$address_id            = false !== strpos( $form_data['address-id'], '_' ) ?
820
		array_pop( explode( '_', $form_data['address-id'] ) ) :
821
		null;
822
	$response_data         = array(
823
		'action' => $form_data['address-action'],
824
		'id'     => $form_data['address-id'],
825
	);
826
827
	// Security check.
828 View Code Duplication
	if ( ! wp_verify_nonce( $form_data['_wpnonce'], 'give-manage-donor-addresses' ) ) {
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...
829
		wp_send_json_error( array(
830
				'error'     => 1,
831
				'error_msg' => wp_sprintf(
832
					'<div class="notice notice-error"><p>%s</p></div>',
833
					__( 'Error: Security issue.', 'give' )
834
				)
835
			)
836
		);
837
	}
838
839
	$donor = new Give_Donor( $donorID );
840
841
	// Verify donor.
842
	if ( ! $donor->id ) {
843
		wp_send_json_error( array( 'error' => 3 ) );
844
	}
845
846
	// Unset all data except address.
847
	unset(
848
		$form_data['_wpnonce'],
849
		$form_data['address-action'],
850
		$form_data['address-id']
851
	);
852
853
	// Process action.
854
	switch ( $response_data['action'] ) {
855
856
		case 'add':
857 View Code Duplication
			if ( ! $donor->add_address( "{$address_type}[]", $form_data ) ) {
0 ignored issues
show
Bug introduced by
It seems like $form_data defined by give_clean(wp_parse_args($post['form'])) on line 814 can also be of type string; however, Give_Donor::add_address() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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...
858
				wp_send_json_error( array(
859
						'error'     => 1,
860
						'error_msg' => wp_sprintf(
861
							'<div class="notice notice-error"><p>%s</p></div>',
862
							__( 'Error: Unable to save the address. Please check if address already exist.', 'give' )
863
						)
864
					)
865
				);
866
			}
867
868
			$total_addresses = count( $donor->address[ $address_type ] );
869
870
			$address_index = $is_multi_address_type ?
871
				$total_addresses - 1 :
872
				$address_type;
873
874
			$address_id = $is_multi_address_type ?
875
				end( array_keys( $donor->address[ $address_type ] ) ) :
876
				$address_type;
877
878
			$response_data['address_html'] = __give_get_format_address(
879
				end( $donor->address['billing'] ),
880
				array(
881
					// We can add only billing address from donor screen.
882
					'type'  => 'billing',
883
					'id'    => $address_id,
884
					'index' => ++ $address_index,
885
				)
886
			);
887
			$response_data['success_msg']  = wp_sprintf(
888
				'<div class="notice updated"><p>%s</p></div>',
889
				__( 'Successfully added a new address to the donor.', 'give' )
890
			);
891
892
			if ( $is_multi_address_type ) {
893
				$response_data['id'] = "{$response_data['id']}_{$address_index}";
894
			}
895
896
			break;
897
898
		case 'remove':
899 View Code Duplication
			if ( ! $donor->remove_address( $response_data['id'] ) ) {
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...
900
				wp_send_json_error( array(
901
						'error'     => 2,
902
						'error_msg' => wp_sprintf(
903
							'<div class="notice notice-error"><p>%s</p></div>',
904
							__( 'Error: Unable to delete address.', 'give' )
905
						)
906
					)
907
				);
908
			}
909
910
			$response_data['success_msg'] = wp_sprintf(
911
				'<div class="notice updated"><p>%s</p></div>',
912
				__( 'Successfully removed a address of donor.', 'give' )
913
			);
914
915
			break;
916
917
		case 'update':
918 View Code Duplication
			if ( ! $donor->update_address( $response_data['id'], $form_data ) ) {
0 ignored issues
show
Bug introduced by
It seems like $form_data defined by give_clean(wp_parse_args($post['form'])) on line 814 can also be of type string; however, Give_Donor::update_address() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
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...
919
				wp_send_json_error( array(
920
						'error'     => 3,
921
						'error_msg' => wp_sprintf(
922
							'<div class="notice notice-error"><p>%s</p></div>',
923
							__( 'Error: Unable to update address. Please check if address already exist.', 'give' )
924
						)
925
					)
926
				);
927
			}
928
929
			$response_data['address_html'] = __give_get_format_address(
930
				$is_multi_address_type ?
931
					$donor->address[ $address_type ][ $address_id ] :
932
					$donor->address[ $address_type ],
933
				array(
934
					'type'  => $address_type,
935
					'id'    => $address_id,
936
					'index' => $address_id,
937
				)
938
			);
939
			$response_data['success_msg']  = wp_sprintf(
940
				'<div class="notice updated"><p>%s</p></div>',
941
				__( 'Successfully updated a address of donor', 'give' )
942
			);
943
944
			break;
945
	}
946
947
	wp_send_json_success( $response_data );
948
}
949
950
add_action( 'wp_ajax_donor_manage_addresses', '__give_ajax_donor_manage_addresses' );
951
952
/**
953
 * Admin donor billing address label
954
 *
955
 * @since 2.0
956
 *
957
 * @param string $address_label
958
 *
959
 * @return string
960
 */
961
function __give_donor_billing_address_label( $address_label ) {
0 ignored issues
show
Unused Code introduced by
The parameter $address_label 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...
962
	$address_label = __( 'Billing Address', 'give' );
963
964
	return $address_label;
965
}
966
967
add_action( 'give_donor_billing_address_label', '__give_donor_billing_address_label' );
968
969
/**
970
 * Admin donor personal address label
971
 *
972
 * @since 2.0
973
 *
974
 * @param string $address_label
975
 *
976
 * @return string
977
 */
978
function __give_donor_personal_address_label( $address_label ) {
0 ignored issues
show
Unused Code introduced by
The parameter $address_label 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...
979
	$address_label = __( 'Personal Address', 'give' );
980
981
	return $address_label;
982
}
983
984
add_action( 'give_donor_personal_address_label', '__give_donor_personal_address_label' );
985
986
/**
987
 * Update Donor Information when User Profile is updated from admin.
988
 * Note: for internal use only.
989
 *
990
 * @param int $user_id
991
 *
992
 * @access public
993
 * @since  2.0
994
 *
995
 * @return bool
996
 */
997
function give_update_donor_name_on_user_update( $user_id = 0 ) {
998
999
	if ( current_user_can( 'edit_user', $user_id ) ) {
1000
1001
		$donor = new Give_Donor( $user_id, true );
0 ignored issues
show
Documentation introduced by
$user_id is of type integer, but the function expects a boolean.

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...
1002
1003
		// Bailout, if donor doesn't exists.
1004
		if ( ! $donor ) {
1005
			return false;
1006
		}
1007
1008
		// Get User First name and Last name.
1009
		$first_name = ( $_POST['first_name'] ) ? give_clean( $_POST['first_name'] ) : get_user_meta( $user_id, 'first_name', true );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_POST
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
introduced by
get_user_meta() usage is highly discouraged, check VIP documentation on "Working with wp_users"
Loading history...
1010
		$last_name  = ( $_POST['last_name'] ) ? give_clean( $_POST['last_name'] ) : get_user_meta( $user_id, 'last_name', true );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_POST
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
introduced by
get_user_meta() usage is highly discouraged, check VIP documentation on "Working with wp_users"
Loading history...
1011
		$full_name  = strip_tags( wp_unslash( trim( "{$first_name} {$last_name}" ) ) );
1012
1013
		// Assign User First name and Last name to Donor.
1014
		Give()->donors->update( $donor->id, array( 'name' => $full_name ) );
1015
		Give()->donor_meta->update_meta( $donor->id, '_give_donor_first_name', $first_name );
1016
		Give()->donor_meta->update_meta( $donor->id, '_give_donor_last_name', $last_name );
1017
1018
	}
1019
}
1020
1021
add_action( 'edit_user_profile_update', 'give_update_donor_name_on_user_update', 10 );
1022
add_action( 'personal_options_update', 'give_update_donor_name_on_user_update', 10 );
1023
1024
1025
/**
1026
 * Updates the email address of a donor record when the email on a user is updated
1027
 * Note: for internal use only.
1028
 *
1029
 * @since  1.4.3
1030
 * @access public
1031
 *
1032
 * @param  int          $user_id       User ID.
1033
 * @param  WP_User|bool $old_user_data User data.
1034
 *
1035
 * @return bool
1036
 */
1037
function give_update_donor_email_on_user_update( $user_id = 0, $old_user_data = false ) {
0 ignored issues
show
Unused Code introduced by
The parameter $old_user_data 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...
1038
1039
	$donor = new Give_Donor( $user_id, true );
0 ignored issues
show
Documentation introduced by
$user_id is of type integer, but the function expects a boolean.

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...
1040
1041
	if ( ! $donor ) {
1042
		return false;
1043
	}
1044
1045
	$user = get_userdata( $user_id );
1046
1047
	if ( ! empty( $user ) && $user->user_email !== $donor->email ) {
1048
1049
		$success = Give()->donors->update( $donor->id, array( 'email' => $user->user_email ) );
1050
1051
		if ( $success ) {
1052
			// Update some payment meta if we need to
1053
			$payments_array = explode( ',', $donor->payment_ids );
1054
1055
			if ( ! empty( $payments_array ) ) {
1056
1057
				foreach ( $payments_array as $payment_id ) {
1058
1059
					give_update_payment_meta( $payment_id, 'email', $user->user_email );
1060
1061
				}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
1062
1063
			}
1064
1065
			/**
1066
			 * Fires after updating donor email on user update.
1067
			 *
1068
			 * @since 1.4.3
1069
			 *
1070
			 * @param  WP_User    $user  WordPress User object.
1071
			 * @param  Give_Donor $donor Give donor object.
1072
			 */
1073
			do_action( 'give_update_donor_email_on_user_update', $user, $donor );
1074
1075
		}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
1076
1077
	}
1078
1079
}
1080
1081
add_action( 'profile_update', 'give_update_donor_email_on_user_update', 10, 2 );