Test Failed
Push — hotfix/arabic-currencies ( 149636 )
by Ravinder
05:38
created

admin-actions.php ➔ give_flush_rewrite_rules()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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
			// Add donor bulk notice.
203
		} elseif (
204
			isset( $_GET['page'] ) &&
205
			'give-donors' === $_GET['page'] &&
206
			isset( $_GET['donor'] ) &&
207
			! empty( $_GET['donor'] )
208
		) {
209
210
			$donor_count = isset( $_GET['donor'] ) ? count( $_GET['donor'] ) : 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...
211
212
			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...
213 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...
214
					Give()->notices->register_notice( array(
215
						'id'          => 'bulk_action_delete',
216
						'type'        => 'updated',
217
						'description' => sprintf(
218
							_n(
219
								'Successfully deleted one donor and associated records.',
220
								'Successfully deleted %d donors and associated records.',
221
								$donor_count,
222
								'give'
223
							),
224
							$donor_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...
225
						'show'        => true,
226
					) );
227
					
228
					break;
229
			}
230
		}
231
	}
232
233
	// Add give message notices.
234
	if ( ! empty( $_GET['give-message'] ) ) {
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
235
		// Donation reports errors.
236
		if ( current_user_can( 'view_give_reports' ) ) {
237
			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...
238 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...
239
					Give()->notices->register_notice( array(
240
						'id'          => 'give-donation-deleted',
241
						'type'        => 'updated',
242
						'description' => __( 'The donation has been deleted.', 'give' ),
243
						'show'        => true,
244
					) );
245
					break;
246 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...
247
					Give()->notices->register_notice( array(
248
						'id'          => 'give-payment-sent',
249
						'type'        => 'updated',
250
						'description' => __( 'The donation receipt has been resent.', 'give' ),
251
						'show'        => true,
252
					) );
253
					break;
254 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...
255
					Give()->notices->register_notice( array(
256
						'id'          => 'give-refreshed-reports',
257
						'type'        => 'updated',
258
						'description' => __( 'The reports cache has been cleared.', 'give' ),
259
						'show'        => true,
260
					) );
261
					break;
262 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...
263
					Give()->notices->register_notice( array(
264
						'id'          => 'give-donation-note-deleted',
265
						'type'        => 'updated',
266
						'description' => __( 'The donation note has been deleted.', 'give' ),
267
						'show'        => true,
268
					) );
269
					break;
270
			}
271
		}
272
273
		// Give settings notices and errors.
274
		if ( current_user_can( 'manage_give_settings' ) ) {
275
			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...
276 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...
277
					Give()->notices->register_notice( array(
278
						'id'          => 'give-settings-imported',
279
						'type'        => 'updated',
280
						'description' => __( 'The settings have been imported.', 'give' ),
281
						'show'        => true,
282
					) );
283
					break;
284 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...
285
					Give()->notices->register_notice( array(
286
						'id'          => 'give-api-key-generated',
287
						'type'        => 'updated',
288
						'description' => __( 'API keys have been generated.', 'give' ),
289
						'show'        => true,
290
					) );
291
					break;
292 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...
293
					Give()->notices->register_notice( array(
294
						'id'          => 'give-api-key-exists',
295
						'type'        => 'updated',
296
						'description' => __( 'The specified user already has API keys.', 'give' ),
297
						'show'        => true,
298
					) );
299
					break;
300 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...
301
					Give()->notices->register_notice( array(
302
						'id'          => 'give-api-key-regenerated',
303
						'type'        => 'updated',
304
						'description' => __( 'API keys have been regenerated.', 'give' ),
305
						'show'        => true,
306
					) );
307
					break;
308 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...
309
					Give()->notices->register_notice( array(
310
						'id'          => 'give-api-key-revoked',
311
						'type'        => 'updated',
312
						'description' => __( 'API keys have been revoked.', 'give' ),
313
						'show'        => true,
314
					) );
315
					break;
316 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...
317
					Give()->notices->register_notice( array(
318
						'id'          => 'give-sent-test-email',
319
						'type'        => 'updated',
320
						'description' => __( 'The test email has been sent.', 'give' ),
321
						'show'        => true,
322
					) );
323
					break;
324 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...
325
					Give()->notices->register_notice( array(
326
						'id'          => 'give-matched-success-failure-page',
327
						'type'        => 'updated',
328
						'description' => __( 'You cannot set the success and failed pages to the same page', 'give' ),
329
						'show'        => true,
330
					) );
331
					break;
332
			}
333
		}
334
		// Payments errors.
335
		if ( current_user_can( 'edit_give_payments' ) ) {
336
			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...
337 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...
338
					Give()->notices->register_notice( array(
339
						'id'          => 'give-note-added',
340
						'type'        => 'updated',
341
						'description' => __( 'The donation note has been added.', 'give' ),
342
						'show'        => true,
343
					) );
344
					break;
345 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...
346
					Give()->notices->register_notice( array(
347
						'id'          => 'give-payment-updated',
348
						'type'        => 'updated',
349
						'description' => __( 'The donation has been updated.', 'give' ),
350
						'show'        => true,
351
					) );
352
					break;
353
			}
354
		}
355
356
		// Donor Notices.
357
		if ( current_user_can( 'edit_give_payments' ) ) {
358
			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...
359 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...
360
					Give()->notices->register_notice( array(
361
						'id'          => 'give-donor-deleted',
362
						'type'        => 'updated',
363
						'description' => __( 'The donor has been deleted.', 'give' ),
364
						'show'        => true,
365
					) );
366
					break;
367
368 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...
369
					Give()->notices->register_notice( array(
370
						'id'          => 'give-donor-email-added',
371
						'type'        => 'updated',
372
						'description' => __( 'Donor email added.', 'give' ),
373
						'show'        => true,
374
					) );
375
					break;
376
377 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...
378
					Give()->notices->register_notice( array(
379
						'id'          => 'give-donor-email-removed',
380
						'type'        => 'updated',
381
						'description' => __( 'Donor email removed.', 'give' ),
382
						'show'        => true,
383
					) );
384
					break;
385
386 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...
387
					Give()->notices->register_notice( array(
388
						'id'          => 'give-donor-email-remove-failed',
389
						'type'        => 'updated',
390
						'description' => __( 'Failed to remove donor email.', 'give' ),
391
						'show'        => true,
392
					) );
393
					break;
394
395 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...
396
					Give()->notices->register_notice( array(
397
						'id'          => 'give-donor-primary-email-updated',
398
						'type'        => 'updated',
399
						'description' => __( 'Primary email updated for donor.', 'give' ),
400
						'show'        => true,
401
					) );
402
					break;
403
404 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...
405
					Give()->notices->register_notice( array(
406
						'id'          => 'give-donor-primary-email-failed',
407
						'type'        => 'updated',
408
						'description' => __( 'Failed to set primary email.', 'give' ),
409
						'show'        => true,
410
					) );
411
					break;
412
413 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...
414
					Give()->notices->register_notice( array(
415
						'id'          => 'give-donor-reconnect-user',
416
						'type'        => 'updated',
417
						'description' => __( 'User has been successfully connected with Donor.', 'give' ),
418
						'show'        => true,
419
					) );
420
					break;
421
422 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...
423
					Give()->notices->register_notice( array(
424
						'id'          => 'give-donor-profile-updated',
425
						'type'        => 'updated',
426
						'description' => __( 'Donor information updated successfully.', 'give' ),
427
						'show'        => true,
428
					) );
429
					break;
430
			}
431
		}
432
	}
433
}
434
435
add_action( 'admin_notices', '_give_register_admin_notices', - 1 );
436
437
438
/**
439
 * Display admin bar when active.
440
 *
441
 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance, passed by reference.
442
 *
443
 * @return bool
444
 */
445
function _give_show_test_mode_notice_in_admin_bar( $wp_admin_bar ) {
446
	$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...
447
		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...
448
		give_is_test_mode();
449
450
	if (
451
		! current_user_can( 'view_give_reports' ) ||
452
		! $is_test_mode
453
	) {
454
		return false;
455
	}
456
457
	// Add the main site admin menu item.
458
	$wp_admin_bar->add_menu( array(
459
		'id'     => 'give-test-notice',
460
		'href'   => admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=gateways' ),
461
		'parent' => 'top-secondary',
462
		'title'  => __( 'Give Test Mode Active', 'give' ),
463
		'meta'   => array( 'class' => 'give-test-mode-active' ),
464
	) );
465
466
	return true;
467
}
468
469
add_action( 'admin_bar_menu', '_give_show_test_mode_notice_in_admin_bar', 1000, 1 );
470
471
/**
472
 * Add Link to Import page in from donation archive and donation single page
473
 *
474
 * @since 1.8.13
475
 */
476
function give_import_page_link_callback() {
477
	?>
478
	<a href="<?php echo esc_url( give_import_page_url() ); ?>"
479
	   class="page-import-action page-title-action"><?php _e( 'Import Donations', 'give' ); ?></a>
480
481
	<?php
482
	// Check if view donation single page only.
483
	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...
484
		?>
485
		<style type="text/css">
486
			.wrap #transaction-details-heading {
487
				display: inline-block;
488
			}
489
		</style>
490
		<?php
491
	}
492
}
493
494
add_action( 'give_payments_page_top', 'give_import_page_link_callback', 11 );
495
496
/**
497
 * Load donation import ajax callback
498
 * Fire when importing from CSV start
499
 *
500
 * @since  1.8.13
501
 *
502
 * @return json $json_data
503
 */
504
function give_donation_import_callback() {
505
	$import_setting = array();
506
	$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...
507
508
	parse_str( $fields );
509
510
	$import_setting['create_user'] = $create_user;
511
	$import_setting['mode']        = $mode;
512
	$import_setting['delimiter']   = $delimiter;
513
	$import_setting['csv']         = $csv;
514
	$import_setting['delete_csv']  = $delete_csv;
515
516
	// Parent key id.
517
	$main_key = maybe_unserialize( $main_key );
518
519
	$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...
520
	$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...
521
	$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...
522
	$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...
523
	$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...
524
	$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...
525
	$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...
526
	if ( empty( $delimiter ) ) {
527
		$delimiter = ',';
528
	}
529
530
	// Processing done here.
531
	$raw_data = give_get_donation_data_from_csv( $csv, $start, $end, $delimiter );
532
	$raw_key  = maybe_unserialize( $mapto );
533
534
	// Prevent normal emails.
535
	remove_action( 'give_complete_donation', 'give_trigger_donation_receipt', 999 );
536
	remove_action( 'give_insert_user', 'give_new_user_notification', 10 );
537
	remove_action( 'give_insert_payment', 'give_payment_save_page_data' );
538
539
	foreach ( $raw_data as $row_data ) {
540
		give_save_import_donation_to_db( $raw_key, $row_data, $main_key, $import_setting );
541
	}
542
543
	// Check if function exists or not.
544
	if ( function_exists( 'give_payment_save_page_data' ) ) {
545
		add_action( 'give_insert_payment', 'give_payment_save_page_data' );
546
	}
547
	add_action( 'give_insert_user', 'give_new_user_notification', 10, 2 );
548
	add_action( 'give_complete_donation', 'give_trigger_donation_receipt', 999 );
549
550
	if ( $next == false ) {
0 ignored issues
show
introduced by
Found "== false". Use Yoda Condition checks, you must
Loading history...
551
		$json_data = array(
552
			'success' => true,
553
			'message' => __( 'All donation uploaded successfully!', 'give' ),
554
		);
555
	} else {
556
		$index_start = $start;
557
		$index_end   = $end;
558
		$last        = false;
559
		$next        = true;
560
		if ( $next ) {
561
			$index_start = $index_start + $per_page;
562
			$index_end   = $per_page + ( $index_start - 1 );
563
		}
564
		if ( $index_end >= $total ) {
565
			$index_end = $total;
566
			$last      = true;
567
		}
568
		$json_data = array(
569
			'raw_data' => $raw_data,
570
			'raw_key'  => $raw_key,
571
			'next'     => $next,
572
			'start'    => $index_start,
573
			'end'      => $index_end,
574
			'last'     => $last,
575
		);
576
	}
577
578
	$url              = give_import_page_url( array(
579
		'step'          => '4',
580
		'importer-type' => 'import_donations',
581
		'csv'           => $csv,
582
		'total'         => $total,
583
		'delete_csv'    => $import_setting['delete_csv'],
584
		'success'       => ( isset( $json_data['success'] ) ? $json_data['success'] : '' ),
585
	) );
586
	$json_data['url'] = $url;
587
588
	$current ++;
589
	$json_data['current'] = $current;
590
591
	$percentage              = ( 100 / ( $total_ajax + 1 ) ) * $current;
592
	$json_data['percentage'] = $percentage;
593
	
594
	$json_data = apply_filters( 'give_import_ajax_responces', $json_data, $fields );
595
	wp_die( json_encode( $json_data ) );
596
}
597
598
add_action( 'wp_ajax_give_donation_import', 'give_donation_import_callback' );
599
600
/**
601
 * Load core settings import ajax callback
602
 * Fire when importing from JSON start
603
 *
604
 * @since  1.8.17
605
 *
606
 * @return json $json_data
607
 */
608
609
function give_core_settings_import_callback() {
610
	$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...
611
	parse_str( $fields, $fields );
612
613
	$json_data['success'] = false;
614
615
	/**
616
	 * Filter to Modify fields that are being pass by the ajax before importing of the core setting start.
617
	 *
618
	 * @access public
619
	 *
620
	 * @since 1.8.17
621
	 *
622
	 * @param array $fields
623
	 *
624
	 * @return array $fields
625
	 */
626
	$fields = (array) apply_filters( 'give_import_core_settings_fields', $fields );
627
628
	$file_name = ( ! empty( $fields['file_name'] ) ? give_clean( $fields['file_name'] ) : false );
629
630
	if ( ! empty( $file_name ) ) {
631
		$type = ( ! empty( $fields['type'] ) ? give_clean( $fields['type'] ) : 'merge' );
632
633
		// Get the json data from the file and then alter it in array format
634
		$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 628 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...
635
		$json_to_array = json_decode( $json_string, true );
636
637
		// get the current settign from the options table.
638
		$host_give_options = get_option( 'give_settings', array() );
639
640
		// Save old settins for backup.
641
		update_option( 'give_settings_old', $host_give_options );
642
643
		/**
644
		 * Filter to Modify Core Settings that are being going to get import in options table as give settings.
645
		 *
646
		 * @access public
647
		 *
648
		 * @since 1.8.17
649
		 *
650
		 * @param array $json_to_array Setting that are being going to get imported
651
		 * @param array $type Type of Import
652
		 * @param array $host_give_options Setting old setting that used to be in the options table.
653
		 * @param array $fields Data that is being send from the ajax
654
		 *
655
		 * @return array $json_to_array Setting that are being going to get imported
656
		 */
657
		$json_to_array = (array) apply_filters( 'give_import_core_settings_data', $json_to_array, $type, $host_give_options, $fields );
658
659
		update_option( 'give_settings', $json_to_array );
660
661
		$json_data['success'] = true;
662
	}
663
664
	$json_data['percentage'] = 100;
665
666
	/**
667
	 * Filter to Modify core import setting page url
668
	 *
669
	 * @access public
670
	 *
671
	 * @since 1.8.17
672
	 *
673
	 * @return array $url
674
	 */
675
	$json_data['url'] = give_import_page_url( (array) apply_filters( 'give_import_core_settings_success_url', array(
676
		'step'          => ( empty( $json_data['success'] ) ? '1' : '3' ),
677
		'importer-type' => 'import_core_setting',
678
		'success'       => ( empty( $json_data['success'] ) ? '0' : '1' ),
679
	) ) );
680
681
	wp_send_json( $json_data );
682
}
683
684
add_action( 'wp_ajax_give_core_settings_import', 'give_core_settings_import_callback' );
685
686
/**
687
 * Initializes blank slate content if a list table is empty.
688
 *
689
 * @since 1.8.13
690
 */
691
function give_blank_slate() {
692
	$blank_slate = new Give_Blank_Slate();
693
	$blank_slate->init();
694
}
695
696
add_action( 'current_screen', 'give_blank_slate' );
697
698
/**
699
 * Get Array of WP User Roles.
700
 *
701
 * @since 1.8.13
702
 *
703
 * @return array
704
 */
705
function give_get_user_roles() {
706
	$user_roles = array();
707
708
	// Loop through User Roles.
709
	foreach ( get_editable_roles() as $role_name => $role_info ):
710
		$user_roles[ $role_name ] = $role_info['name'];
711
	endforeach;
712
713
	return $user_roles;
714
}
715