Test Failed
Push — master ( 8c3601...e118e9 )
by Ravinder
03:11
created
includes/import-functions.php 1 patch
Spacing   +344 added lines, -344 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
  */
11 11
 
12 12
 // Exit if accessed directly.
13
-if ( ! defined( 'ABSPATH' ) ) {
13
+if ( ! defined('ABSPATH')) {
14 14
 	exit;
15 15
 }
16 16
 
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  * @since 1.8.13
21 21
  */
22 22
 function give_import_donation_report() {
23
-	return get_option( 'give_import_donation_report', array() );
23
+	return get_option('give_import_donation_report', array());
24 24
 }
25 25
 
26 26
 
@@ -29,8 +29,8 @@  discard block
 block discarded – undo
29 29
  *
30 30
  * @since 1.8.13
31 31
  */
32
-function give_import_donation_report_update( $value = array() ) {
33
-	update_option( 'give_import_donation_report', $value, false );
32
+function give_import_donation_report_update($value = array()) {
33
+	update_option('give_import_donation_report', $value, false);
34 34
 }
35 35
 
36 36
 /**
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
  * @since 1.8.13
40 40
  */
41 41
 function give_import_donation_report_reset() {
42
-	update_option( 'give_import_donation_report', array(), false );
42
+	update_option('give_import_donation_report', array(), false);
43 43
 }
44 44
 
45 45
 /**
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
  *
52 52
  * @return array|bool|Give_Donate_Form|int|null|WP_Post
53 53
  */
54
-function give_import_get_form_data_from_csv( $data, $import_setting = array() ) {
54
+function give_import_get_form_data_from_csv($data, $import_setting = array()) {
55 55
 	$new_form = false;
56
-	$dry_run  = isset( $import_setting['dry_run'] ) ? $import_setting['dry_run'] : false;
56
+	$dry_run  = isset($import_setting['dry_run']) ? $import_setting['dry_run'] : false;
57 57
 
58 58
 	// Get the import report
59 59
 	$report = give_import_donation_report();
@@ -61,25 +61,25 @@  discard block
 block discarded – undo
61 61
 	$form = false;
62 62
 	$meta = array();
63 63
 
64
-	if ( ! empty( $data['form_id'] ) ) {
65
-		$form = new Give_Donate_Form( $data['form_id'] );
64
+	if ( ! empty($data['form_id'])) {
65
+		$form = new Give_Donate_Form($data['form_id']);
66 66
 		// Add support to older php version.
67 67
 		$form_id = $form->get_ID();
68
-		if ( empty( $form_id ) ) {
68
+		if (empty($form_id)) {
69 69
 			$form = false;
70 70
 		} else {
71
-			$report['duplicate_form'] = ( ! empty( $report['duplicate_form'] ) ? ( absint( $report['duplicate_form'] ) + 1 ) : 1 );
71
+			$report['duplicate_form'] = ( ! empty($report['duplicate_form']) ? (absint($report['duplicate_form']) + 1) : 1);
72 72
 		}
73 73
 	}
74 74
 
75
-	if ( false === $form && ! empty( $data['form_title'] ) ) {
76
-		$form = get_page_by_title( $data['form_title'], OBJECT, 'give_forms' );
75
+	if (false === $form && ! empty($data['form_title'])) {
76
+		$form = get_page_by_title($data['form_title'], OBJECT, 'give_forms');
77 77
 
78
-		if ( ! empty( $form->ID ) ) {
78
+		if ( ! empty($form->ID)) {
79 79
 
80
-			$report['duplicate_form'] = ( ! empty( $report['duplicate_form'] ) ? ( absint( $report['duplicate_form'] ) + 1 ) : 1 );
80
+			$report['duplicate_form'] = ( ! empty($report['duplicate_form']) ? (absint($report['duplicate_form']) + 1) : 1);
81 81
 
82
-			$form = new Give_Donate_Form( $form->ID );
82
+			$form = new Give_Donate_Form($form->ID);
83 83
 		} else {
84 84
 			$form = new Give_Donate_Form();
85 85
 			$args = array(
@@ -87,43 +87,43 @@  discard block
 block discarded – undo
87 87
 				'post_status' => 'publish',
88 88
 			);
89 89
 
90
-			if ( empty( $dry_run ) ) {
91
-				$form = $form->create( $args );
90
+			if (empty($dry_run)) {
91
+				$form = $form->create($args);
92 92
 			}
93 93
 
94
-			$report['create_form'] = ( ! empty( $report['create_form'] ) ? ( absint( $report['create_form'] ) + 1 ) : 1 );
94
+			$report['create_form'] = ( ! empty($report['create_form']) ? (absint($report['create_form']) + 1) : 1);
95 95
 			$new_form              = true;
96 96
 
97 97
 		}
98 98
 
99
-		$form = get_page_by_title( $data['form_title'], OBJECT, 'give_forms' );
100
-		if ( ! empty( $form->ID ) ) {
101
-			$form = new Give_Donate_Form( $form->ID );
99
+		$form = get_page_by_title($data['form_title'], OBJECT, 'give_forms');
100
+		if ( ! empty($form->ID)) {
101
+			$form = new Give_Donate_Form($form->ID);
102 102
 		}
103 103
 	}
104 104
 
105
-	if ( ! empty( $form ) && $form->get_ID() && ! empty( $data['form_level'] ) && empty( $dry_run ) ) {
105
+	if ( ! empty($form) && $form->get_ID() && ! empty($data['form_level']) && empty($dry_run)) {
106 106
 
107 107
 		$price_option = 'set';
108
-		$form_level   = strtolower( preg_replace( '/\s+/', '', $data['form_level'] ) );
108
+		$form_level   = strtolower(preg_replace('/\s+/', '', $data['form_level']));
109 109
 
110
-		if ( 'custom' !== $form_level ) {
110
+		if ('custom' !== $form_level) {
111 111
 			$prices     = (array) $form->get_prices();
112 112
 			$price_text = array();
113
-			foreach ( $prices as $key => $price ) {
114
-				if ( isset( $price['_give_id']['level_id'] ) ) {
115
-					$price_text[ $price['_give_id']['level_id'] ] = ( ! empty( $price['_give_text'] ) ? strtolower( preg_replace( '/\s+/', '', $price['_give_text'] ) ) : '' );
113
+			foreach ($prices as $key => $price) {
114
+				if (isset($price['_give_id']['level_id'])) {
115
+					$price_text[$price['_give_id']['level_id']] = ( ! empty($price['_give_text']) ? strtolower(preg_replace('/\s+/', '', $price['_give_text'])) : '');
116 116
 				}
117 117
 			}
118 118
 
119
-			if ( ! in_array( $form_level, $price_text ) ) {
119
+			if ( ! in_array($form_level, $price_text)) {
120 120
 
121 121
 				// For generating unquiet level id.
122 122
 				$count     = 1;
123
-				$new_level = count( $prices ) + $count;
124
-				while ( array_key_exists( $new_level, $price_text ) ) {
125
-					$count ++;
126
-					$new_level = count( $prices ) + $count;
123
+				$new_level = count($prices) + $count;
124
+				while (array_key_exists($new_level, $price_text)) {
125
+					$count++;
126
+					$new_level = count($prices) + $count;
127 127
 				}
128 128
 
129 129
 				$multi_level_donations = array(
@@ -131,42 +131,42 @@  discard block
 block discarded – undo
131 131
 						'_give_id'     => array(
132 132
 							'level_id' => $new_level,
133 133
 						),
134
-						'_give_amount' => give_sanitize_amount_for_db( $data['amount'] ),
134
+						'_give_amount' => give_sanitize_amount_for_db($data['amount']),
135 135
 						'_give_text'   => $data['form_level'],
136 136
 					),
137 137
 				);
138 138
 
139
-				$price_text[ $new_level ] = strtolower( preg_replace( '/\s+/', '', $data['form_level'] ) );
139
+				$price_text[$new_level] = strtolower(preg_replace('/\s+/', '', $data['form_level']));
140 140
 
141
-				if ( ! empty( $prices ) && is_array( $prices ) && ! empty( $prices[0] ) ) {
142
-					$prices = wp_parse_args( $multi_level_donations, $prices );
141
+				if ( ! empty($prices) && is_array($prices) && ! empty($prices[0])) {
142
+					$prices = wp_parse_args($multi_level_donations, $prices);
143 143
 
144 144
 					// Sort $prices by amount in ascending order.
145
-					$prices = wp_list_sort( $prices, '_give_amount', 'ASC' );
145
+					$prices = wp_list_sort($prices, '_give_amount', 'ASC');
146 146
 				} else {
147 147
 					$prices = $multi_level_donations;
148 148
 				}
149 149
 
150 150
 				// Unset _give_default key from $prices.
151
-				foreach ( $prices as $key => $price ) {
152
-					if ( isset( $prices[ $key ]['_give_default'] ) ) {
153
-						unset( $prices[ $key ]['_give_default'] );
151
+				foreach ($prices as $key => $price) {
152
+					if (isset($prices[$key]['_give_default'])) {
153
+						unset($prices[$key]['_give_default']);
154 154
 					}
155 155
 				}
156 156
 
157 157
 				// Set the first $price of the $prices as default.
158 158
 				$prices[0]['_give_default'] = 'default';
159 159
 			}
160
-			$form->price_id = array_search( $form_level, $price_text );
160
+			$form->price_id = array_search($form_level, $price_text);
161 161
 
162
-			$donation_levels_amounts = wp_list_pluck( $prices, '_give_amount' );
163
-			$min_amount              = min( $donation_levels_amounts );
164
-			$max_amount              = max( $donation_levels_amounts );
162
+			$donation_levels_amounts = wp_list_pluck($prices, '_give_amount');
163
+			$min_amount              = min($donation_levels_amounts);
164
+			$max_amount              = max($donation_levels_amounts);
165 165
 
166 166
 			$meta = array(
167 167
 				'_give_levels_minimum_amount' => $min_amount,
168 168
 				'_give_levels_maximum_amount' => $max_amount,
169
-				'_give_donation_levels'       => array_values( $prices ),
169
+				'_give_donation_levels'       => array_values($prices),
170 170
 			);
171 171
 
172 172
 			$price_option = 'multi';
@@ -175,13 +175,13 @@  discard block
 block discarded – undo
175 175
 		}
176 176
 
177 177
 		$defaults = array(
178
-			'_give_set_price' => give_sanitize_amount_for_db( $data['amount'] ),
178
+			'_give_set_price' => give_sanitize_amount_for_db($data['amount']),
179 179
 		);
180 180
 
181 181
 		// If new form is created.
182
-		if ( ! empty( $new_form ) ) {
182
+		if ( ! empty($new_form)) {
183 183
 			$new_form = array(
184
-				'_give_custom_amount_text'          => ( ! empty( $data['form_custom_amount_text'] ) ? $data['form_custom_amount_text'] : 'custom' ),
184
+				'_give_custom_amount_text'          => ( ! empty($data['form_custom_amount_text']) ? $data['form_custom_amount_text'] : 'custom'),
185 185
 				'_give_logged_in_only'              => 'enabled',
186 186
 				'_give_custom_amount'               => 'enabled',
187 187
 				'_give_payment_import'              => true,
@@ -194,18 +194,18 @@  discard block
 block discarded – undo
194 194
 				'_give_show_register_form'          => 'both',
195 195
 				'_give_price_option'                => $price_option,
196 196
 			);
197
-			$defaults = wp_parse_args( $defaults, $new_form );
197
+			$defaults = wp_parse_args($defaults, $new_form);
198 198
 		}
199 199
 
200
-		$meta = wp_parse_args( $meta, $defaults );
200
+		$meta = wp_parse_args($meta, $defaults);
201 201
 
202
-		foreach ( $meta as $key => $value ) {
203
-			give_update_meta( $form->get_ID(), $key, $value );
202
+		foreach ($meta as $key => $value) {
203
+			give_update_meta($form->get_ID(), $key, $value);
204 204
 		}
205 205
 	}
206 206
 
207 207
 	// update the report
208
-	give_import_donation_report_update( $report );
208
+	give_import_donation_report_update($report);
209 209
 
210 210
 	return $form;
211 211
 }
@@ -219,36 +219,36 @@  discard block
 block discarded – undo
219 219
  *
220 220
  * @return bool|false|WP_User
221 221
  */
222
-function give_import_get_user_from_csv( $data, $import_setting = array() ) {
222
+function give_import_get_user_from_csv($data, $import_setting = array()) {
223 223
 	$report               = give_import_donation_report();
224
-	$dry_run              = isset( $import_setting['dry_run'] ) ? $import_setting['dry_run'] : false;
224
+	$dry_run              = isset($import_setting['dry_run']) ? $import_setting['dry_run'] : false;
225 225
 	$dry_run_donor_create = false;
226 226
 	$donor_data           = array();
227 227
 	$donor_id             = false;
228 228
 
229 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
-		if ( ! empty( $donor_data->id ) ) {
233
-			$report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 );
230
+	if ( ! empty($data['donor_id'])) {
231
+		$donor_data = new Give_Donor((int) $data['donor_id']);
232
+		if ( ! empty($donor_data->id)) {
233
+			$report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1);
234 234
 		}
235 235
 	}
236 236
 
237
-	if ( empty( $donor_data->id ) && ! empty( $data['user_id'] ) ) {
237
+	if (empty($donor_data->id) && ! empty($data['user_id'])) {
238 238
 		$user_id    = (int) $data['user_id'];
239
-		$donor_data = new Give_Donor( $user_id, true );
239
+		$donor_data = new Give_Donor($user_id, true);
240 240
 
241 241
 
242
-		if ( empty( $donor_data->id ) ) {
243
-			$donor_data = get_user_by( 'id', $user_id );
242
+		if (empty($donor_data->id)) {
243
+			$donor_data = get_user_by('id', $user_id);
244 244
 
245 245
 			// if no wp user is found then no donor is create with that user id
246
-			if ( ! empty( $donor_data->ID ) ) {
246
+			if ( ! empty($donor_data->ID)) {
247 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 : '' ) );
251
-					$name       = $first_name . ' ' . $last_name;
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 : ''));
251
+					$name       = $first_name.' '.$last_name;
252 252
 					$user_email = $donor_data->user_email;
253 253
 					$donor_args = array(
254 254
 						'name'    => $name,
@@ -257,51 +257,51 @@  discard block
 block discarded – undo
257 257
 					);
258 258
 
259 259
 					$donor_data = new Give_Donor();
260
-					$donor_data->create( $donor_args );
260
+					$donor_data->create($donor_args);
261 261
 
262 262
 					// Adding notes that donor is being imported from CSV.
263 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 ) );
264
+					$donor_data->add_note(wp_sprintf(__('This donor was imported by %s', 'give'), $current_user->user_email));
265 265
 
266 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'] );
267
+					if ($user_email != $data['email'] && ! empty($data['email'])) {
268
+						$donor_data->add_meta('additional_email', $data['email']);
269 269
 					}
270 270
 				} else {
271 271
 					$dry_run_donor_create = true;
272
-					$donor_data           = array( 'id' => 1 );
272
+					$donor_data           = array('id' => 1);
273 273
 				}
274 274
 
275
-				$report['create_donor'] = ( ! empty( $report['create_donor'] ) ? ( absint( $report['create_donor'] ) + 1 ) : 1 );
276
-			} elseif ( $dry_run ) {
275
+				$report['create_donor'] = ( ! empty($report['create_donor']) ? (absint($report['create_donor']) + 1) : 1);
276
+			} elseif ($dry_run) {
277 277
 				$donor_data = array();
278 278
 			}
279 279
 		} else {
280 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 ) );
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 283
 			}
284
-			$report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 );
284
+			$report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1);
285 285
 		}
286 286
 	}
287 287
 
288
-	if ( empty( $donor_data->id ) && ! empty( $data['email'] ) && empty( $dry_run_donor_create ) ) {
288
+	if (empty($donor_data->id) && ! empty($data['email']) && empty($dry_run_donor_create)) {
289 289
 
290
-		$donor_data = new Give_Donor( $data['email'] );
291
-		if ( empty( $donor_data->id ) ) {
292
-			$donor_data = get_user_by( 'email', $data['email'] );
290
+		$donor_data = new Give_Donor($data['email']);
291
+		if (empty($donor_data->id)) {
292
+			$donor_data = get_user_by('email', $data['email']);
293 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' ) ) );
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 298
 				$donor_args         = array(
299 299
 					'user_login'      => $data['email'],
300 300
 					'user_email'      => $data['email'],
301
-					'user_registered' => date( 'Y-m-d H:i:s' ),
301
+					'user_registered' => date('Y-m-d H:i:s'),
302 302
 					'user_first'      => $data['first_name'],
303 303
 					'user_last'       => $data['last_name'],
304
-					'user_pass'       => wp_generate_password( 8, true ),
304
+					'user_pass'       => wp_generate_password(8, true),
305 305
 					'role'            => $give_role,
306 306
 				);
307 307
 
@@ -310,64 +310,64 @@  discard block
 block discarded – undo
310 310
 				 *
311 311
 				 * @since 1.8.13
312 312
 				 */
313
-				$donor_args = (array) apply_filters( 'give_import_insert_user_args', $donor_args, $data, $import_setting );
313
+				$donor_args = (array) apply_filters('give_import_insert_user_args', $donor_args, $data, $import_setting);
314 314
 
315
-				if ( empty( $dry_run ) ) {
315
+				if (empty($dry_run)) {
316 316
 
317 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 );
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 321
 
322
-					$donor_data = new Give_Donor( $donor_id, true );
323
-					$donor_data->update_meta( '_give_payment_import', true );
322
+					$donor_data = new Give_Donor($donor_id, true);
323
+					$donor_data->update_meta('_give_payment_import', true);
324 324
 
325 325
 				} else {
326 326
 					$dry_run_donor_create   = true;
327
-					$report['create_donor'] = ( ! empty( $report['create_donor'] ) ? ( absint( $report['create_donor'] ) + 1 ) : 1 );
327
+					$report['create_donor'] = ( ! empty($report['create_donor']) ? (absint($report['create_donor']) + 1) : 1);
328 328
 				}
329 329
 			} else {
330
-				$donor_id = ( ! empty( $donor_data->ID ) ? $donor_data->ID : false );
330
+				$donor_id = ( ! empty($donor_data->ID) ? $donor_data->ID : false);
331 331
 			}
332 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 );
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 335
 
336
-				if ( empty( $donor_data->id ) ) {
336
+				if (empty($donor_data->id)) {
337 337
 
338
-					if ( ! empty( $data['form_id'] ) ) {
339
-						$form = new Give_Donate_Form( $data['form_id'] );
338
+					if ( ! empty($data['form_id'])) {
339
+						$form = new Give_Donate_Form($data['form_id']);
340 340
 					}
341 341
 
342
-					if ( empty( $dry_run ) ) {
343
-						$payment_title = ( isset( $data['form_title'] ) ? $data['form_title'] : ( isset( $form ) ? $form->get_name() : __( 'New Form', 'give' ) ) );
342
+					if (empty($dry_run)) {
343
+						$payment_title = (isset($data['form_title']) ? $data['form_title'] : (isset($form) ? $form->get_name() : __('New Form', 'give')));
344 344
 						$donor_args    = array(
345
-							'name'  => ! is_email( $payment_title ) ? $data['first_name'] . ' ' . $data['last_name'] : '',
345
+							'name'  => ! is_email($payment_title) ? $data['first_name'].' '.$data['last_name'] : '',
346 346
 							'email' => $data['email'],
347 347
 						);
348
-						if ( ! empty( $donor_id ) ) {
348
+						if ( ! empty($donor_id)) {
349 349
 							$donor_args['user_id'] = $donor_id;
350 350
 						}
351
-						$donor_data->create( $donor_args );
351
+						$donor_data->create($donor_args);
352 352
 
353 353
 						// Adding notes that donor is being imported from CSV.
354 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 ) );
355
+						$donor_data->add_note(wp_sprintf(__('This donor was imported by %s', 'give'), $current_user->user_email));
356 356
 					} else {
357 357
 						$dry_run_donor_create = true;
358 358
 					}
359
-					$report['create_donor'] = ( ! empty( $report['create_donor'] ) ? ( absint( $report['create_donor'] ) + 1 ) : 1 );
359
+					$report['create_donor'] = ( ! empty($report['create_donor']) ? (absint($report['create_donor']) + 1) : 1);
360 360
 				} else {
361
-					$report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 );
361
+					$report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1);
362 362
 				}
363 363
 			}
364 364
 		} else {
365
-			$report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 );
365
+			$report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1);
366 366
 		}
367 367
 	}
368 368
 
369 369
 	// update the report
370
-	give_import_donation_report_update( $report );
370
+	give_import_donation_report_update($report);
371 371
 
372 372
 	return $donor_data;
373 373
 }
@@ -385,9 +385,9 @@  discard block
 block discarded – undo
385 385
 	 *
386 386
 	 * @return array
387 387
 	 */
388
-	return (array) apply_filters( 'give_import_default_options', array(
389
-		'' => __( 'Do not import', 'give' ),
390
-	) );
388
+	return (array) apply_filters('give_import_default_options', array(
389
+		'' => __('Do not import', 'give'),
390
+	));
391 391
 }
392 392
 
393 393
 /**
@@ -403,93 +403,93 @@  discard block
 block discarded – undo
403 403
 	 *
404 404
 	 * @return array
405 405
 	 */
406
-	return (array) apply_filters( 'give_import_donations_options', array(
407
-		'id'           => __( 'Donation ID', 'give' ),
406
+	return (array) apply_filters('give_import_donations_options', array(
407
+		'id'           => __('Donation ID', 'give'),
408 408
 		'amount'       => array(
409
-			__( 'Donation Amount', 'give' ),
410
-			__( 'Amount', 'give' ),
411
-			__( 'Donation Total', 'give' ),
412
-			__( 'Total', 'give' ),
409
+			__('Donation Amount', 'give'),
410
+			__('Amount', 'give'),
411
+			__('Donation Total', 'give'),
412
+			__('Total', 'give'),
413 413
 		),
414 414
 		'currency'     => array(
415
-			__( 'Donation Currencies', 'give' ),
416
-			__( 'Currencies', 'give' ),
417
-			__( 'Currencies Code', 'give' ),
418
-			__( 'Currency Code', 'give' ),
419
-			__( 'Code', 'give' ),
415
+			__('Donation Currencies', 'give'),
416
+			__('Currencies', 'give'),
417
+			__('Currencies Code', 'give'),
418
+			__('Currency Code', 'give'),
419
+			__('Code', 'give'),
420 420
 		),
421 421
 		'post_date'    => array(
422
-			__( 'Donation Date', 'give' ),
423
-			__( 'Date', 'give' ),
422
+			__('Donation Date', 'give'),
423
+			__('Date', 'give'),
424 424
 		),
425 425
 		'post_time'    => array(
426
-			__( 'Donation Time', 'give' ),
427
-			__( 'Time', 'give' ),
426
+			__('Donation Time', 'give'),
427
+			__('Time', 'give'),
428 428
 		),
429 429
 		'title_prefix' => array(
430
-			__( 'Title Prefix', 'give' ),
431
-			__( 'Prefix', 'give' ),
430
+			__('Title Prefix', 'give'),
431
+			__('Prefix', 'give'),
432 432
 		),
433 433
 		'first_name'   => array(
434
-			__( 'Donor First Name', 'give' ),
435
-			__( 'First Name', 'give' ),
436
-			__( 'Name', 'give' ),
437
-			__( 'First', 'give' ),
434
+			__('Donor First Name', 'give'),
435
+			__('First Name', 'give'),
436
+			__('Name', 'give'),
437
+			__('First', 'give'),
438 438
 		),
439 439
 		'last_name'    => array(
440
-			__( 'Donor Last Name', 'give' ),
441
-			__( 'Last Name', 'give' ),
442
-			__( 'Last', 'give' ),
440
+			__('Donor Last Name', 'give'),
441
+			__('Last Name', 'give'),
442
+			__('Last', 'give'),
443 443
 		),
444 444
 		'company_name' => array(
445
-			__( 'Company Name', 'give' ),
446
-			__( 'Donor Company Name', 'give' ),
447
-			__( 'Donor Company', 'give' ),
448
-			__( 'Company', 'give' ),
445
+			__('Company Name', 'give'),
446
+			__('Donor Company Name', 'give'),
447
+			__('Donor Company', 'give'),
448
+			__('Company', 'give'),
449 449
 		),
450 450
 		'line1'        => array(
451
-			__( 'Address 1', 'give' ),
452
-			__( 'Address', 'give' ),
451
+			__('Address 1', 'give'),
452
+			__('Address', 'give'),
453 453
 		),
454
-		'line2'        => __( 'Address 2', 'give' ),
455
-		'city'         => __( 'City', 'give' ),
454
+		'line2'        => __('Address 2', 'give'),
455
+		'city'         => __('City', 'give'),
456 456
 		'state'        => array(
457
-			__( 'State', 'give' ),
458
-			__( 'Province', 'give' ),
459
-			__( 'County', 'give' ),
460
-			__( 'Region', 'give' ),
457
+			__('State', 'give'),
458
+			__('Province', 'give'),
459
+			__('County', 'give'),
460
+			__('Region', 'give'),
461 461
 		),
462
-		'country'      => __( 'Country', 'give' ),
462
+		'country'      => __('Country', 'give'),
463 463
 		'zip'          => array(
464
-			__( 'Zip Code', 'give' ),
465
-			__( 'Zip', 'give' ),
466
-			__( 'zipcode', 'give' ),
467
-			__( 'Postal Code', 'give' ),
468
-			__( 'Postal', 'give' ),
464
+			__('Zip Code', 'give'),
465
+			__('Zip', 'give'),
466
+			__('zipcode', 'give'),
467
+			__('Postal Code', 'give'),
468
+			__('Postal', 'give'),
469 469
 		),
470 470
 		'email'        => array(
471
-			__( 'Donor Email', 'give' ),
472
-			__( 'Email', 'give' ),
473
-			__( 'Email Address', 'give' ),
471
+			__('Donor Email', 'give'),
472
+			__('Email', 'give'),
473
+			__('Email Address', 'give'),
474 474
 		),
475 475
 		'post_status'  => array(
476
-			__( 'Donation Status', 'give' ),
477
-			__( 'Status', 'give' ),
476
+			__('Donation Status', 'give'),
477
+			__('Status', 'give'),
478 478
 		),
479 479
 		'gateway'      => array(
480
-			__( 'Payment Method', 'give' ),
481
-			__( 'Method', 'give' ),
482
-			__( 'Payment Gateway', 'give' ),
483
-			__( 'Gateway', 'give' ),
480
+			__('Payment Method', 'give'),
481
+			__('Method', 'give'),
482
+			__('Payment Gateway', 'give'),
483
+			__('Gateway', 'give'),
484 484
 		),
485
-		'notes'        => __( 'Notes', 'give' ),
485
+		'notes'        => __('Notes', 'give'),
486 486
 		'mode'         => array(
487
-			__( 'Payment Mode', 'give' ),
488
-			__( 'Mode', 'give' ),
489
-			__( 'Test Mode', 'give' ),
487
+			__('Payment Mode', 'give'),
488
+			__('Mode', 'give'),
489
+			__('Test Mode', 'give'),
490 490
 		),
491
-		'post_meta'    => __( 'Import as Meta', 'give' ),
492
-	) );
491
+		'post_meta'    => __('Import as Meta', 'give'),
492
+	));
493 493
 }
494 494
 
495 495
 /**
@@ -505,10 +505,10 @@  discard block
 block discarded – undo
505 505
 	 *
506 506
 	 * @return array
507 507
 	 */
508
-	return (array) apply_filters( 'give_import_donor_options', array(
509
-		'donor_id' => __( 'Donor ID', 'give' ),
510
-		'user_id'  => __( 'User ID', 'give' ),
511
-	) );
508
+	return (array) apply_filters('give_import_donor_options', array(
509
+		'donor_id' => __('Donor ID', 'give'),
510
+		'user_id'  => __('User ID', 'give'),
511
+	));
512 512
 }
513 513
 
514 514
 /**
@@ -524,29 +524,29 @@  discard block
 block discarded – undo
524 524
 	 *
525 525
 	 * @return array
526 526
 	 */
527
-	return (array) apply_filters( 'give_import_donation_form_options', array(
527
+	return (array) apply_filters('give_import_donation_form_options', array(
528 528
 		'form_title'              => array(
529
-			__( 'Donation Form Title', 'give' ),
530
-			__( 'Donation Form', 'give' ),
531
-			__( 'Form Name', 'give' ),
532
-			__( 'Title', 'give' ),
533
-			__( 'Form Title', 'give' ),
529
+			__('Donation Form Title', 'give'),
530
+			__('Donation Form', 'give'),
531
+			__('Form Name', 'give'),
532
+			__('Title', 'give'),
533
+			__('Form Title', 'give'),
534 534
 			'ignore' => array(
535
-				__( 'Title Prefix', 'give' ),
536
-				__( 'Prefix', 'give' ),
535
+				__('Title Prefix', 'give'),
536
+				__('Prefix', 'give'),
537 537
 			),
538 538
 		),
539 539
 		'form_id'                 => array(
540
-			__( 'Donation Form ID', 'give' ),
541
-			__( 'Form ID', 'give' ),
540
+			__('Donation Form ID', 'give'),
541
+			__('Form ID', 'give'),
542 542
 		),
543 543
 		'form_level'              => array(
544
-			__( 'Donation Level', 'give' ),
545
-			__( 'Level', 'give' ),
546
-			__( 'Level Title', 'give' ),
544
+			__('Donation Level', 'give'),
545
+			__('Level', 'give'),
546
+			__('Level Title', 'give'),
547 547
 		),
548
-		'form_custom_amount_text' => __( 'Custom Amount Text', 'give' ),
549
-	) );
548
+		'form_custom_amount_text' => __('Custom Amount Text', 'give'),
549
+	));
550 550
 }
551 551
 
552 552
 /**
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
  *
560 560
  * @return array
561 561
  */
562
-function give_get_donation_data_from_csv( $file_id, $start, $end, $delimiter = 'csv' ) {
562
+function give_get_donation_data_from_csv($file_id, $start, $end, $delimiter = 'csv') {
563 563
 	/**
564 564
 	 * Filter to modify delimiter of Import
565 565
 	 *
@@ -569,11 +569,11 @@  discard block
 block discarded – undo
569 569
 	 *
570 570
 	 * @return string $delimiter
571 571
 	 */
572
-	$delimiter = (string) apply_filters( 'give_import_delimiter_set', $delimiter );
572
+	$delimiter = (string) apply_filters('give_import_delimiter_set', $delimiter);
573 573
 
574
-	$file_dir = give_get_file_data_by_file_id( $file_id );
574
+	$file_dir = give_get_file_data_by_file_id($file_id);
575 575
 
576
-	return give_get_raw_data_from_file( $file_dir, $start, $end, $delimiter );
576
+	return give_get_raw_data_from_file($file_dir, $start, $end, $delimiter);
577 577
 }
578 578
 
579 579
 /**
@@ -588,18 +588,18 @@  discard block
 block discarded – undo
588 588
  *
589 589
  * @return array
590 590
  */
591
-function give_get_raw_data_from_file( $file_dir, $start, $end, $delimiter ) {
591
+function give_get_raw_data_from_file($file_dir, $start, $end, $delimiter) {
592 592
 	$raw_data = array();
593 593
 
594 594
 	$count    = 0;
595
-	if ( false !== ( $handle = fopen( $file_dir, 'r' ) ) ) {
596
-		while ( false !== ( $row = fgetcsv( $handle, 0, $delimiter ) ) ) {
597
-			if ( $count >= $start && $count <= $end ) {
595
+	if (false !== ($handle = fopen($file_dir, 'r'))) {
596
+		while (false !== ($row = fgetcsv($handle, 0, $delimiter))) {
597
+			if ($count >= $start && $count <= $end) {
598 598
 				$raw_data[] = $row;
599 599
 			}
600
-			$count ++;
600
+			$count++;
601 601
 		}
602
-		fclose( $handle );
602
+		fclose($handle);
603 603
 	}
604 604
 
605 605
 	return $raw_data;
@@ -614,8 +614,8 @@  discard block
 block discarded – undo
614 614
  *
615 615
  * @return false|string file content
616 616
  */
617
-function give_get_file_data_by_file_id( $file_id ) {
618
-	return get_attached_file( $file_id );
617
+function give_get_file_data_by_file_id($file_id) {
618
+	return get_attached_file($file_id);
619 619
 }
620 620
 
621 621
 
@@ -628,7 +628,7 @@  discard block
 block discarded – undo
628 628
  *
629 629
  * @return bool
630 630
  */
631
-function give_log_user_in_on_register_callback( $value ) {
631
+function give_log_user_in_on_register_callback($value) {
632 632
 	return false;
633 633
 }
634 634
 
@@ -644,87 +644,87 @@  discard block
 block discarded – undo
644 644
  *
645 645
  * @return bool
646 646
  */
647
-function give_save_import_donation_to_db( $raw_key, $row_data, $main_key = array(), $import_setting = array() ) {
648
-	$data                          = array_combine( $raw_key, $row_data );
647
+function give_save_import_donation_to_db($raw_key, $row_data, $main_key = array(), $import_setting = array()) {
648
+	$data                          = array_combine($raw_key, $row_data);
649 649
 	$price_id                      = false;
650 650
 	$donor_id                      = 0;
651 651
 	$donor_data                    = array();
652 652
 	$form                          = array();
653
-	$import_setting['create_user'] = isset( $import_setting['create_user'] ) ? $import_setting['create_user'] : 1;
654
-	$dry_run                       = isset( $import_setting['dry_run'] ) ? $import_setting['dry_run'] : false;
653
+	$import_setting['create_user'] = isset($import_setting['create_user']) ? $import_setting['create_user'] : 1;
654
+	$dry_run                       = isset($import_setting['dry_run']) ? $import_setting['dry_run'] : false;
655 655
 	$_dry_run_is_duplicate         = false;
656 656
 	$dry_run_duplicate_form        = false;
657 657
 	$dry_run_duplicate_donor       = false;
658
-	$donation_key                  = empty( $import_setting['donation_key'] ) ? 1 : (int) $import_setting['donation_key'];
658
+	$donation_key                  = empty($import_setting['donation_key']) ? 1 : (int) $import_setting['donation_key'];
659 659
 	$payment_id                    = false;
660 660
 
661
-	$data = (array) apply_filters( 'give_save_import_donation_to_db', $data );
661
+	$data = (array) apply_filters('give_save_import_donation_to_db', $data);
662 662
 
663
-	$data['amount'] = give_maybe_sanitize_amount( $data['amount'] );
663
+	$data['amount'] = give_maybe_sanitize_amount($data['amount']);
664 664
 	$diff           = array();
665 665
 
666
-	if ( ! empty( $dry_run ) && 1 !== $donation_key ) {
667
-		$csv_raw_data = empty( $import_setting['csv_raw_data'] ) ? array() : $import_setting['csv_raw_data'];
668
-		$donors_list  = empty( $import_setting['donors_list'] ) ? array() : $import_setting['donors_list'];
666
+	if ( ! empty($dry_run) && 1 !== $donation_key) {
667
+		$csv_raw_data = empty($import_setting['csv_raw_data']) ? array() : $import_setting['csv_raw_data'];
668
+		$donors_list  = empty($import_setting['donors_list']) ? array() : $import_setting['donors_list'];
669 669
 		$key          = $donation_key - 1;
670
-		for ( $i = 0; $i < $key; $i ++ ) {
671
-			$csv_data           = array_combine( $raw_key, $csv_raw_data[ $i ] );
672
-			$csv_data['amount'] = give_maybe_sanitize_amount( $csv_data['amount'] );
670
+		for ($i = 0; $i < $key; $i++) {
671
+			$csv_data           = array_combine($raw_key, $csv_raw_data[$i]);
672
+			$csv_data['amount'] = give_maybe_sanitize_amount($csv_data['amount']);
673 673
 			// check for duplicate donations
674
-			$diff = array_diff( $csv_data, $data );
675
-			if ( empty( $diff ) ) {
674
+			$diff = array_diff($csv_data, $data);
675
+			if (empty($diff)) {
676 676
 				$_dry_run_is_duplicate   = true;
677 677
 				$dry_run_duplicate_form  = true;
678 678
 				$dry_run_duplicate_donor = true;
679 679
 			} else {
680 680
 				// check for duplicate donation form with form id
681
-				if ( ! empty( $csv_data['form_id'] ) && ! empty( $data['form_id'] ) && $csv_data['form_id'] === $data['form_id'] ) {
682
-					$form    = new Give_Donate_Form( $data['form_id'] );
681
+				if ( ! empty($csv_data['form_id']) && ! empty($data['form_id']) && $csv_data['form_id'] === $data['form_id']) {
682
+					$form    = new Give_Donate_Form($data['form_id']);
683 683
 					$form_id = $form->get_ID();
684
-					if ( ! empty( $form_id ) ) {
684
+					if ( ! empty($form_id)) {
685 685
 						$dry_run_duplicate_form = true;
686 686
 					}
687 687
 				}
688 688
 				// check for duplicate donation form with form title
689
-				if ( empty( $dry_run_duplicate_form ) && ! empty( $csv_data['form_title'] ) && ! empty( $data['form_title'] ) && $csv_data['form_title'] === $data['form_title'] ) {
689
+				if (empty($dry_run_duplicate_form) && ! empty($csv_data['form_title']) && ! empty($data['form_title']) && $csv_data['form_title'] === $data['form_title']) {
690 690
 					$dry_run_duplicate_form = true;
691 691
 				}
692 692
 
693 693
 
694 694
 				// check for duplicate donor by donor id
695
-				if ( ! empty( $csv_data['donor_id'] ) && ! empty( $data['donor_id'] ) && $csv_data['donor_id'] === $data['donor_id'] ) {
696
-					$donor = array_search( (int) $data['donor_id'], array_column( 'id', $donors_list ) );
697
-					if ( ! empty( $donor ) ) {
695
+				if ( ! empty($csv_data['donor_id']) && ! empty($data['donor_id']) && $csv_data['donor_id'] === $data['donor_id']) {
696
+					$donor = array_search((int) $data['donor_id'], array_column('id', $donors_list));
697
+					if ( ! empty($donor)) {
698 698
 						$dry_run_duplicate_donor = true;
699 699
 					}
700 700
 				}
701 701
 
702 702
 				// check for duplicate donor by user id
703
-				if ( empty( $dry_run_duplicate_donor ) && ! empty( $csv_data['user_id'] ) && ! empty( $data['user_id'] ) && $csv_data['user_id'] === $data['user_id'] ) {
704
-					$donor = array_search( (int) $data['user_id'], array_column( 'user_id', $donors_list ) );
705
-					if ( ! empty( $donor ) ) {
703
+				if (empty($dry_run_duplicate_donor) && ! empty($csv_data['user_id']) && ! empty($data['user_id']) && $csv_data['user_id'] === $data['user_id']) {
704
+					$donor = array_search((int) $data['user_id'], array_column('user_id', $donors_list));
705
+					if ( ! empty($donor)) {
706 706
 						$dry_run_duplicate_donor = true;
707 707
 					} else {
708
-						$donor = get_user_by( 'id', $csv_data['user_id'] );
709
-						if ( ! empty( $donor->ID ) ) {
708
+						$donor = get_user_by('id', $csv_data['user_id']);
709
+						if ( ! empty($donor->ID)) {
710 710
 							$dry_run_duplicate_donor = true;
711 711
 						}
712 712
 					}
713 713
 				}
714 714
 
715 715
 				// check for duplicate donor by donor id
716
-				if ( empty( $dry_run_duplicate_donor ) && ! empty( $csv_data['email'] ) && ! empty( $data['email'] ) && $csv_data['email'] === $data['email'] ) {
716
+				if (empty($dry_run_duplicate_donor) && ! empty($csv_data['email']) && ! empty($data['email']) && $csv_data['email'] === $data['email']) {
717 717
 					$dry_run_duplicate_donor = true;
718 718
 				}
719 719
 			}
720 720
 		}
721 721
 	}
722 722
 
723
-	if ( empty( $dry_run_duplicate_donor ) ) {
723
+	if (empty($dry_run_duplicate_donor)) {
724 724
 		// Here come the login function.
725
-		$donor_data = give_import_get_user_from_csv( $data, $import_setting );
726
-		if ( empty( $dry_run ) ) {
727
-			if ( ! empty( $donor_data->id ) ) {
725
+		$donor_data = give_import_get_user_from_csv($data, $import_setting);
726
+		if (empty($dry_run)) {
727
+			if ( ! empty($donor_data->id)) {
728 728
 				$donor_id = $donor_data->id;
729 729
 			} else {
730 730
 				return $payment_id;
@@ -733,52 +733,52 @@  discard block
 block discarded – undo
733 733
 	} else {
734 734
 		// Get the report
735 735
 		$report                    = give_import_donation_report();
736
-		$report['duplicate_donor'] = ( ! empty( $report['duplicate_donor'] ) ? ( absint( $report['duplicate_donor'] ) + 1 ) : 1 );
736
+		$report['duplicate_donor'] = ( ! empty($report['duplicate_donor']) ? (absint($report['duplicate_donor']) + 1) : 1);
737 737
 		// update the report
738
-		give_import_donation_report_update( $report );
738
+		give_import_donation_report_update($report);
739 739
 	}
740 740
 
741
-	if ( empty( $dry_run_duplicate_form ) ) {
741
+	if (empty($dry_run_duplicate_form)) {
742 742
 		// get form data or register a form data.
743
-		$form = give_import_get_form_data_from_csv( $data, $import_setting );
744
-		if ( false == $form && empty( $dry_run ) ) {
743
+		$form = give_import_get_form_data_from_csv($data, $import_setting);
744
+		if (false == $form && empty($dry_run)) {
745 745
 			return $payment_id;
746 746
 		} else {
747
-			$price_id = ( ! empty( $form->price_id ) ) ? $form->price_id : false;
747
+			$price_id = ( ! empty($form->price_id)) ? $form->price_id : false;
748 748
 		}
749 749
 	} else {
750 750
 		// Get the report
751 751
 		$report                   = give_import_donation_report();
752
-		$report['duplicate_form'] = ( ! empty( $report['duplicate_form'] ) ? ( absint( $report['duplicate_form'] ) + 1 ) : 1 );
752
+		$report['duplicate_form'] = ( ! empty($report['duplicate_form']) ? (absint($report['duplicate_form']) + 1) : 1);
753 753
 		// update the report
754
-		give_import_donation_report_update( $report );
754
+		give_import_donation_report_update($report);
755 755
 	}
756 756
 
757 757
 	// Get the report
758 758
 	$report = give_import_donation_report();
759 759
 
760 760
 
761
-	$status  = give_import_donation_get_status( $data );
762
-	$country = ( ! empty( $data['country'] ) ? ( ( $country_code = array_search( $data['country'], give_get_country_list() ) ) ? $country_code : $data['country'] ) : '' );
763
-	$state   = ( ! empty( $data['state'] ) ? ( ( $state_code = array_search( $data['state'], give_get_states( $country ) ) ) ? $state_code : $data['state'] ) : '' );
761
+	$status  = give_import_donation_get_status($data);
762
+	$country = ( ! empty($data['country']) ? (($country_code = array_search($data['country'], give_get_country_list())) ? $country_code : $data['country']) : '');
763
+	$state   = ( ! empty($data['state']) ? (($state_code = array_search($data['state'], give_get_states($country))) ? $state_code : $data['state']) : '');
764 764
 
765 765
 	$address = array(
766
-		'line1'   => ( ! empty( $data['line1'] ) ? give_clean( $data['line1'] ) : '' ),
767
-		'line2'   => ( ! empty( $data['line2'] ) ? give_clean( $data['line2'] ) : '' ),
768
-		'city'    => ( ! empty( $data['city'] ) ? give_clean( $data['city'] ) : '' ),
769
-		'zip'     => ( ! empty( $data['zip'] ) ? give_clean( $data['zip'] ) : '' ),
766
+		'line1'   => ( ! empty($data['line1']) ? give_clean($data['line1']) : ''),
767
+		'line2'   => ( ! empty($data['line2']) ? give_clean($data['line2']) : ''),
768
+		'city'    => ( ! empty($data['city']) ? give_clean($data['city']) : ''),
769
+		'zip'     => ( ! empty($data['zip']) ? give_clean($data['zip']) : ''),
770 770
 		'state'   => $state,
771 771
 		'country' => $country,
772 772
 	);
773 773
 
774
-	$test_mode = array( 'test', 'true', );
775
-	$post_date = current_time( 'mysql' );
776
-	if ( ! empty( $data['post_date'] ) ) {
777
-		if ( ! empty( $data['post_time'] ) ) {
778
-			$post_date = mysql2date( 'Y-m-d', $data['post_date'] );
779
-			$post_date = mysql2date( 'Y-m-d H:i:s', $post_date . ' ' . $data['post_time'] );
774
+	$test_mode = array('test', 'true',);
775
+	$post_date = current_time('mysql');
776
+	if ( ! empty($data['post_date'])) {
777
+		if ( ! empty($data['post_time'])) {
778
+			$post_date = mysql2date('Y-m-d', $data['post_date']);
779
+			$post_date = mysql2date('Y-m-d H:i:s', $post_date.' '.$data['post_time']);
780 780
 		} else {
781
-			$post_date = mysql2date( 'Y-m-d H:i:s', $data['post_date'] );
781
+			$post_date = mysql2date('Y-m-d H:i:s', $data['post_date']);
782 782
 		}
783 783
 	}
784 784
 
@@ -787,23 +787,23 @@  discard block
 block discarded – undo
787 787
 		'donor_id'        => $donor_id,
788 788
 		'price'           => $data['amount'],
789 789
 		'status'          => $status,
790
-		'currency'        => ! empty( $data['currency'] ) && array_key_exists( $data['currency'], give_get_currencies_list() ) ? $data['currency'] : give_get_currency(),
790
+		'currency'        => ! empty($data['currency']) && array_key_exists($data['currency'], give_get_currencies_list()) ? $data['currency'] : give_get_currency(),
791 791
 		'user_info'       => array(
792 792
 			'id'         => $donor_id,
793
-			'email'      => ( ! empty( $data['email'] ) ? $data['email'] : ( isset( $donor_data->email ) ? $donor_data->email : false ) ),
794
-			'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 ) ),
795
-			'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 ) ),
793
+			'email'      => ( ! empty($data['email']) ? $data['email'] : (isset($donor_data->email) ? $donor_data->email : false)),
794
+			'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)),
795
+			'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)),
796 796
 			'address'    => $address,
797
-			'title'      => ! empty( $data['title_prefix'] ) ? $data['title_prefix'] : '',
797
+			'title'      => ! empty($data['title_prefix']) ? $data['title_prefix'] : '',
798 798
 		),
799
-		'gateway'         => ( ! empty( $data['gateway'] ) ? strtolower( $data['gateway'] ) : 'manual' ),
800
-		'give_form_title' => ( ! empty( $data['form_title'] ) ? $data['form_title'] : ( method_exists( $form, 'get_name' ) ? $form->get_name() : '' ) ),
801
-		'give_form_id'    => method_exists( $form, 'get_ID' ) ? $form->get_ID() : '',
799
+		'gateway'         => ( ! empty($data['gateway']) ? strtolower($data['gateway']) : 'manual'),
800
+		'give_form_title' => ( ! empty($data['form_title']) ? $data['form_title'] : (method_exists($form, 'get_name') ? $form->get_name() : '')),
801
+		'give_form_id'    => method_exists($form, 'get_ID') ? $form->get_ID() : '',
802 802
 		'give_price_id'   => $price_id,
803
-		'purchase_key'    => strtolower( md5( uniqid() ) ),
803
+		'purchase_key'    => strtolower(md5(uniqid())),
804 804
 		'user_email'      => $data['email'],
805 805
 		'post_date'       => $post_date,
806
-		'mode'            => ( ! empty( $data['mode'] ) ? ( in_array( strtolower( $data['mode'] ), $test_mode ) ? 'test' : 'live' ) : ( isset( $import_setting['mode'] ) ? ( true == (bool) $import_setting['mode'] ? 'test' : 'live' ) : ( give_is_test_mode() ? 'test' : 'live' ) ) ),
806
+		'mode'            => ( ! empty($data['mode']) ? (in_array(strtolower($data['mode']), $test_mode) ? 'test' : 'live') : (isset($import_setting['mode']) ? (true == (bool) $import_setting['mode'] ? 'test' : 'live') : (give_is_test_mode() ? 'test' : 'live'))),
807 807
 	);
808 808
 
809 809
 	/**
@@ -818,76 +818,76 @@  discard block
 block discarded – undo
818 818
 	 *
819 819
 	 * @return array $payment_data payment data
820 820
 	 */
821
-	$payment_data = apply_filters( 'give_import_before_import_payment', $payment_data, $data, $donor_data, $form );
821
+	$payment_data = apply_filters('give_import_before_import_payment', $payment_data, $data, $donor_data, $form);
822 822
 
823 823
 	// Get the report
824 824
 	$report = give_import_donation_report();
825 825
 
826 826
 	// Check for duplicate code.
827
-	$donation_duplicate = give_check_import_donation_duplicate( $payment_data, $data, $form, $donor_data );
828
-	if ( false !== $donation_duplicate || ! empty( $_dry_run_is_duplicate ) ) {
829
-		$report['donation_details'][ $import_setting['donation_key'] ]['duplicate'] = $donation_duplicate;
830
-		$report['duplicate_donation']                                               = ( ! empty( $report['duplicate_donation'] ) ? ( absint( $report['duplicate_donation'] ) + 1 ) : 1 );
827
+	$donation_duplicate = give_check_import_donation_duplicate($payment_data, $data, $form, $donor_data);
828
+	if (false !== $donation_duplicate || ! empty($_dry_run_is_duplicate)) {
829
+		$report['donation_details'][$import_setting['donation_key']]['duplicate'] = $donation_duplicate;
830
+		$report['duplicate_donation']                                               = ( ! empty($report['duplicate_donation']) ? (absint($report['duplicate_donation']) + 1) : 1);
831 831
 	} else {
832 832
 
833
-		if ( empty( $dry_run ) ) {
834
-			add_action( 'give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1, 1 );
835
-			add_filter( 'give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11, 2 );
836
-			add_filter( 'give_update_donor_information', 'give_donation_import_update_donor_information', 11, 3 );
837
-			add_action( 'give_insert_payment', 'give_import_donation_insert_payment', 11, 2 );
838
-			add_filter( 'give_is_stop_email_notification', '__return_true' );
833
+		if (empty($dry_run)) {
834
+			add_action('give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1, 1);
835
+			add_filter('give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11, 2);
836
+			add_filter('give_update_donor_information', 'give_donation_import_update_donor_information', 11, 3);
837
+			add_action('give_insert_payment', 'give_import_donation_insert_payment', 11, 2);
838
+			add_filter('give_is_stop_email_notification', '__return_true');
839 839
 
840 840
 			// 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.
841
-			if ( 'pending' !== $status ) {
842
-				unset( $payment_data['status'] );
841
+			if ('pending' !== $status) {
842
+				unset($payment_data['status']);
843 843
 			}
844 844
 
845
-			$payment_id = give_insert_payment( $payment_data );
846
-			remove_action( 'give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1 );
847
-			remove_filter( 'give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11 );
848
-			remove_filter( 'give_update_donor_information', 'give_donation_import_update_donor_information', 11 );
849
-			remove_action( 'give_insert_payment', 'give_import_donation_insert_payment', 11 );
850
-			remove_filter( 'give_is_stop_email_notification', '__return_true' );
845
+			$payment_id = give_insert_payment($payment_data);
846
+			remove_action('give_update_payment_status', 'give_donation_import_insert_default_payment_note', 1);
847
+			remove_filter('give_insert_payment_args', 'give_donation_import_give_insert_payment_args', 11);
848
+			remove_filter('give_update_donor_information', 'give_donation_import_update_donor_information', 11);
849
+			remove_action('give_insert_payment', 'give_import_donation_insert_payment', 11);
850
+			remove_filter('give_is_stop_email_notification', '__return_true');
851 851
 
852
-			if ( $payment_id ) {
852
+			if ($payment_id) {
853 853
 
854
-				$payment = new Give_Payment( $payment_id );
854
+				$payment = new Give_Payment($payment_id);
855 855
 
856
-				$report['create_donation'] = ( ! empty( $report['create_donation'] ) ? ( absint( $report['create_donation'] ) + 1 ) : 1 );
856
+				$report['create_donation'] = ( ! empty($report['create_donation']) ? (absint($report['create_donation']) + 1) : 1);
857 857
 
858
-				$payment->update_meta( '_give_payment_import', true );
858
+				$payment->update_meta('_give_payment_import', true);
859 859
 
860
-				if ( ! empty( $import_setting['csv'] ) ) {
861
-					$payment->update_meta( '_give_payment_import_id', $import_setting['csv'] );
860
+				if ( ! empty($import_setting['csv'])) {
861
+					$payment->update_meta('_give_payment_import_id', $import_setting['csv']);
862 862
 				}
863 863
 
864 864
 				// Insert Company Name.
865
-				if ( ! empty( $data['company_name'] ) ) {
866
-					$payment->update_meta( '_give_donation_company', $data['company_name'] );
867
-					$donor_data->update_meta( '_give_donor_company', $data['company_name'] );
865
+				if ( ! empty($data['company_name'])) {
866
+					$payment->update_meta('_give_donation_company', $data['company_name']);
867
+					$donor_data->update_meta('_give_donor_company', $data['company_name']);
868 868
 				}
869 869
 
870 870
 				// Insert Notes.
871
-				if ( ! empty( $data['notes'] ) ) {
872
-					$payment->add_note( $data['notes'] );
871
+				if ( ! empty($data['notes'])) {
872
+					$payment->add_note($data['notes']);
873 873
 				}
874 874
 
875
-				$meta_exists = array_keys( $raw_key, 'post_meta' );
876
-				if ( ! empty( $main_key ) && ! empty( $meta_exists ) ) {
877
-					foreach ( $meta_exists as $meta_exist ) {
878
-						if ( ! empty( $main_key[ $meta_exist ] ) && ! empty( $row_data[ $meta_exist ] ) ) {
879
-							$payment->update_meta( $main_key[ $meta_exist ], $row_data[ $meta_exist ] );
875
+				$meta_exists = array_keys($raw_key, 'post_meta');
876
+				if ( ! empty($main_key) && ! empty($meta_exists)) {
877
+					foreach ($meta_exists as $meta_exist) {
878
+						if ( ! empty($main_key[$meta_exist]) && ! empty($row_data[$meta_exist])) {
879
+							$payment->update_meta($main_key[$meta_exist], $row_data[$meta_exist]);
880 880
 						}
881 881
 					}
882 882
 				}
883 883
 
884 884
 				// update the donation status if it's other then pending
885
-				if ( 'pending' !== $status ) {
886
-					$payment->update_status( $status );
885
+				if ('pending' !== $status) {
886
+					$payment->update_status($status);
887 887
 				}
888 888
 
889 889
 			} else {
890
-				$report['failed_donation'] = ( ! empty( $report['failed_donation'] ) ? ( absint( $report['failed_donation'] ) + 1 ) : 1 );
890
+				$report['failed_donation'] = ( ! empty($report['failed_donation']) ? (absint($report['failed_donation']) + 1) : 1);
891 891
 				$payment_id                = false;
892 892
 			}
893 893
 
@@ -902,15 +902,15 @@  discard block
 block discarded – undo
902 902
 			 * @param array $donor_data donor data
903 903
 			 * @param object $donor_data form object
904 904
 			 */
905
-			do_action( 'give_import_after_import_payment', $payment, $payment_data, $data, $donor_data, $form );
905
+			do_action('give_import_after_import_payment', $payment, $payment_data, $data, $donor_data, $form);
906 906
 		} else {
907
-			$report['create_donation'] = ( ! empty( $report['create_donation'] ) ? ( absint( $report['create_donation'] ) + 1 ) : 1 );
907
+			$report['create_donation'] = ( ! empty($report['create_donation']) ? (absint($report['create_donation']) + 1) : 1);
908 908
 			$payment_id                = true;
909 909
 		}
910 910
 	}
911 911
 
912 912
 	// update the report
913
-	give_import_donation_report_update( $report );
913
+	give_import_donation_report_update($report);
914 914
 
915 915
 	return $payment_id;
916 916
 }
@@ -924,25 +924,25 @@  discard block
 block discarded – undo
924 924
  *
925 925
  * @return string $status Donation status.
926 926
  */
927
-function give_import_donation_get_status( $data ) {
928
-	if ( empty( $data['post_status'] ) ) {
927
+function give_import_donation_get_status($data) {
928
+	if (empty($data['post_status'])) {
929 929
 		return 'publish';
930 930
 	}
931 931
 
932 932
 	$status = 'publish';
933 933
 
934
-	$donation_status = trim( $data['post_status'] );
935
-	$donation_status_key      = strtolower( preg_replace( '/\s+/', '', $donation_status ) );
934
+	$donation_status = trim($data['post_status']);
935
+	$donation_status_key = strtolower(preg_replace('/\s+/', '', $donation_status));
936 936
 
937
-	foreach ( give_get_payment_statuses() as $key => $value ) {
937
+	foreach (give_get_payment_statuses() as $key => $value) {
938 938
 		$match = false;
939
-		if ( $key === $donation_status_key ) {
939
+		if ($key === $donation_status_key) {
940 940
 			$match = true;
941
-		} else if ( stristr( $donation_status, $value ) ) {
941
+		} else if (stristr($donation_status, $value)) {
942 942
 			$match = true;
943 943
 		}
944 944
 
945
-		if ( ! empty( $match ) ) {
945
+		if ( ! empty($match)) {
946 946
 			$status = $key;
947 947
 			break;
948 948
 		}
@@ -962,12 +962,12 @@  discard block
 block discarded – undo
962 962
  *
963 963
  * @return Give_Donor
964 964
  */
965
-function give_donation_import_update_donor_information( $donor, $payment_id, $payment_data ) {
965
+function give_donation_import_update_donor_information($donor, $payment_id, $payment_data) {
966 966
 	$old_donor = $donor;
967
-	if ( ! empty( $payment_data['donor_id'] ) ) {
968
-		$donor_id = absint( $payment_data['donor_id'] );
969
-		$donor    = new Give_Donor( $donor_id );
970
-		if ( ! empty( $donor->id ) ) {
967
+	if ( ! empty($payment_data['donor_id'])) {
968
+		$donor_id = absint($payment_data['donor_id']);
969
+		$donor    = new Give_Donor($donor_id);
970
+		if ( ! empty($donor->id)) {
971 971
 			return $donor;
972 972
 		}
973 973
 	}
@@ -980,12 +980,12 @@  discard block
 block discarded – undo
980 980
  *
981 981
  * @since 1.8.13
982 982
  */
983
-function give_import_donation_insert_payment( $payment_id, $payment_data ) {
983
+function give_import_donation_insert_payment($payment_id, $payment_data) {
984 984
 	// Update Give Customers purchase_count
985
-	if ( ! empty( $payment_data['status'] ) && ( 'complete' === (string) $payment_data['status'] || 'publish' === (string) $payment_data['status'] ) ) {
986
-		$donor_id = (int) get_post_meta( $payment_id, '_give_payment_customer_id', true );
987
-		if ( ! empty( $donor_id ) ) {
988
-			$donor = new Give_Donor( $donor_id );
985
+	if ( ! empty($payment_data['status']) && ('complete' === (string) $payment_data['status'] || 'publish' === (string) $payment_data['status'])) {
986
+		$donor_id = (int) get_post_meta($payment_id, '_give_payment_customer_id', true);
987
+		if ( ! empty($donor_id)) {
988
+			$donor = new Give_Donor($donor_id);
989 989
 			$donor->increase_purchase_count();
990 990
 		}
991 991
 	}
@@ -996,8 +996,8 @@  discard block
 block discarded – undo
996 996
  *
997 997
  * @since 1.8.13
998 998
  */
999
-function give_donation_import_give_insert_payment_args( $args, $payment_data ) {
1000
-	if ( ! empty( $payment_data['user_info']['id'] ) ) {
999
+function give_donation_import_give_insert_payment_args($args, $payment_data) {
1000
+	if ( ! empty($payment_data['user_info']['id'])) {
1001 1001
 		$args['post_author'] = (int) $payment_data['user_info']['id'];
1002 1002
 	}
1003 1003
 
@@ -1009,11 +1009,11 @@  discard block
 block discarded – undo
1009 1009
  *
1010 1010
  * @since 1.8.13
1011 1011
  */
1012
-function give_check_import_donation_duplicate( $payment_data, $data, $form, $donor_data ) {
1012
+function give_check_import_donation_duplicate($payment_data, $data, $form, $donor_data) {
1013 1013
 	$return = false;
1014
-	if ( ! empty( $data['post_date'] ) ) {
1015
-		$post_date = mysql2date( 'Y-m-d-H-i-s', $payment_data['post_date'] );
1016
-		$post_date = explode( '-', $post_date );
1014
+	if ( ! empty($data['post_date'])) {
1015
+		$post_date = mysql2date('Y-m-d-H-i-s', $payment_data['post_date']);
1016
+		$post_date = explode('-', $post_date);
1017 1017
 		$args      = array(
1018 1018
 			'output'                 => 'post',
1019 1019
 			'cache_results'          => false,
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
 			'meta_query'             => array(
1035 1035
 				array(
1036 1036
 					'key'     => '_give_payment_total',
1037
-					'value'   => preg_replace( '/[\$,]/', '', $payment_data['price'] ),
1037
+					'value'   => preg_replace('/[\$,]/', '', $payment_data['price']),
1038 1038
 					'compare' => 'LIKE',
1039 1039
 				),
1040 1040
 				array(
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
 				),
1051 1051
 				array(
1052 1052
 					'key'     => '_give_payment_donor_id',
1053
-					'value'   => isset( $donor_data->id ) ? $donor_data->id : '',
1053
+					'value'   => isset($donor_data->id) ? $donor_data->id : '',
1054 1054
 					'compare' => '=',
1055 1055
 				),
1056 1056
 				array(
@@ -1061,9 +1061,9 @@  discard block
 block discarded – undo
1061 1061
 			),
1062 1062
 		);
1063 1063
 
1064
-		$payments  = new Give_Payments_Query( $args );
1064
+		$payments  = new Give_Payments_Query($args);
1065 1065
 		$donations = $payments->get_payments();
1066
-		if ( ! empty( $donations ) ) {
1066
+		if ( ! empty($donations)) {
1067 1067
 			$return = $donations;
1068 1068
 		}
1069 1069
 	}
@@ -1073,7 +1073,7 @@  discard block
 block discarded – undo
1073 1073
 	 *
1074 1074
 	 * @since 1.8.18
1075 1075
 	 */
1076
-	return apply_filters( 'give_check_import_donation_duplicate', $return, $payment_data, $data, $form, $donor_data );
1076
+	return apply_filters('give_check_import_donation_duplicate', $return, $payment_data, $data, $form, $donor_data);
1077 1077
 }
1078 1078
 
1079 1079
 /**
@@ -1085,9 +1085,9 @@  discard block
 block discarded – undo
1085 1085
  *
1086 1086
  * @return void
1087 1087
  */
1088
-function give_donation_import_insert_default_payment_note( $payment_id ) {
1088
+function give_donation_import_insert_default_payment_note($payment_id) {
1089 1089
 	$current_user = wp_get_current_user();
1090
-	give_insert_payment_note( $payment_id, wp_sprintf( __( 'This donation was imported by %s', 'give' ), $current_user->user_email ) );
1090
+	give_insert_payment_note($payment_id, wp_sprintf(__('This donation was imported by %s', 'give'), $current_user->user_email));
1091 1091
 }
1092 1092
 
1093 1093
 /**
@@ -1099,14 +1099,14 @@  discard block
 block discarded – undo
1099 1099
  *
1100 1100
  * @return string URL
1101 1101
  */
1102
-function give_import_page_url( $parameter = array() ) {
1102
+function give_import_page_url($parameter = array()) {
1103 1103
 	$defalut_query_arg = array(
1104 1104
 		'post_type'     => 'give_forms',
1105 1105
 		'page'          => 'give-tools',
1106 1106
 		'tab'           => 'import',
1107 1107
 		'importer-type' => 'import_donations',
1108 1108
 	);
1109
-	$import_query_arg  = wp_parse_args( $parameter, $defalut_query_arg );
1109
+	$import_query_arg = wp_parse_args($parameter, $defalut_query_arg);
1110 1110
 
1111
-	return add_query_arg( $import_query_arg, admin_url( 'edit.php' ) );
1111
+	return add_query_arg($import_query_arg, admin_url('edit.php'));
1112 1112
 }
Please login to merge, or discard this patch.