Test Failed
Push — issue/2900 ( f2122b...7f8e46 )
by Ravinder
05:24
created

import-functions.php ➔ give_check_import_donation_duplicate()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 61
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 43
nc 5
nop 4
dl 0
loc 61
rs 8.9392
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
 * Import Functions
4
 *
5
 * @package     Give
6
 * @subpackage  Functions
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.8.14
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Get the Import report of the donations
19
 *
20
 * @since 1.8.13
21
 */
22
function give_import_donation_report() {
23
	return get_option( 'give_import_donation_report', array() );
24
}
25
26
27
/**
28
 * Update the Import report of the donations
29
 *
30
 * @since 1.8.13
31
 */
32
function give_import_donation_report_update( $value = array() ) {
33
	update_option( 'give_import_donation_report', $value );
34
}
35
36
37
/**
38
 * Delete the Import report of the donations
39
 *
40
 * @since 1.8.13
41
 */
42
function give_import_donation_report_reset() {
43
	update_option( 'give_import_donation_report', array() );
44
}
45
46
/**
47
 * Give get form data from csv if not then create and form and return the form value.
48
 *
49
 * @since 1.8.13.
50
 *
51
 * @param $data .
52
 *
53
 * @return array|bool|Give_Donate_Form|int|null|WP_Post
54
 */
55
function give_import_get_form_data_from_csv( $data, $import_setting = array() ) {
56
	$new_form = false;
57
	$dry_run  = isset( $import_setting['dry_run'] ) ? $import_setting['dry_run'] : false;
58
59
	// Get the import report
60
	$report = give_import_donation_report();
61
62
	$form = false;
63
	$meta = array();
64
65
	if ( ! empty( $data['form_id'] ) ) {
66
		$form = new Give_Donate_Form( $data['form_id'] );
67
		// Add support to older php version.
68
		$form_id = $form->get_ID();
69
		if ( empty( $form_id ) ) {
70
			$form = false;
71
		} else {
72
			$report['duplicate_form'] = ( ! empty( $report['duplicate_form'] ) ? ( absint( $report['duplicate_form'] ) + 1 ) : 1 );
73
		}
74
	}
75
76
	if ( false === $form && ! empty( $data['form_title'] ) ) {
77
		$form = get_page_by_title( $data['form_title'], OBJECT, 'give_forms' );
78
79
		if ( ! empty( $form->ID ) ) {
80
81
			$report['duplicate_form'] = ( ! empty( $report['duplicate_form'] ) ? ( absint( $report['duplicate_form'] ) + 1 ) : 1 );
82
83
			$form = new Give_Donate_Form( $form->ID );
0 ignored issues
show
Unused Code introduced by
$form 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...
84
		} else {
85
			$form = new Give_Donate_Form();
86
			$args = array(
87
				'post_title'  => $data['form_title'],
88
				'post_status' => 'publish',
89
			);
90
91
			if ( empty( $dry_run ) ) {
92
				$form = $form->create( $args );
0 ignored issues
show
Unused Code introduced by
$form 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...
93
			}
94
95
			$report['create_form'] = ( ! empty( $report['create_form'] ) ? ( absint( $report['create_form'] ) + 1 ) : 1 );
96
			$new_form              = true;
97
98
		}
99
100
		$form = get_page_by_title( $data['form_title'], OBJECT, 'give_forms' );
101
		if ( ! empty( $form->ID ) ) {
102
			$form = new Give_Donate_Form( $form->ID );
103
		}
104
	}
105
106
	if ( ! empty( $form ) && $form->get_ID() && ! empty( $data['form_level'] ) && empty( $dry_run ) ) {
107
108
		$price_option = 'set';
109
		$form_level   = strtolower( preg_replace( '/\s+/', '', $data['form_level'] ) );
110
111
		if ( 'custom' !== $form_level ) {
112
			$prices     = (array) $form->get_prices();
113
			$price_text = array();
114
			foreach ( $prices as $key => $price ) {
115
				if ( isset( $price['_give_id']['level_id'] ) ) {
116
					$price_text[ $price['_give_id']['level_id'] ] = ( ! empty( $price['_give_text'] ) ? strtolower( preg_replace( '/\s+/', '', $price['_give_text'] ) ) : '' );
117
				}
118
			}
119
120
			if ( ! in_array( $form_level, $price_text ) ) {
121
122
				// For generating unquiet level id.
123
				$count     = 1;
124
				$new_level = count( $prices ) + $count;
125
				while ( array_key_exists( $new_level, $price_text ) ) {
126
					$count ++;
127
					$new_level = count( $prices ) + $count;
128
				}
129
130
				$multi_level_donations = array(
131
					array(
132
						'_give_id'     => array(
133
							'level_id' => $new_level,
134
						),
135
						'_give_amount' => give_sanitize_amount_for_db( $data['amount'] ),
136
						'_give_text'   => $data['form_level'],
137
					),
138
				);
139
140
				$price_text[ $new_level ] = strtolower( preg_replace( '/\s+/', '', $data['form_level'] ) );
141
142
				if ( ! empty( $prices ) && is_array( $prices ) && ! empty( $prices[0] ) ) {
143
					$prices = wp_parse_args( $multi_level_donations, $prices );
144
145
					// Sort $prices by amount in ascending order.
146
					$prices = wp_list_sort( $prices, '_give_amount', 'ASC' );
147
				} else {
148
					$prices = $multi_level_donations;
149
				}
150
151
				// Unset _give_default key from $prices.
152
				foreach ( $prices as $key => $price ) {
153
					if ( isset( $prices[ $key ]['_give_default'] ) ) {
154
						unset( $prices[ $key ]['_give_default'] );
155
					}
156
				}
157
158
				// Set the first $price of the $prices as default.
159
				$prices[0]['_give_default'] = 'default';
160
			}
161
			$form->price_id = array_search( $form_level, $price_text );
162
163
			$donation_levels_amounts = wp_list_pluck( $prices, '_give_amount' );
164
			$min_amount              = min( $donation_levels_amounts );
165
			$max_amount              = max( $donation_levels_amounts );
166
167
			$meta = array(
168
				'_give_levels_minimum_amount' => $min_amount,
169
				'_give_levels_maximum_amount' => $max_amount,
170
				'_give_donation_levels'       => array_values( $prices ),
171
			);
172
173
			$price_option = 'multi';
174
		} else {
175
			$form->price_id = 'custom';
176
		}
177
178
		$defaults = array(
179
			'_give_set_price' => give_sanitize_amount_for_db( $data['amount'] ),
180
		);
181
182
		// If new form is created.
183
		if ( ! empty( $new_form ) ) {
184
			$new_form = array(
185
				'_give_custom_amount_text' => ( ! empty( $data['form_custom_amount_text'] ) ? $data['form_custom_amount_text'] : 'Custom' ),
186
				'_give_logged_in_only'     => 'enabled',
187
				'_give_custom_amount'      => 'enabled',
188
				'_give_payment_import'     => true,
189
				'_give_display_style'      => 'radios',
190
				'_give_payment_display'    => 'onpage',
191
				'give_product_notes'       => 'Donation Notes',
192
				'_give_product_type'       => 'default',
193
				'_give_default_gateway'    => 'global',
194
				'_give_show_register_form' => 'both',
195
				'_give_price_option'       => $price_option,
196
			);
197
			$defaults = wp_parse_args( $defaults, $new_form );
198
		}
199
200
		$meta = wp_parse_args( $meta, $defaults );
201
202
		foreach ( $meta as $key => $value ) {
203
			give_update_meta( $form->get_ID(), $key, $value );
204
		}
205
	}
206
207
	// update the report
208
	give_import_donation_report_update( $report );
209
210
	return $form;
211
}
212
213
/**
214
 * Give get user details if not then create a user. Used in Import Donation CSV.
215
 *
216
 * @since 1.8.13
217
 *
218
 * @param $data
219
 *
220
 * @return bool|false|WP_User
221
 */
222
function give_import_get_user_from_csv( $data, $import_setting = array() ) {
223
	$report               = give_import_donation_report();
224
	$dry_run              = isset( $import_setting['dry_run'] ) ? $import_setting['dry_run'] : false;
225
	$dry_run_donor_create = false;
226
	$donor_data           = array();
227
	$donor_id             = false;
228
229
	// check if donor id is not empty
230
	if ( ! empty( $data['donor_id'] ) ) {
231
		$donor_data = new Give_Donor( (int) $data['donor_id'] );
232 View Code Duplication
		if ( ! empty( $donor_data->id ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
233
			$report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 );
234
		}
235
	}
236
237
	if ( empty( $donor_data->id ) && ! empty( $data['user_id'] ) ) {
238
		$user_id    = (int) $data['user_id'];
239
		$donor_data = new Give_Donor( $user_id, true );
240
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
241
242
		if ( empty( $donor_data->id ) ) {
243
			$donor_data = get_user_by( 'id', $user_id );
244
245
			// if no wp user is found then no donor is create with that user id
246
			if ( ! empty( $donor_data->ID ) ) {
247
248
				if ( empty( $dry_run ) ) {
249
					$first_name = ( ! empty( $data['first_name'] ) ? $data['first_name'] : $donor_data->user_nicename );
250
					$last_name  = ( ! empty( $data['last_name'] ) ? $data['last_name'] : ( ( $lastname = get_user_meta( $donor_data->ID, 'last_name', true ) ) ? $lastname : '' ) );
0 ignored issues
show
introduced by
get_user_meta() usage is highly discouraged, check VIP documentation on "Working with wp_users"
Loading history...
251
					$name       = $first_name . ' ' . $last_name;
252
					$user_email = $donor_data->user_email;
253
					$donor_args = array(
254
						'name'    => $name,
255
						'email'   => $user_email,
256
						'user_id' => $user_id,
257
					);
258
259
					$donor_data = new Give_Donor();
260
					$donor_data->create( $donor_args );
261
262
					// Adding notes that donor is being imported from CSV.
263
					$current_user = wp_get_current_user();
264
					$donor_data->add_note( wp_sprintf( __( 'This donor was imported by %s', 'give' ), $current_user->user_email ) );
265
266
					// Add is used to ensure duplicate emails are not added
267
					if ( $user_email != $data['email'] && ! empty( $data['email'] ) ) {
268
						$donor_data->add_meta( 'additional_email', $data['email'] );
269
					}
270
				} else {
271
					$dry_run_donor_create = true;
272
					$donor_data           = array( 'id' => 1 );
273
				}
274
275
				$report['create_donor'] = ( ! empty( $report['create_donor'] ) ? ( absint( $report['create_donor'] ) + 1 ) : 1 );
276
			} elseif ( $dry_run ) {
277
				$donor_data = array();
278
			}
279
		} else {
280
			// Add is used to ensure duplicate emails are not added
281
			if ( $donor_data->email != $data['email'] && empty( $dry_run ) ) {
282
				$donor_data->add_meta( 'additional_email', ( ! empty( $data['email'] ) ? $data['email'] : $donor_data->email ) );
283
			}
284
			$report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 );
285
		}
286
	}
287
288
	if ( empty( $donor_data->id ) && ! empty( $data['email'] ) && empty( $dry_run_donor_create ) ) {
289
290
		$donor_data = new Give_Donor( $data['email'] );
291
		if ( empty( $donor_data->id ) ) {
292
			$donor_data = get_user_by( 'email', $data['email'] );
293
294
			if ( empty( $donor_data->ID ) && isset( $import_setting['create_user'] ) && 1 === absint( $import_setting['create_user'] ) ) {
295
				$data['first_name'] = ( ! empty( $data['first_name'] ) ? $data['first_name'] : $data['email'] );
296
				$data['last_name']  = ( ! empty( $data['last_name'] ) ? $data['last_name'] : '' );
297
				$give_role          = (array) give_get_option( 'donor_default_user_role', get_option( 'default_role', ( ( $give_donor = wp_roles()->is_role( 'give_donor' ) ) && ! empty( $give_donor ) ? 'give_donor' : 'subscriber' ) ) );
298
				$donor_args         = array(
299
					'user_login'      => $data['email'],
300
					'user_email'      => $data['email'],
301
					'user_registered' => date( 'Y-m-d H:i:s' ),
302
					'user_first'      => $data['first_name'],
303
					'user_last'       => $data['last_name'],
304
					'user_pass'       => wp_generate_password( 8, true ),
305
					'role'            => $give_role,
306
				);
307
308
				/**
309
				 * Filter to modify user data before new user id register.
310
				 *
311
				 * @since 1.8.13
312
				 */
313
				$donor_args = (array) apply_filters( 'give_import_insert_user_args', $donor_args, $data, $import_setting );
314
315
				if ( empty( $dry_run ) ) {
316
317
					// This action was added to remove the login when using the give register function.
318
					add_filter( 'give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11 );
319
					$donor_id = give_register_and_login_new_user( $donor_args );
320
					remove_filter( 'give_log_user_in_on_register', 'give_log_user_in_on_register_callback', 11 );
321
322
					$donor_data = new Give_Donor( $donor_id, true );
323
					$donor_data->update_meta( '_give_payment_import', true );
324
325 View Code Duplication
				} else {
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...
326
					$dry_run_donor_create   = true;
327
					$report['create_donor'] = ( ! empty( $report['create_donor'] ) ? ( absint( $report['create_donor'] ) + 1 ) : 1 );
328
				}
329
			} else {
330
				$donor_id = ( ! empty( $donor_data->ID ) ? $donor_data->ID : false );
331
			}
332
333
			if ( empty( $dry_run_donor_create ) && ( ! empty( $donor_id ) || ( isset( $import_setting['create_user'] ) && 0 === absint( $import_setting['create_user'] ) ) ) ) {
334
				$donor_data = new Give_Donor( $donor_id, true );
335
336
				if ( empty( $donor_data->id ) ) {
337
338
					if ( ! empty( $data['form_id'] ) ) {
339
						$form = new Give_Donate_Form( $data['form_id'] );
340
					}
341
342
					if ( empty( $dry_run ) ) {
343
						$payment_title = ( isset( $data['form_title'] ) ? $data['form_title'] : ( isset( $form ) ? $form->get_name() : __( 'New Form', 'give' ) ) );
344
						$donor_args    = array(
345
							'name'  => ! is_email( $payment_title ) ? $data['first_name'] . ' ' . $data['last_name'] : '',
346
							'email' => $data['email'],
347
						);
348
						if ( ! empty( $donor_id ) ) {
349
							$donor_args['user_id'] = $donor_id;
350
						}
351
						$donor_data->create( $donor_args );
352
353
						// Adding notes that donor is being imported from CSV.
354
						$current_user = wp_get_current_user();
355
						$donor_data->add_note( wp_sprintf( __( 'This donor was imported by %s', 'give' ), $current_user->user_email ) );
356
					} else {
357
						$dry_run_donor_create = true;
0 ignored issues
show
Unused Code introduced by
$dry_run_donor_create 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...
358
					}
359
					$report['create_donor'] = ( ! empty( $report['create_donor'] ) ? ( absint( $report['create_donor'] ) + 1 ) : 1 );
360 View Code Duplication
				} else {
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...
361
					$report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 );
362
				}
363
			}
364 View Code Duplication
		} else {
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...
365
			$report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 );
366
		}
367
	}
368
	// update the report
369
	give_import_donation_report_update( $report );
370
371
	return $donor_data;
372
}
373
374
/**
375
 * Return the option that are default options.
376
 *
377
 * @since 1.8.13
378
 */
379
function give_import_default_options() {
380
	/**
381
	 * Filter to modify default option in the import dropdown
382
	 *
383
	 * @since 1.8.13
384
	 *
385
	 * @return array
386
	 */
387
	return (array) apply_filters( 'give_import_default_options', array(
388
		'' => __( 'Do not import', 'give' ),
389
	) );
390
}
391
392
/**
393
 * Return the option that are related to donations.
394
 *
395
 * @since 1.8.13
396
 */
397
function give_import_donations_options() {
398
	/**
399
	 * Filter to modify donations option in the import dropdown
400
	 *
401
	 * @since 1.8.13
402
	 *
403
	 * @return array
404
	 */
405
	return (array) apply_filters( 'give_import_donations_options', array(
406
		'id'          => __( 'Donation ID', 'give' ),
407
		'amount'      => array(
408
			__( 'Donation Amount', 'give' ),
409
			__( 'Amount', 'give' )
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
410
		),
411
		'currency'      => array(
412
			__( 'Donation Currencies', 'give' ),
413
			__( 'Currencies', 'give' )
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
414
		),
415
		'post_date'   => array(
416
			__( 'Donation Date', 'give' ),
417
			__( 'Date', 'give' ),
418
		),
419
		'first_name'  => array(
420
			__( 'Donor First Name', 'give' ),
421
			__( 'First Name', 'give' ),
422
			__( 'Name', 'give' ),
423
		),
424
		'last_name'   => array(
425
			__( 'Donor Last Name', 'give' ),
426
			__( 'Last Name', 'give' ),
427
		),
428
		'company_name'   => array(
429
			__( 'Company Name', 'give' ),
430
			__( 'Donor Company Name', 'give' ),
431
			__( 'Donor Company', 'give' ),
432
			__( 'Company', 'give' ),
433
		),
434
		'line1'       => array(
435
			__( 'Address 1', 'give' ),
436
			__( 'Address', 'give' ),
437
		),
438
		'line2'       => __( 'Address 2', 'give' ),
439
		'city'        => __( 'City', 'give' ),
440
		'state'       => array(
441
			__( 'State', 'give' ),
442
			__( 'Province', 'give' ),
443
			__( 'County', 'give' ),
444
			__( 'Region', 'give' ),
445
		),
446
		'country'     => __( 'Country', 'give' ),
447
		'zip'         => array(
448
			__( 'Zip Code', 'give' ),
449
			__( 'Zip', 'give' ),
450
			__( 'zipcode', 'give' ),
451
			__( 'Postal Code', 'give' ),
452
			__( 'Postal', 'give' ),
453
		),
454
		'email'       => array(
455
			__( 'Donor Email', 'give' ),
456
			__( 'Email', 'give' )
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
457
		),
458
		'post_status' => array(
459
			__( 'Donation Status', 'give' ),
460
			__( 'Status', 'give' ),
461
		),
462
		'gateway'     => array(
463
			__( 'Payment Method', 'give' ),
464
			__( 'Method', 'give' ),
465
		),
466
		'notes'       => __( 'Notes', 'give' ),
467
		'mode'        => array(
468
			__( 'Test Mode', 'give' ),
469
			__( 'Mode', 'give' ),
470
		),
471
		'post_meta'   => __( 'Import as Meta', 'give' ),
472
	) );
473
}
474
475
/**
476
 * Return the option that are related to donations.
477
 *
478
 * @since 1.8.13
479
 */
480
function give_import_donor_options() {
481
	/**
482
	 * Filter to modify donors option in the import dropdown
483
	 *
484
	 * @since 1.8.13
485
	 *
486
	 * @return array
487
	 */
488
	return (array) apply_filters( 'give_import_donor_options', array(
489
		'donor_id' => __( 'Donor ID', 'give' ),
490
		'user_id'  => __( 'User ID', 'give' ),
491
	) );
492
}
493
494
/**
495
 * Return the option that are related to donations.
496
 *
497
 * @since 1.8.13
498
 */
499
function give_import_donation_form_options() {
500
	/**
501
	 * Filter to modify form option in the import dropdown
502
	 *
503
	 * @since 1.8.13
504
	 *
505
	 * @return array
506
	 */
507
	return (array) apply_filters( 'give_import_donation_form_options', array(
508
		'form_title'              => array(
509
			__( 'Donation Form Title', 'give' ),
510
			__( 'Donation Form', 'give' ),
511
			__( 'Form Name', 'give' ),
512
			__( 'Title', 'give' ),
513
		),
514
		'form_id'                 => array(
515
			__( 'Donation Form ID', 'give' ),
516
			__( 'Form ID', 'give' )
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
517
		),
518
		'form_level'              => array(
519
			__( 'Donation Level', 'give' ),
520
			__( 'Level', 'give' ),
521
		),
522
		'form_custom_amount_text' => __( 'Custom Amount Text', 'give' ),
523
	) );
524
}
525
526
/**
527
 * Import CSV in DB
528
 *
529
 * @param int    $file_id   CSV id
530
 * @param int    $start     Start from which csv line.
531
 * @param int    $end       End from which csv line.
532
 * @param string $delimiter CSV delimeter.
533
 *
534
 * @return array
535
 */
536
function give_get_donation_data_from_csv( $file_id, $start, $end, $delimiter = 'csv' ) {
537
	/**
538
	 * Filter to modify delimiter of Import.
539
	 *
540
	 * @since
541
	 * 1.8.14
542
	 *
543
	 * Return string $delimiter.
544
	 */
545
	$delimiter = (string) apply_filters( 'give_import_delimiter_set', $delimiter );
546
547
	$raw_data = array();
548
	$file_dir = get_attached_file( $file_id );
549
	$count    = 0;
550
	if ( false !== ( $handle = fopen( $file_dir, 'r' ) ) ) {
551
		while ( false !== ( $row = fgetcsv( $handle, 0, $delimiter ) ) ) {
552
			if ( $count >= $start && $count <= $end ) {
553
				$raw_data[] = $row;
554
			}
555
			$count ++;
556
		}
557
		fclose( $handle );
558
	}
559
560
	return $raw_data;
561
}
562
563
564
/**
565
 * Remove login when user register with give functions.
566
 *
567
 * @since 1.8.13
568
 *
569
 * @param $value
570
 *
571
 * @return bool
572
 */
573
function give_log_user_in_on_register_callback( $value ) {
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

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

Loading history...
574
	return false;
575
}
576
577
/**
578
 * Add import Donation forms, donations , donor from CSV to database
579
 *
580
 * @since 1.8.13
581
 *
582
 * @param array $raw_key Setup bu user at step 2.
583
 * @param array $row_data Feilds that are being imported from CSV
584
 * @param array $main_key First row from the CSV
585
 * @param array $import_setting Contain the global variable.
586
 *
587
 * @return bool
588
 */
589
function give_save_import_donation_to_db( $raw_key, $row_data, $main_key = array(), $import_setting = array() ) {
590
	$data                          = array_combine( $raw_key, $row_data );
591
	$price_id                      = false;
592
	$donor_id                      = 0;
593
	$donor_data                    = array();
594
	$form                          = array();
595
	$import_setting['create_user'] = isset( $import_setting['create_user'] ) ? $import_setting['create_user'] : 1;
596
	$dry_run                       = isset( $import_setting['dry_run'] ) ? $import_setting['dry_run'] : false;
597
	$_dry_run_is_duplicate         = false;
598
	$dry_run_duplicate_form        = false;
599
	$dry_run_duplicate_donor       = false;
600
	$donation_key                  = empty( $import_setting['donation_key'] ) ? 1 : (int) $import_setting['donation_key'];
601
602
	$data = (array) apply_filters( 'give_save_import_donation_to_db', $data );
603
604
	$data['amount'] = give_maybe_sanitize_amount( $data['amount'] );
605
	$diff           = array();
0 ignored issues
show
Unused Code introduced by
$diff 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...
606
607
	if ( ! empty( $dry_run ) && 1 !== $donation_key ) {
608
		$csv_raw_data = empty( $import_setting['csv_raw_data'] ) ? array() : $import_setting['csv_raw_data'];
609
		$donors_list  = empty( $import_setting['donors_list'] ) ? array() : $import_setting['donors_list'];
610
		$key          = $donation_key - 1;
611
		for ( $i = 0; $i < $key; $i ++ ) {
612
			$csv_data           = array_combine( $raw_key, $csv_raw_data[ $i ] );
613
			$csv_data['amount'] = give_maybe_sanitize_amount( $csv_data['amount'] );
614
			// check for duplicate donations
615
			$diff = array_diff( $csv_data, $data );
616
			if ( empty( $diff ) ) {
617
				$_dry_run_is_duplicate   = true;
618
				$dry_run_duplicate_form  = true;
619
				$dry_run_duplicate_donor = true;
620
			} else {
621
				// check for duplicate donation form with form id
622
				if ( ! empty( $csv_data['form_id'] ) && ! empty( $data['form_id'] ) && $csv_data['form_id'] === $data['form_id'] ) {
623
					$form    = new Give_Donate_Form( $data['form_id'] );
624
					$form_id = $form->get_ID();
625
					if ( ! empty( $form_id ) ) {
626
						$dry_run_duplicate_form = true;
627
					}
628
				}
629
				// check for duplicate donation form with form title
630
				if ( empty( $dry_run_duplicate_form ) && ! empty( $csv_data['form_title'] ) && ! empty( $data['form_title'] ) && $csv_data['form_title'] === $data['form_title'] ) {
631
					$dry_run_duplicate_form = true;
632
				}
633
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
634
635
				// check for duplicate donor by donor id
636
				if ( ! empty( $csv_data['donor_id'] ) && ! empty( $data['donor_id'] ) && $csv_data['donor_id'] === $data['donor_id'] ) {
637
					$donor = array_search( (int) $data['donor_id'], array_column( 'id', $donors_list ) );
638
					if ( ! empty( $donor ) ) {
639
						$dry_run_duplicate_donor = true;
640
					}
641
				}
642
643
				// check for duplicate donor by user id
644
				if ( empty( $dry_run_duplicate_donor ) && ! empty( $csv_data['user_id'] ) && ! empty( $data['user_id'] ) && $csv_data['user_id'] === $data['user_id'] ) {
645
					$donor = array_search( (int) $data['user_id'], array_column( 'user_id', $donors_list ) );
646
					if ( ! empty( $donor ) ) {
647
						$dry_run_duplicate_donor = true;
648
					} else {
649
						$donor = get_user_by( 'id', $csv_data['user_id'] );
650
						if ( ! empty( $donor->ID ) ) {
651
							$dry_run_duplicate_donor = true;
652
						}
653
					}
654
				}
655
656
				// check for duplicate donor by donor id
657
				if ( empty( $dry_run_duplicate_donor ) && ! empty( $csv_data['email'] ) && ! empty( $data['email'] ) && $csv_data['email'] === $data['email'] ) {
658
					$dry_run_duplicate_donor = true;
659
				}
660
			}
661
		}
662
	}
663
664
	if ( empty( $dry_run_duplicate_donor ) ) {
665
		// Here come the login function.
666
		$donor_data = give_import_get_user_from_csv( $data, $import_setting );
667
		if ( empty( $dry_run ) ) {
668
			if ( ! empty( $donor_data->id ) ) {
669
				$donor_id = $donor_data->id;
670
			} else {
671
				return false;
672
			}
673
		}
674 View Code Duplication
	} else {
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...
675
		// Get the report
676
		$report                    = give_import_donation_report();
677
		$report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 );
678
		// update the report
679
		give_import_donation_report_update( $report );
680
	}
681
682
	if ( empty( $dry_run_duplicate_form ) ) {
683
		// get form data or register a form data.
684
		$form = give_import_get_form_data_from_csv( $data, $import_setting );
685
		if ( false == $form && empty( $dry_run ) ) {
686
			return false;
687
		} else {
688
			$price_id = ( ! empty( $form->price_id ) ) ? $form->price_id : false;
689
		}
690 View Code Duplication
	} else {
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...
691
		// Get the report
692
		$report                   = give_import_donation_report();
693
		$report['duplicate_form'] = ( ! empty( $report['duplicate_form'] ) ? ( absint( $report['duplicate_form'] ) + 1 ) : 1 );
694
		// update the report
695
		give_import_donation_report_update( $report );
696
	}
697
698
	// Get the report
699
	$report = give_import_donation_report();
0 ignored issues
show
Unused Code introduced by
$report 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...
700
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
701
702
	$status  = give_import_donation_get_status( $data );
703
	$country = ( ! empty( $data['country'] ) ? ( ( $country_code = array_search( $data['country'], give_get_country_list() ) ) ? $country_code : $data['country'] ) : '' );
704
	$state   = ( ! empty( $data['state'] ) ? ( ( $state_code = array_search( $data['state'], give_get_states( $country ) ) ) ? $state_code : $data['state'] ) : '' );
705
706
	$address = array(
707
		'line1'   => ( ! empty( $data['line1'] ) ? give_clean( $data['line1'] ) : '' ),
708
		'line2'   => ( ! empty( $data['line2'] ) ? give_clean( $data['line2'] ) : '' ),
709
		'city'    => ( ! empty( $data['city'] ) ? give_clean( $data['city'] ) : '' ),
710
		'zip'     => ( ! empty( $data['zip'] ) ? give_clean( $data['zip'] ) : '' ),
711
		'state'   => $state,
712
		'country' => $country,
713
	);
714
715
	//Create payment_data array
716
	$payment_data = array(
717
		'donor_id'        => $donor_id,
718
		'price'           => $data['amount'],
719
		'status'          => $status,
720
		'currency'        => ! empty( $data['currency'] ) && array_key_exists( $data['currency'], give_get_currencies_list() ) ? $data['currency'] : give_get_currency(),
721
		'user_info'       => array(
722
			'id'         => $donor_id,
723
			'email'      => ( ! empty( $data['email'] ) ? $data['email'] : ( isset( $donor_data->email ) ? $donor_data->email : false ) ),
724
			'first_name' => ( ! empty( $data['first_name'] ) ? $data['first_name'] : ( ! empty( $donor_id ) && ( $first_name = get_user_meta( $donor_id, 'first_name', true ) ) ? $first_name : $donor_data->name ) ),
0 ignored issues
show
introduced by
get_user_meta() usage is highly discouraged, check VIP documentation on "Working with wp_users"
Loading history...
725
			'last_name'  => ( ! empty( $data['last_name'] ) ? $data['last_name'] : ( ! empty( $donor_id ) && ( $last_name = get_user_meta( $donor_id, 'last_name', true ) ) ? $last_name : $donor_data->name ) ),
0 ignored issues
show
introduced by
get_user_meta() usage is highly discouraged, check VIP documentation on "Working with wp_users"
Loading history...
726
			'address'    => $address,
727
		),
728
		'gateway'         => ( ! empty( $data['gateway'] ) && 'offline' != strtolower( $data['gateway'] ) ? strtolower( $data['gateway'] ) : 'manual' ),
729
		'give_form_title' => ( ! empty( $data['form_title'] ) ? $data['form_title'] : ( method_exists( $form, 'get_name' ) ? $form->get_name() : '' ) ),
730
		'give_form_id'    => method_exists( $form, 'get_ID' ) ? $form->get_ID() : '',
731
		'give_price_id'   => $price_id,
732
		'purchase_key'    => strtolower( md5( uniqid() ) ),
733
		'user_email'      => $data['email'],
734
		'post_date'       => ( ! empty( $data['post_date'] ) ? mysql2date( 'Y-m-d H:i:s', $data['post_date'] ) : current_time( 'mysql' ) ),
735
		'mode'            => ( ! empty( $data['mode'] ) ? ( 'true' == (string) $data['mode'] || 'TRUE' == (string) $data['mode'] ? 'test' : 'live' ) : ( isset( $import_setting['mode'] ) ? ( true == (bool) $import_setting['mode'] ? 'test' : 'live' ) : ( give_is_test_mode() ? 'test' : 'live' ) ) ),
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
736
	);
737
738
	/**
739
	 * Filter to modify payment Data before getting imported.
740
	 *
741
	 * @since 2.1.0
742
	 *
743
	 * @param array $payment_data payment data
744
	 * @param array $payment_data donation data
745
	 * @param array $donor_data donor data
746
	 * @param object $donor_data form object
747
	 *
748
	 * @return array $payment_data payment data
749
	 */
750
	$payment_data = apply_filters( 'give_import_before_import_payment', $payment_data, $data, $donor_data, $form );
751
752
	// Get the report
753
	$report = give_import_donation_report();
754
755
	// Check for duplicate code.
756
	$donation_duplicate = give_check_import_donation_duplicate( $payment_data, $data, $form, $donor_data );
757
	if ( false !== $donation_duplicate || ! empty( $_dry_run_is_duplicate ) ) {
758
		$report['donation_details'][ $import_setting['donation_key'] ]['duplicate'] = $donation_duplicate;
759
		$report['duplicate_donation']                                               = ( ! empty( $report['duplicate_donation'] ) ? ( absint( $report['duplicate_donation'] ) + 1 ) : 1 );
760
	} else {
761
762
		if ( empty( $dry_run ) ) {
763
			add_action( 'give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1, 1 );
764
			add_filter( 'give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11, 2 );
765
			add_filter( 'give_update_donor_information', 'give_donation_import_update_donor_information', 11, 3 );
766
			add_action( 'give_insert_payment', 'give_import_donation_insert_payment', 11, 2 );
767
768
			// if it status is other then pending then first change the donation status to pending and after adding the payment meta update the donation status.
769
			if ( 'pending' !== $status ) {
770
				unset( $payment_data['status'] );
771
			}
772
773
			$payment_id = give_insert_payment( $payment_data );
774
			remove_action( 'give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1 );
775
			remove_filter( 'give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11 );
776
			remove_filter( 'give_update_donor_information', 'give_donation_import_update_donor_information', 11 );
777
			remove_action( 'give_insert_payment', 'give_import_donation_insert_payment', 11 );
778
779
			if ( $payment_id ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $payment_id of type false|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

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

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

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

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
780
781
				$payment = new Give_Payment( $payment_id );
782
783
				$report['create_donation'] = ( ! empty( $report['create_donation'] ) ? ( absint( $report['create_donation'] ) + 1 ) : 1 );
784
785
				$payment->update_meta( '_give_payment_import', true );
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a string.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
786
787
				if ( ! empty( $import_setting['csv'] ) ) {
788
					$payment->update_meta( '_give_payment_import_id', $import_setting['csv'] );
789
				}
790
791
				// Insert Company Name.
792
				if ( ! empty( $data['company_name'] ) ) {
793
					$payment->update_meta( '_give_donation_company', $data['company_name'] );
794
					$donor_data->update_meta( '_give_donor_company', $data['company_name'] );
795
				}
796
797
				// Insert Notes.
798
				if ( ! empty( $data['notes'] ) ) {
799
					$payment->add_note( $data['notes'] );
800
				}
801
802
				$meta_exists = array_keys( $raw_key, 'post_meta' );
803
				if ( ! empty( $main_key ) && ! empty( $meta_exists ) ) {
804
					foreach ( $meta_exists as $meta_exist ) {
805
						if ( ! empty( $main_key[ $meta_exist ] ) && ! empty( $row_data[ $meta_exist ] ) ) {
806
							$payment->update_meta( $main_key[ $meta_exist ], $row_data[ $meta_exist ] );
807
						}
808
					}
809
				}
810
811
				// update the donation status if it's other then pending
812
				if ( 'pending' !== $status ) {
813
					$payment->update_status( $status );
814
				}
0 ignored issues
show
introduced by
Blank line found after control structure
Loading history...
815
816
			} else {
817
				$report['failed_donation'] = ( ! empty( $report['failed_donation'] ) ? ( absint( $report['failed_donation'] ) + 1 ) : 1 );
818
			}
819
820
			/**
821
			 * Fire after payment is imported and payment meta is also being imported.
822
			 *
823
			 * @since 2.1.0
824
			 *
825
			 * @param int $payment payment id
826
			 * @param array $payment_data payment data
827
			 * @param array $payment_data donation data
828
			 * @param array $donor_data donor data
829
			 * @param object $donor_data form object
830
			 */
831
			do_action( 'give_import_after_import_payment', $payment, $payment_data, $data, $donor_data, $form );
832
		} else {
833
			$report['create_donation'] = ( ! empty( $report['create_donation'] ) ? ( absint( $report['create_donation'] ) + 1 ) : 1 );
834
		}
835
	}
836
837
	// update the report
838
	give_import_donation_report_update( $report );
839
840
	return true;
841
}
842
843
/**
844
 * Get Donation form status
845
 *
846
 * @since 2.0.2
847
 *
848
 * @param array $data donation data that is goingt o get imported
849
 *
850
 * @return string $status Donation status.
851
 */
852
function give_import_donation_get_status( $data ) {
853
	if ( empty( $data['post_status'] ) ) {
854
		return 'publish';
855
	}
856
857
	$status = 'publish';
858
859
	$donation_status = trim( $data['post_status'] );
860
	$donation_status_key      = strtolower( preg_replace( '/\s+/', '', $donation_status ) );
861
862
	foreach ( give_get_payment_statuses() as $key => $value ) {
863
		$match = false;
864
		if ( $key === $donation_status_key ) {
865
			$match = true;
866
		} else if ( stristr( $donation_status, $value ) ) {
867
			$match = true;
868
		}
869
870
		if ( ! empty( $match ) ) {
871
			$status = $key;
872
			break;
873
		}
874
	}
875
876
	return $status;
877
}
878
879
/**
880
 * Alter donor information when importing donations from CSV
881
 *
882
 * @since 1.8.13
883
 *
884
 * @param $donor
885
 * @param $payment_id
886
 * @param $payment_data
887
 *
888
 * @return Give_Donor
889
 */
890
function give_donation_import_update_donor_information( $donor, $payment_id, $payment_data ) {
0 ignored issues
show
Unused Code introduced by
The parameter $payment_id is not used and could be removed.

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

Loading history...
891
	$old_donor = $donor;
892
	if ( ! empty( $payment_data['donor_id'] ) ) {
893
		$donor_id = absint( $payment_data['donor_id'] );
894
		$donor    = new Give_Donor( $donor_id );
895
		if ( ! empty( $donor->id ) ) {
896
			return $donor;
897
		}
898
	}
899
900
	return $old_donor;
901
}
902
903
/*
904
 * Give update purchase_count of give customer.
905
 *
906
 * @since 1.8.13
907
 */
908
function give_import_donation_insert_payment( $payment_id, $payment_data ) {
909
	// Update Give Customers purchase_count
910
	if ( ! empty( $payment_data['status'] ) && ( 'complete' === (string) $payment_data['status'] || 'publish' === (string) $payment_data['status'] ) ) {
911
		$donor_id = (int) get_post_meta( $payment_id, '_give_payment_customer_id', true );
912
		if ( ! empty( $donor_id ) ) {
913
			$donor = new Give_Donor( $donor_id );
914
			$donor->increase_purchase_count();
915
		}
916
	}
917
}
918
919
/**
920
 * Add author id in in donation post
921
 *
922
 * @since 1.8.13
923
 */
924
function give_donation_import_give_insert_payment_args( $args, $payment_data ) {
925
	if ( ! empty( $payment_data['user_info']['id'] ) ) {
926
		$args['post_author'] = (int) $payment_data['user_info']['id'];
927
	}
928
929
	return $args;
930
}
931
932
/**
933
 * Check if Import donation is duplicate
934
 *
935
 * @since 1.8.13
936
 */
937
function give_check_import_donation_duplicate( $payment_data, $data, $form, $donor_data ) {
938
	$return = false;
939
	if ( ! empty( $data['post_date'] ) ) {
940
		$post_date = mysql2date( 'Y-m-d-H-i-s', $payment_data['post_date'] );
941
		$post_date = explode( '-', $post_date );
942
		$args      = array(
943
			'output'                 => 'post',
944
			'cache_results'          => false,
945
			'no_found_rows'          => true,
946
			'update_post_meta_cache' => false,
947
			'update_post_term_cache' => false,
948
			'fields'                 => 'ids',
949
			'date_query'             => array(
950
				array(
951
					'year'   => $post_date[0],
952
					'month'  => $post_date[1],
953
					'day'    => $post_date[2],
954
					'hour'   => $post_date[3],
955
					'minute' => $post_date[4],
956
					'second' => $post_date[5],
957
				),
958
			),
959
			'meta_query'             => array(
0 ignored issues
show
introduced by
Detected usage of meta_query, possible slow query.
Loading history...
960
				array(
961
					'key'     => '_give_payment_total',
962
					'value'   => preg_replace( '/[\$,]/', '', $payment_data['price'] ),
963
					'compare' => 'LIKE',
964
				),
965
				array(
966
					'key'     => '_give_payment_form_id',
967
					'value'   => $payment_data['give_form_id'],
968
					'type'    => 'numeric',
969
					'compare' => '=',
970
				),
971
				array(
972
					'key'     => '_give_payment_gateway',
973
					'value'   => $payment_data['gateway'],
974
					'compare' => '=',
975
				),
976
				array(
977
					'key'     => '_give_payment_donor_id',
978
					'value'   => isset( $donor_data->id ) ? $donor_data->id : '',
979
					'compare' => '=',
980
				),
981
			),
982
		);
983
984
		$payments  = new Give_Payments_Query( $args );
985
		$donations = $payments->get_payments();
986
		if ( ! empty( $donations ) ) {
987
			$return = $donations;
988
		}
989
	}
990
991
	/**
992
	 * Filter to modify donation which is getting add is duplicate or not.
993
	 *
994
	 * @since 1.8.18
995
	 */
996
	return apply_filters( 'give_check_import_donation_duplicate', $return, $payment_data, $data, $form, $donor_data );
997
}
998
999
/**
1000
 * Record payment notes that is being imported from CSV.
1001
 *
1002
 * @since  1.8.13
1003
 *
1004
 * @param  int $payment_id The ID number of the payment.
1005
 *
1006
 * @return void
1007
 */
1008
function give_donation_import_insert_default_payment_note( $payment_id ) {
1009
	$current_user = wp_get_current_user();
1010
	give_insert_payment_note( $payment_id, wp_sprintf( __( 'This donation was imported by %s', 'give' ), $current_user->user_email ) );
1011
}
1012
1013
/**
1014
 * Return Import Page URL
1015
 *
1016
 * @since 1.8.13
1017
 *
1018
 * @param array $parameter
1019
 *
1020
 * @return string URL
1021
 */
1022
function give_import_page_url( $parameter = array() ) {
1023
	$defalut_query_arg = array(
1024
		'post_type'     => 'give_forms',
1025
		'page'          => 'give-tools',
1026
		'tab'           => 'import',
1027
		'importer-type' => 'import_donations',
1028
	);
1029
	$import_query_arg  = wp_parse_args( $parameter, $defalut_query_arg );
1030
1031
	return add_query_arg( $import_query_arg, admin_url( 'edit.php' ) );
1032
}