Test Failed
Push — issues/2980 ( 6931f9 )
by Ravinder
05:32
created

Give_Import_Donations::start_import()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 60
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 35
nc 4
nop 0
dl 0
loc 60
rs 9.5555
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
 * Donations Import Class
4
 *
5
 * This class handles donations import.
6
 *
7
 * @package     Give
8
 * @subpackage  Classes/Give_Import_Donations
9
 * @copyright   Copyright (c) 2017, WordImpress
10
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
11
 * @since       1.8.14
12
 */
13
14
if ( ! defined( 'ABSPATH' ) ) {
15
	exit; // Exit if accessed directly
16
}
17
18
if ( ! class_exists( 'Give_Import_Donations' ) ) {
19
20
	/**
21
	 * Give_Import_Donations.
22
	 *
23
	 * @since 1.8.14
24
	 */
25
	final class Give_Import_Donations {
26
27
		/**
28
		 * Importer type
29
		 *
30
		 * @since 1.8.13
31
		 * @var string
32
		 */
33
		private $importer_type = 'import_donations';
34
35
		/**
36
		 * Instance.
37
		 *
38
		 * @since
39
		 * @access private
40
		 * @var
41
		 */
42
		static private $instance;
43
44
		/**
45
		 * Importing donation per page.
46
		 *
47
		 * @since 1.8.14
48
		 *
49
		 * @var   int
50
		 */
51
		public static $per_page = 25;
52
53
		/**
54
		 * Importing donation per page.
55
		 *
56
		 * @since 2.1
57
		 *
58
		 * @var   int
59
		 */
60
		public $is_csv_valid = false;
61
62
		/**
63
		 * Singleton pattern.
64
		 *
65
		 * @since
66
		 * @access private
67
		 */
68
		private function __construct() {
69
			self::$per_page = ! empty( $_GET['per_page'] ) ? absint( $_GET['per_page'] ) : self::$per_page;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
70
		}
71
72
		/**
73
		 * Get instance.
74
		 *
75
		 * @since
76
		 * @access public
77
		 *
78
		 * @return static
79
		 */
80
		public static function get_instance() {
81
			if ( null === static::$instance ) {
82
				self::$instance = new static();
83
			}
84
85
			return self::$instance;
86
		}
87
88
		/**
89
		 * Setup
90
		 *
91
		 * @since 1.8.14
92
		 *
93
		 * @return void
94
		 */
95
		public function setup() {
96
			$this->setup_hooks();
97
		}
98
99
100
		/**
101
		 * Setup Hooks.
102
		 *
103
		 * @since 1.8.14
104
		 *
105
		 * @return void
106
		 */
107 View Code Duplication
		private function setup_hooks() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
108
			if ( ! $this->is_donations_import_page() ) {
109
				return;
110
			}
111
112
			// Do not render main import tools page.
113
			remove_action( 'give_admin_field_tools_import', array( 'Give_Settings_Import', 'render_import_field', ) );
114
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
115
116
			// Render donation import page
117
			add_action( 'give_admin_field_tools_import', array( $this, 'render_page' ) );
118
119
			// Print the HTML.
120
			add_action( 'give_tools_import_donations_form_start', array( $this, 'html' ), 10 );
121
122
			// Run when form submit.
123
			add_action( 'give-tools_save_import', array( $this, 'save' ) );
124
125
			add_action( 'give-tools_update_notices', array( $this, 'update_notices' ), 11, 1 );
126
127
			// Used to add submit button.
128
			add_action( 'give_tools_import_donations_form_end', array( $this, 'submit' ), 10 );
129
		}
130
131
		/**
132
		 * Update notice
133
		 *
134
		 * @since 1.8.14
135
		 *
136
		 * @param $messages
137
		 *
138
		 * @return mixed
139
		 */
140 View Code Duplication
		public function update_notices( $messages ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
141
			if ( ! empty( $_GET['tab'] ) && 'import' === give_clean( $_GET['tab'] ) ) {
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...
142
				unset( $messages['give-setting-updated'] );
143
			}
144
145
			return $messages;
146
		}
147
148
		/**
149
		 * Print submit and nonce button.
150
		 *
151
		 * @since 1.8.14
152
		 */
153
		public function submit() {
154
			wp_nonce_field( 'give-save-settings', '_give-save-settings' );
155
			?>
156
			<input type="hidden" class="import-step" id="import-step" name="step"
157
			       value="<?php echo $this->get_step(); ?>"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
158
			<input type="hidden" class="importer-type" value="<?php echo $this->importer_type; ?>"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
159
			<?php
160
		}
161
162
		/**
163
		 * Print the HTML for importer.
164
		 *
165
		 * @since 1.8.14
166
		 */
167
		public function html() {
168
			$step = $this->get_step();
169
170
			// Show progress.
171
			$this->render_progress();
172
			?>
173
			<section>
174
				<table class="widefat export-options-table give-table <?php echo "step-{$step}"; ?> <?php echo ( 1 === $step && ! empty( $this->is_csv_valid ) ? 'give-hidden' : '' ); ?>  "
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '"step-{$step}"'
Loading history...
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
175
				       id="<?php echo "step-{$step}"; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '"step-{$step}"'
Loading history...
176
					<tbody>
177
					<?php
178
					switch ( $step ) {
179
						case 1:
180
							$this->render_media_csv();
181
							break;
182
183
						case 2:
184
							$this->render_dropdown();
185
							break;
186
187
						case 3:
188
							$this->start_import();
189
							break;
190
191
						case 4:
192
							$this->import_success();
193
					}
194
					if ( false === $this->check_for_dropdown_or_import() ) {
195
						?>
196
						<tr valign="top">
197
							<th></th>
198
							<th>
199
								<input type="submit"
200
								       class=" button button-primary button-large button-secondary <?php echo "step-{$step}"; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '"step-{$step}"'
Loading history...
201
								       id="recount-stats-submit"
202
									<?php echo ( 2 === $step ) ? 'disabled' : ''; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
203
									   value="<?php esc_attr_e( 'Submit', 'give' ); ?>"/>
204
							</th>
205
						</tr>
206
						<?php
207
					}
208
					?>
209
					</tbody>
210
				</table>
211
			</section>
212
			<?php
213
		}
214
215
		/**
216
		 * Show success notice
217
		 *
218
		 * @since 1.8.14
219
		 */
220
		public function import_success() {
221
222
			$delete_csv = ( ! empty( $_GET['delete_csv'] ) ? absint( $_GET['delete_csv'] ) : false );
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
223
			$csv        = ( ! empty( $_GET['csv'] ) ? absint( $_GET['csv'] ) : false );
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
224
			if ( ! empty( $delete_csv ) && ! empty( $csv ) ) {
225
				wp_delete_attachment( $csv, true );
226
			}
227
228
			$report = give_import_donation_report();
229
230
			$report_html = array(
231
				'duplicate_donor'    => array(
232
					__( '%s duplicate %s detected', 'give' ),
233
					__( 'donor', 'give' ),
234
					__( 'donors', 'give' ),
235
				),
236
				'create_donor'       => array(
237
					__( '%s %s created', 'give' ),
238
					__( 'donor', 'give' ),
239
					__( 'donors', 'give' ),
240
				),
241
				'create_form'        => array(
242
					__( '%s donation %s created', 'give' ),
243
					__( 'form', 'give' ),
244
					__( 'forms', 'give' ),
245
				),
246
				'duplicate_donation' => array(
247
					__( '%s duplicate %s detected', 'give' ),
248
					__( 'donation', 'give' ),
249
					__( 'donations', 'give' ),
250
				),
251
				'create_donation'    => array(
252
					__( '%s %s imported', 'give' ),
253
					__( 'donation', 'give' ),
254
					__( 'donations', 'give' ),
255
				),
256
			);
257
			$total       = (int) $_GET['total'];
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-validated input variable: $_GET
Loading history...
258
			-- $total;
259
			$success = (bool) $_GET['success'];
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-validated input variable: $_GET
Loading history...
260
			?>
261
			<tr valign="top" class="give-import-dropdown">
262
				<th colspan="2">
263
					<h2>
264
						<?php
265
						if ( $success ) {
266
							printf(
267
								_n( 'Import complete! %s donation processed', 'Import complete! %s donations processed', $total, 'give' ),
268
								"<strong>{$total}</strong>"
269
							);
270
						} else {
271
							printf(
272
								_n( 'Failed to import %s donation', 'Failed to import %s donations', $total, 'give' ),
273
								"<strong>{$total}</strong>"
274
							);
275
						}
276
						?>
277
					</h2>
278
279
					<?php
280
					$text      = __( 'Import Donation', 'give' );
281
					$query_arg = array(
282
						'post_type' => 'give_forms',
283
						'page'      => 'give-tools',
284
						'tab'       => 'import',
285
					);
286
					if ( $success ) {
287
						$query_arg = array(
288
							'post_type' => 'give_forms',
289
							'page'      => 'give-payment-history',
290
						);
291
						$text      = __( 'View Donations', 'give' );
292
					}
293
294
					foreach ( $report as $key => $value ) {
295
						if ( array_key_exists( $key, $report_html ) && ! empty( $value ) ) {
296
							?>
297
							<p>
298
								<?php esc_html_e( wp_sprintf( $report_html[ $key ][0], $value, _n( $report_html[ $key ][1], $report_html[ $key ][2], $value, 'give' ) ) ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$report_html'
Loading history...
299
							</p>
300
							<?php
301
						}
302
					}
303
					?>
304
305
					<p>
306
						<a class="button button-large button-secondary"
307
						   href="<?php echo add_query_arg( $query_arg, admin_url( 'edit.php' ) ); ?>"><?php echo $text; ?></a>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'add_query_arg'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$text'
Loading history...
308
					</p>
309
				</th>
310
			</tr>
311
			<?php
312
		}
313
314
		/**
315
		 * Will start Import
316
		 *
317
		 * @since 1.8.14
318
		 */
319
		public function start_import() {
320
			// Reset the donation form report.
321
			give_import_donation_report_reset();
322
323
			$csv         = (int) $_REQUEST['csv'];
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...
324
			$delimiter   = ( ! empty( $_REQUEST['delimiter'] ) ? give_clean( $_REQUEST['delimiter'] ) : 'csv' );
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...
325
			$index_start = 1;
326
			$index_end   = 1;
0 ignored issues
show
Unused Code introduced by
$index_end is not used, you could remove the assignment.

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

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

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

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

Loading history...
327
			$next        = true;
328
			$total       = self::get_csv_total( $csv );
329
			if ( self::$per_page < $total ) {
330
				$total_ajax = ceil( $total / self::$per_page );
331
				$index_end  = self::$per_page;
332
			} else {
333
				$total_ajax = 1;
334
				$index_end  = $total;
335
				$next       = false;
336
			}
337
			$current_percentage = 100 / ( $total_ajax + 1 );
338
339
			?>
340
			<tr valign="top" class="give-import-dropdown">
341
				<th colspan="2">
342
					<h2 id="give-import-title"><?php esc_html_e( 'Importing', 'give' ) ?></h2>
343
					<p class="give-field-description"><?php esc_html_e( 'Your donations are now being imported...', 'give' ) ?></p>
344
				</th>
345
			</tr>
346
347
			<tr valign="top" class="give-import-dropdown">
348
				<th colspan="2">
349
					<span class="spinner is-active"></span>
350
					<div class="give-progress"
351
					     data-current="1"
352
					     data-total_ajax="<?php echo $total_ajax; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$total_ajax'
Loading history...
353
					     data-start="<?php echo $index_start; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$index_start'
Loading history...
354
					     data-end="<?php echo $index_end; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$index_end'
Loading history...
355
					     data-next="<?php echo $next; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$next'
Loading history...
356
					     data-total="<?php echo $total; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$total'
Loading history...
357
					     data-per_page="<?php echo self::$per_page; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'self'
Loading history...
358
359
						<div style="width: <?php echo $current_percentage; ?>%"></div>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$current_percentage'
Loading history...
360
					</div>
361
					<input type="hidden" value="3" name="step">
362
					<input type="hidden" value='<?php echo maybe_serialize( $_REQUEST['mapto'] ); ?>' name="mapto"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'maybe_serialize'
Loading history...
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...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
363
					       class="mapto">
364
					<input type="hidden" value="<?php echo $_REQUEST['csv']; ?>" name="csv" class="csv">
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Expected next thing to be a escaping function, not '$_REQUEST'
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
365
					<input type="hidden" value="<?php echo $_REQUEST['mode']; ?>" name="mode" class="mode">
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Expected next thing to be a escaping function, not '$_REQUEST'
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
366
					<input type="hidden" value="<?php echo $_REQUEST['create_user']; ?>" name="create_user"
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Expected next thing to be a escaping function, not '$_REQUEST'
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
367
					       class="create_user">
368
					<input type="hidden" value="<?php echo $_REQUEST['delete_csv']; ?>" name="delete_csv"
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Expected next thing to be a escaping function, not '$_REQUEST'
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
369
					       class="delete_csv">
370
					<input type="hidden" value="<?php echo $delimiter; ?>" name="delimiter">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$delimiter'
Loading history...
371
					<input type="hidden"
372
					       value='<?php echo maybe_serialize( self::get_importer( $csv, 0, $delimiter ) ); ?>'
0 ignored issues
show
Bug introduced by
It seems like $delimiter defined by !empty($_REQUEST['delimi...T['delimiter']) : 'csv' on line 324 can also be of type array; however, Give_Import_Donations::get_importer() 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...
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'maybe_serialize'
Loading history...
373
					       name="main_key"
374
					       class="main_key">
375
				</th>
376
			</tr>
377
			<?php
378
		}
379
380
		/**
381
		 * Will return true if importing can be started or not else false.
382
		 *
383
		 * @since 1.8.14
384
		 */
385
		public function check_for_dropdown_or_import() {
386
			$return = true;
387
			if ( isset( $_REQUEST['mapto'] ) ) {
388
				$mapto = (array) $_REQUEST['mapto'];
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...
389
				if ( false === in_array( 'form_title', $mapto ) && false === in_array( 'form_id', $mapto ) ) {
390
					Give_Admin_Settings::add_error( 'give-import-csv-form', __( 'In order to import donations, a column must be mapped to either the "Donation Form Title" or "Donation Form ID" field. Please map a column to one of those fields.', 'give' ) );
391
					$return = false;
392
				}
393
394
				if ( false === in_array( 'amount', $mapto ) ) {
395
					Give_Admin_Settings::add_error( 'give-import-csv-amount', __( 'In order to import donations, a column must be mapped to the "Amount" field. Please map a column to that field.', 'give' ) );
396
					$return = false;
397
				}
398
399
				if ( false === in_array( 'email', $mapto ) && false === in_array( 'donor_id', $mapto ) ) {
400
					Give_Admin_Settings::add_error( 'give-import-csv-donor', __( 'In order to import donations, a column must be mapped to either the "Donor Email" or "Donor ID" field. Please map a column to that field.', 'give' ) );
401
					$return = false;
402
				}
403
			} else {
404
				$return = false;
405
			}
406
407
			return $return;
408
		}
409
410
		/**
411
		 * Print the Dropdown option for CSV.
412
		 *
413
		 * @since 1.8.14
414
		 */
415
		public function render_dropdown() {
416
			$csv       = (int) $_GET['csv'];
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-validated input variable: $_GET
Loading history...
417
			$delimiter = ( ! empty( $_GET['delimiter'] ) ? give_clean( $_GET['delimiter'] ) : 'csv' );
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...
418
419
			// TO check if the CSV files that is being add is valid or not if not then redirect to first step again
420
			if ( ! $this->is_valid_csv( $csv ) ) {
421
				$url = give_import_page_url();
422
				?>
423
				<input type="hidden" name="csv_not_valid" class="csv_not_valid" value="<?php echo $url; ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$url'
Loading history...
424
				<?php
425
			} else {
426
				?>
427
				<tr valign="top" class="give-import-dropdown">
428
					<th colspan="2">
429
						<h2 id="give-import-title"><?php esc_html_e( 'Map CSV fields to donations', 'give' ) ?></h2>
430
431
						<p class="give-import-donation-required-fields-title"><?php _e( 'Required Fields' ); ?></p>
432
433
						<p class="give-field-description"><?php _e( 'These fields are required for the import to submitted' ); ?></p>
434
435
						<ul class="give-import-donation-required-fields">
436
							<li class="give-import-donation-required-email"
437
							    title="Please configure all required fields to start the import process.">
438
								<span class="give-import-donation-required-symbol dashicons dashicons-no-alt"></span>
439
								<span class="give-import-donation-required-text">
440
									<?php
441
									_e( 'Email Address', 'give' );
442
									?>
443
								</span>
444
							</li>
445
446
							<li class="give-import-donation-required-first"
447
							    title="Please configure all required fields to start the import process.">
448
								<span class="give-import-donation-required-symbol dashicons dashicons-no-alt"></span>
449
								<span class="give-import-donation-required-text">
450
									<?php
451
									_e( 'First Name', 'give' );
452
									?>
453
								</span>
454
							</li>
455
456
							<li class="give-import-donation-required-amount"
457
							    title="Please configure all required fields to start the import process.">
458
								<span class="give-import-donation-required-symbol dashicons dashicons-no-alt"></span>
459
								<span class="give-import-donation-required-text">
460
									<?php
461
									_e( 'Donation Amount', 'give' );
462
									?>
463
								</span>
464
							</li>
465
466
							<li class="give-import-donation-required-form"
467
							    title="Please configure all required fields to start the import process.">
468
								<span class="give-import-donation-required-symbol dashicons dashicons-no-alt"></span>
469
								<span class="give-import-donation-required-text">
470
									<?php
471
									_e( 'Form Title or ID', 'give' );
472
									?>
473
								</span>
474
							</li>
475
						</ul>
476
477
						<p class="give-field-description"><?php esc_html_e( 'Select fields from your CSV file to map against donations fields or to ignore during import.', 'give' ) ?></p>
478
					</th>
479
				</tr>
480
481
				<tr valign="top" class="give-import-dropdown">
482
					<th><b><?php esc_html_e( 'Column name', 'give' ); ?></b></th>
483
					<th><b><?php esc_html_e( 'Map to field', 'give' ); ?></b></th>
484
				</tr>
485
486
				<?php
487
				$raw_key = $this->get_importer( $csv, 0, $delimiter );
0 ignored issues
show
Bug introduced by
It seems like $delimiter defined by !empty($_GET['delimiter'...T['delimiter']) : 'csv' on line 417 can also be of type array; however, Give_Import_Donations::get_importer() 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...
488
				$mapto   = (array) ( isset( $_REQUEST['mapto'] ) ? $_REQUEST['mapto'] : array() );
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...
489
490
				foreach ( $raw_key as $index => $value ) {
0 ignored issues
show
Bug introduced by
The expression $raw_key of type array<integer,string|nul...":"string|null"}>|false is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
491
					?>
492
					<tr valign="top" class="give-import-option">
493
						<th><?php echo $value; ?></th>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$value'
Loading history...
494
						<th>
495
							<?php
496
							$this->get_columns( $index, $value, $mapto );
497
							?>
498
						</th>
499
					</tr>
500
					<?php
501
				}
502
			}
503
		}
504
505
		/**
506
		 * @param $option_value
507
		 * @param $value
508
		 *
509
		 * @return string
510
		 */
511
		public function selected( $option_value, $value ) {
512
			$option_value = strtolower( $option_value );
513
			$value        = strtolower( $value );
514
515
			$selected = '';
516
			if ( stristr( $value, $option_value ) ) {
517
				$selected = 'selected';
518
			} elseif ( strrpos( $value, 'give_' ) && stristr( $option_value, __( 'Import as Meta', 'give' ) ) ) {
519
				$selected = 'selected';
520
			}
521
522
			return $selected;
523
		}
524
525
		/**
526
		 * Print the columns from the CSV.
527
		 *
528
		 * @since  1.8.14
529
		 * @access private
530
		 *
531
		 * @param string $index
532
		 * @param bool   $value
533
		 * @param array  $mapto
534
		 *
535
		 * @return void
536
		 */
537
		private function get_columns( $index, $value = false, $mapto = array() ) {
538
			$default       = give_import_default_options();
539
			$current_mapto = (string) ( ! empty( $mapto[ $index ] ) ? $mapto[ $index ] : '' );
540
			?>
541
			<select name="mapto[<?php echo $index; ?>]">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$index'
Loading history...
542
				<?php $this->get_dropdown_option_html( $default, $current_mapto, $value ); ?>
543
544
				<optgroup label="<?php _e( 'Donations', 'give' ); ?>">
545
					<?php
546
					$this->get_dropdown_option_html( give_import_donations_options(), $current_mapto, $value );
547
					?>
548
				</optgroup>
549
550
				<optgroup label="<?php _e( 'Donors', 'give' ); ?>">
551
					<?php
552
					$this->get_dropdown_option_html( give_import_donor_options(), $current_mapto, $value );
553
					?>
554
				</optgroup>
555
556
				<optgroup label="<?php _e( 'Forms', 'give' ); ?>">
557
					<?php
558
					$this->get_dropdown_option_html( give_import_donation_form_options(), $current_mapto, $value );
559
					?>
560
				</optgroup>
561
562
				<?php
563
				/**
564
				 * Fire the action
565
				 * You can use this filter to add new options.
566
				 *
567
				 * @since 1.8.15
568
				 */
569
				do_action( 'give_import_dropdown_option', $index, $value, $mapto, $current_mapto );
570
				?>
571
			</select>
572
			<?php
573
		}
574
575
		/**
576
		 * Print the option html for select in importer
577
		 *
578
		 * @since  1.8.15
579
		 * @access public
580
		 *
581
		 * @param  array  $options
582
		 * @param  string $current_mapto
583
		 * @param bool    $value
584
		 *
585
		 * @return void
586
		 */
587
		public function get_dropdown_option_html( $options, $current_mapto, $value = false ) {
588
			foreach ( $options as $option => $option_value ) {
589
				$option_value_texts = (array) $option_value;
590
				$option_text        = $option_value_texts[0];
591
592
				$checked = ( ( $current_mapto === $option ) ? 'selected' : false );
593
				if ( empty( $checked ) ) {
594
					foreach ( $option_value_texts as $option_value_text ) {
595
						$checked = $this->selected( $option_value_text, $value );
596
						if ( $checked ) {
597
							break;
598
						}
599
					}
600
				}
601
602
				echo sprintf(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
603
					'<option value="%1$s" %2$s >%3$s</option>',
604
					$option,
605
					$checked,
606
					$option_text
607
				);
608
			}
609
		}
610
611
		/**
612
		 * Get column count of csv file.
613
		 *
614
		 * @since 1.8.14
615
		 *
616
		 * @param $file_id
617
		 *
618
		 * @return bool|int
619
		 */
620
		public function get_csv_total( $file_id ) {
621
			$total = false;
622
			if ( $file_id ) {
623
				$file_dir = get_attached_file( $file_id );
624
				if ( $file_dir ) {
625
					$file = new SplFileObject( $file_dir, 'r' );
626
					$file->seek( PHP_INT_MAX );
627
					$total = $file->key() + 1;
628
				}
629
			}
630
631
			return $total;
632
		}
633
634
		/**
635
		 * Get the CSV fields title from the CSV.
636
		 *
637
		 * @since 1.8.14
638
		 *
639
		 * @param (int) $file_id
640
		 * @param int    $index
641
		 * @param string $delimiter
642
		 *
643
		 * @return array|bool $raw_data title of the CSV file fields
644
		 */
645
		public function get_importer( $file_id, $index = 0, $delimiter = 'csv' ) {
646
			/**
647
			 * Filter to modify delimiter of Import.
648
			 *
649
			 * @since 1.8.14
650
			 *
651
			 * Return string $delimiter.
652
			 */
653
			$delimiter = (string) apply_filters( 'give_import_delimiter_set', $delimiter );
654
655
			$raw_data = false;
656
			$file_dir = get_attached_file( $file_id );
657
			if ( $file_dir ) {
658
				if ( false !== ( $handle = fopen( $file_dir, 'r' ) ) ) {
659
					$raw_data = fgetcsv( $handle, $index, $delimiter );
660
					// Remove BOM signature from the first item.
661
					if ( isset( $raw_data[0] ) ) {
662
						$raw_data[0] = $this->remove_utf8_bom( $raw_data[0] );
663
					}
664
				}
665
			}
666
667
			return $raw_data;
668
		}
669
670
		/**
671
		 * Remove UTF-8 BOM signature.
672
		 *
673
		 * @since 1.8.14
674
		 *
675
		 * @param  string $string String to handle.
676
		 *
677
		 * @return string
678
		 */
679
		public function remove_utf8_bom( $string ) {
680
			if ( 'efbbbf' === substr( bin2hex( $string ), 0, 6 ) ) {
681
				$string = substr( $string, 3 );
682
			}
683
684
			return $string;
685
		}
686
687
688
		/**
689
		 * Is used to show the process when user upload the donor form.
690
		 *
691
		 * @since 1.8.14
692
		 */
693
		public function render_progress() {
694
			$step = $this->get_step();
695
			?>
696
			<ol class="give-progress-steps">
697
				<li class="<?php echo( 1 === $step ? 'active' : '' ); ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
698
					<?php esc_html_e( 'Upload CSV file', 'give' ); ?>
699
				</li>
700
				<li class="<?php echo( 2 === $step ? 'active' : '' ); ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
701
					<?php esc_html_e( 'Column mapping', 'give' ); ?>
702
				</li>
703
				<li class="<?php echo( 3 === $step ? 'active' : '' ); ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
704
					<?php esc_html_e( 'Import', 'give' ); ?>
705
				</li>
706
				<li class="<?php echo( 4 === $step ? 'active' : '' ); ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
707
					<?php esc_html_e( 'Done!', 'give' ); ?>
708
				</li>
709
			</ol>
710
			<?php
711
		}
712
713
		/**
714
		 * Will return the import step.
715
		 *
716
		 * @since 1.8.14
717
		 *
718
		 * @return int $step on which step doest the import is on.
719
		 */
720 View Code Duplication
		public function get_step() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
721
			$step    = (int) ( isset( $_REQUEST['step'] ) ? give_clean( $_REQUEST['step'] ) : 0 );
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...
722
			$on_step = 1;
723
724
			if ( empty( $step ) || 1 === $step ) {
725
				$on_step = 1;
726
			} elseif ( $this->check_for_dropdown_or_import() ) {
727
				$on_step = 3;
728
			} elseif ( 2 === $step ) {
729
				$on_step = 2;
730
			} elseif ( 4 === $step ) {
731
				$on_step = 4;
732
			}
733
734
			return $on_step;
735
		}
736
737
		/**
738
		 * Render donations import page
739
		 *
740
		 * @since 1.8.14
741
		 */
742
		public function render_page() {
743
			include_once GIVE_PLUGIN_DIR . 'includes/admin/tools/views/html-admin-page-import-donations.php';
744
		}
745
746
		/**
747
		 * Add CSV upload HTMl
748
		 *
749
		 * Print the html of the file upload from which CSV will be uploaded.
750
		 *
751
		 * @since 1.8.14
752
		 * @return void
753
		 */
754
		public function render_media_csv() {
755
			?>
756
			<tr valign="top">
757
				<th colspan="2">
758
					<h2 id="give-import-title"><?php esc_html_e( 'Import donations from a CSV file', 'give' ) ?></h2>
759
					<p class="give-field-description"><?php esc_html_e( 'This tool allows you to import or add donation data to your give form(s) via a CSV file.', 'give' ) ?></p>
760
				</th>
761
			</tr>
762
			<?php
763
			$csv         = ( isset( $_POST['csv'] ) ? give_clean( $_POST['csv'] ) : '' );
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...
764
			$csv_id      = ( isset( $_POST['csv_id'] ) ? give_clean( $_POST['csv_id'] ) : '' );
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...
765
			$delimiter   = ( isset( $_POST['delimiter'] ) ? give_clean( $_POST['delimiter'] ) : 'csv' );
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...
766
			$mode        = empty( $_POST['mode'] ) ?
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
767
				'disabled' :
768
				( give_is_setting_enabled( give_clean( $_POST['mode'] ) ) ? 'enabled' : 'disabled' );
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...
769
			$create_user = empty( $_POST['create_user'] ) ?
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
770
				'enabled' :
771
				( give_is_setting_enabled( give_clean( $_POST['create_user'] ) ) ? 'enabled' : 'disabled' );
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...
772
			$delete_csv  = empty( $_POST['delete_csv'] ) ?
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
773
				'enabled' :
774
				( give_is_setting_enabled( give_clean( $_POST['delete_csv'] ) ) ? 'enabled' : 'disabled' );
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...
775
776
			// Reset csv and csv_id if csv
777
			if ( empty( $csv_id ) || ! $this->is_valid_csv( $csv_id, $csv ) ) {
0 ignored issues
show
Bug introduced by
It seems like $csv defined by isset($_POST['csv']) ? g...ean($_POST['csv']) : '' on line 763 can also be of type array; however, Give_Import_Donations::is_valid_csv() 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...
778
				$csv_id = $csv = '';
779
			}
780
			$per_page = isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : self::$per_page;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
781
782
			$sample_file_text = sprintf( 'Download the sample file <a href="%s">here</a>.', esc_url( GIVE_PLUGIN_URL . 'sample-data/sample-data.csv' ) );
783
784
			$csv_description = sprintf(
785
				'%1$s %2$s',
786
				__( 'The file must be a Comma Seperated Version (CSV) file type only.', 'give' ),
787
				$sample_file_text
788
			);
789
790
			$settings = array(
791
				array(
792
					'id'          => 'csv',
793
					'name'        => __( 'Choose a CSV file:', 'give' ),
794
					'type'        => 'file',
795
					'attributes'  => array( 'editing' => 'false', 'library' => 'text' ),
796
					'description' => $csv_description,
797
					'fvalue'      => 'url',
798
					'default'     => $csv,
799
				),
800
				array(
801
					'id'    => 'csv_id',
802
					'type'  => 'hidden',
803
					'value' => $csv_id,
804
				),
805
				array(
806
					'id'          => 'delimiter',
807
					'name'        => __( 'CSV Delimiter:', 'give' ),
808
					'description' => __( 'In case your CSV file supports a different type of separator (or delimiter) -- like a tab or space -- you can set that here.', 'give' ),
809
					'default'     => $delimiter,
810
					'type'        => 'select',
811
					'options'     => array(
812
						'csv'                  => esc_html__( 'Comma', 'give' ),
813
						'tab-separated-values' => esc_html__( 'Tab', 'give' ),
814
					),
815
				),
816
				array(
817
					'id'          => 'mode',
818
					'name'        => __( 'Test Mode:', 'give' ),
819
					'description' => __( 'Test mode allows you to preview what this import would look like without making any actual changes to your site or your database.', 'give' ),
820
					'default'     => $mode,
821
					'type'        => 'radio_inline',
822
					'options'     => array(
823
						'enabled'  => __( 'Enabled', 'give' ),
824
						'disabled' => __( 'Disabled', 'give' ),
825
					),
826
				),
827
				array(
828
					'id'          => 'create_user',
829
					'name'        => __( 'Create WP users for new donors:', 'give' ),
830
					'description' => __( 'The importer can create WordPress user accounts based on the names and email addresses of the donations in your CSV file. Enable this option if you\'d like the importer to do that.', 'give' ),
831
					'default'     => $create_user,
832
					'type'        => 'radio_inline',
833
					'options'     => array(
834
						'enabled'  => __( 'Enabled', 'give' ),
835
						'disabled' => __( 'Disabled', 'give' ),
836
					),
837
				),
838
				array(
839
					'id'          => 'delete_csv',
840
					'name'        => __( 'Delete CSV after import:', 'give' ),
841
					'description' => __( 'Your CSV file will be uploaded via the WordPress Media Library. It\'s a good idea to delete it after the import is finished so that your sensitive data is not accessible on the web. Disable this only if you plan to delete the file manually later.', 'give' ),
842
					'default'     => $delete_csv,
843
					'type'        => 'radio_inline',
844
					'options'     => array(
845
						'enabled'  => __( 'Enabled', 'give' ),
846
						'disabled' => __( 'Disabled', 'give' ),
847
					),
848
				),
849
				array(
850
					'id'          => 'per_page',
851
					'name'        => __( 'Process Rows Per Batch:', 'give' ),
852
					'type'        => 'number',
853
					'description' => __( 'Determine how many rows you would like to import per cycle.', 'give' ),
854
					'default'     => $per_page,
855
					'class'       => 'give-text-small',
856
				),
857
			);
858
859
			$settings = apply_filters( 'give_import_file_upload_html', $settings );
860
861
			if ( empty( $this->is_csv_valid ) ) {
862
				Give_Admin_Settings::output_fields( $settings, 'give_settings' );
863
			} else {
864
				?>
865
				<input type="hidden" name="is_csv_valid" class="is_csv_valid" value="<?php echo $this->is_csv_valid; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$this'
Loading history...
866
				<?php
867
			}
868
		}
869
870
		/**
871
		 * Run when user click on the submit button.
872
		 *
873
		 * @since 1.8.14
874
		 */
875
		public function save() {
876
			// Get the current step.
877
			$step = $this->get_step();
878
879
			// Validation for first step.
880
			if ( 1 === $step ) {
881
				$csv_id = absint( $_POST['csv_id'] );
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...
882
883
				if ( $this->is_valid_csv( $csv_id, esc_url( $_POST['csv'] ) ) ) {
884
885
					$url = give_import_page_url( (array) apply_filters( 'give_import_step_two_url', array(
886
						'step'          => '2',
887
						'importer-type' => $this->importer_type,
888
						'csv'           => $csv_id,
889
						'delimiter'     => isset( $_REQUEST['delimiter'] ) ? give_clean( $_REQUEST['delimiter'] ) : 'csv',
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...
890
						'mode'          => empty( $_POST['mode'] ) ?
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
891
							'0' :
892
							( give_is_setting_enabled( give_clean( $_POST['mode'] ) ) ? '1' : '0' ),
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...
893
						'create_user'   => empty( $_POST['create_user'] ) ?
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
894
							'0' :
895
							( give_is_setting_enabled( give_clean( $_POST['create_user'] ) ) ? '1' : '0' ),
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...
896
						'delete_csv'    => empty( $_POST['delete_csv'] ) ?
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
897
							'1' :
898
							( give_is_setting_enabled( give_clean( $_POST['delete_csv'] ) ) ? '1' : '0' ),
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...
899
						'per_page'      => isset( $_POST['per_page'] ) ? absint( $_POST['per_page'] ) : self::$per_page,
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
900
					) ) );
901
902
					$this->is_csv_valid = $url;
0 ignored issues
show
Documentation Bug introduced by
The property $is_csv_valid was declared of type integer, but $url is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
903
				}
904
			}
905
		}
906
907
		/**
908
		 * Check if user uploaded csv is valid or not.
909
		 *
910
		 * @since  1.8.14
911
		 * @access public
912
		 *
913
		 * @param mixed  $csv       ID of the CSV files.
914
		 * @param string $match_url ID of the CSV files.
915
		 *
916
		 * @return bool $has_error CSV is valid or not.
917
		 */
918
		private function is_valid_csv( $csv = false, $match_url = '' ) {
919
			$is_valid_csv = true;
920
921
			if ( $csv ) {
922
				$csv_url = wp_get_attachment_url( $csv );
923
924
				$delimiter = ( ! empty( $_REQUEST['delimiter'] ) ? give_clean( $_REQUEST['delimiter'] ) : 'csv' );
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...
925
926
				if (
927
					! $csv_url ||
928
					( ! empty( $match_url ) && ( $csv_url !== $match_url ) ) ||
929
					( ( $mime_type = get_post_mime_type( $csv ) ) && ! strpos( $mime_type, $delimiter ) )
930
				) {
931
					$is_valid_csv = false;
932
					Give_Admin_Settings::add_error( 'give-import-csv', __( 'Please upload or provide a valid CSV file.', 'give' ) );
933
				}
934
			} else {
935
				$is_valid_csv = false;
936
				Give_Admin_Settings::add_error( 'give-import-csv', __( 'Please upload or provide a valid CSV file.', 'give' ) );
937
			}
938
939
			return $is_valid_csv;
940
		}
941
942
943
		/**
944
		 * Render report import field
945
		 *
946
		 * @since  1.8.14
947
		 * @access public
948
		 *
949
		 * @param $field
950
		 * @param $option_value
951
		 */
952
		public function render_import_field( $field, $option_value ) {
953
			include_once GIVE_PLUGIN_DIR . 'includes/admin/tools/views/html-admin-page-imports.php';
954
		}
955
956
		/**
957
		 * Get if current page import donations page or not
958
		 *
959
		 * @since 1.8.14
960
		 * @return bool
961
		 */
962
		private function is_donations_import_page() {
963
			return 'import' === give_get_current_setting_tab() &&
964
			       isset( $_GET['importer-type'] ) &&
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
965
			       $this->importer_type === give_clean( $_GET['importer-type'] );
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...
966
		}
967
	}
968
969
	Give_Import_Donations::get_instance()->setup();
970
}
971