Completed
Push — master ( 0fd17f...ebe8e4 )
by Ravinder
15s
created
includes/admin/donors/donor-actions.php 1 patch
Spacing   +194 added lines, -194 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
 
@@ -23,17 +23,17 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @return array|bool $output Response messages
25 25
  */
26
-function give_edit_donor( $args ) {
26
+function give_edit_donor($args) {
27 27
 
28
-	$donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
28
+	$donor_edit_role = apply_filters('give_edit_donors_role', 'edit_give_payments');
29 29
 
30
-	if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) {
31
-		wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array(
30
+	if ( ! is_admin() || ! current_user_can($donor_edit_role)) {
31
+		wp_die(__('You do not have permission to edit this donor.', 'give'), __('Error', 'give'), array(
32 32
 			'response' => 403,
33
-		) );
33
+		));
34 34
 	}
35 35
 
36
-	if ( empty( $args ) ) {
36
+	if (empty($args)) {
37 37
 		return false;
38 38
 	}
39 39
 
@@ -41,15 +41,15 @@  discard block
 block discarded – undo
41 41
 	$donor_id   = (int) $args['customerinfo']['id'];
42 42
 	$nonce      = $args['_wpnonce'];
43 43
 
44
-	if ( ! wp_verify_nonce( $nonce, 'edit-donor' ) ) {
45
-		wp_die( __( 'Cheatin’ uh?', 'give' ), __( 'Error', 'give' ), array(
44
+	if ( ! wp_verify_nonce($nonce, 'edit-donor')) {
45
+		wp_die(__('Cheatin’ uh?', 'give'), __('Error', 'give'), array(
46 46
 			'response' => 400,
47
-		) );
47
+		));
48 48
 	}
49 49
 
50
-	$donor = new Give_Donor( $donor_id );
50
+	$donor = new Give_Donor($donor_id);
51 51
 
52
-	if ( empty( $donor->id ) ) {
52
+	if (empty($donor->id)) {
53 53
 		return false;
54 54
 	}
55 55
 
@@ -58,70 +58,70 @@  discard block
 block discarded – undo
58 58
 		'user_id' => 0,
59 59
 	);
60 60
 
61
-	$donor_info = wp_parse_args( $donor_info, $defaults );
61
+	$donor_info = wp_parse_args($donor_info, $defaults);
62 62
 
63
-	if ( (int) $donor_info['user_id'] !== (int) $donor->user_id ) {
63
+	if ((int) $donor_info['user_id'] !== (int) $donor->user_id) {
64 64
 
65 65
 		// Make sure we don't already have this user attached to a donor.
66
-		if ( ! empty( $donor_info['user_id'] ) && false !== Give()->donors->get_donor_by( 'user_id', $donor_info['user_id'] ) ) {
67
-			give_set_error( 'give-invalid-donor-user_id', sprintf( __( 'The User ID #%d is already associated with a different donor.', 'give' ), $donor_info['user_id'] ) );
66
+		if ( ! empty($donor_info['user_id']) && false !== Give()->donors->get_donor_by('user_id', $donor_info['user_id'])) {
67
+			give_set_error('give-invalid-donor-user_id', sprintf(__('The User ID #%d is already associated with a different donor.', 'give'), $donor_info['user_id']));
68 68
 		}
69 69
 
70 70
 		// Make sure it's actually a user.
71
-		$user = get_user_by( 'id', $donor_info['user_id'] );
72
-		if ( ! empty( $donor_info['user_id'] ) && false === $user ) {
73
-			give_set_error( 'give-invalid-user_id', sprintf( __( 'The User ID #%d does not exist. Please assign an existing user.', 'give' ), $donor_info['user_id'] ) );
71
+		$user = get_user_by('id', $donor_info['user_id']);
72
+		if ( ! empty($donor_info['user_id']) && false === $user) {
73
+			give_set_error('give-invalid-user_id', sprintf(__('The User ID #%d does not exist. Please assign an existing user.', 'give'), $donor_info['user_id']));
74 74
 		}
75 75
 	}
76 76
 
77 77
 	// Record this for later.
78 78
 	$previous_user_id = $donor->user_id;
79 79
 
80
-	if ( give_get_errors() ) {
80
+	if (give_get_errors()) {
81 81
 		return false;
82 82
 	}
83 83
 
84 84
 	// Setup the donor address, if present.
85 85
 	$address = array();
86
-	if ( intval( $donor_info['user_id'] ) > 0 ) {
86
+	if (intval($donor_info['user_id']) > 0) {
87 87
 
88
-		$current_address = get_user_meta( $donor_info['user_id'], '_give_user_address', true );
88
+		$current_address = get_user_meta($donor_info['user_id'], '_give_user_address', true);
89 89
 
90
-		if ( false === $current_address ) {
91
-			$address['line1']   = isset( $donor_info['line1'] ) ? $donor_info['line1'] : '';
92
-			$address['line2']   = isset( $donor_info['line2'] ) ? $donor_info['line2'] : '';
93
-			$address['city']    = isset( $donor_info['city'] ) ? $donor_info['city'] : '';
94
-			$address['country'] = isset( $donor_info['country'] ) ? $donor_info['country'] : '';
95
-			$address['zip']     = isset( $donor_info['zip'] ) ? $donor_info['zip'] : '';
96
-			$address['state']   = isset( $donor_info['state'] ) ? $donor_info['state'] : '';
90
+		if (false === $current_address) {
91
+			$address['line1']   = isset($donor_info['line1']) ? $donor_info['line1'] : '';
92
+			$address['line2']   = isset($donor_info['line2']) ? $donor_info['line2'] : '';
93
+			$address['city']    = isset($donor_info['city']) ? $donor_info['city'] : '';
94
+			$address['country'] = isset($donor_info['country']) ? $donor_info['country'] : '';
95
+			$address['zip']     = isset($donor_info['zip']) ? $donor_info['zip'] : '';
96
+			$address['state']   = isset($donor_info['state']) ? $donor_info['state'] : '';
97 97
 		} else {
98
-			$current_address    = wp_parse_args( $current_address, array(
98
+			$current_address    = wp_parse_args($current_address, array(
99 99
 				'line1',
100 100
 				'line2',
101 101
 				'city',
102 102
 				'zip',
103 103
 				'state',
104 104
 				'country',
105
-			) );
106
-			$address['line1']   = isset( $donor_info['line1'] ) ? $donor_info['line1'] : $current_address['line1'];
107
-			$address['line2']   = isset( $donor_info['line2'] ) ? $donor_info['line2'] : $current_address['line2'];
108
-			$address['city']    = isset( $donor_info['city'] ) ? $donor_info['city'] : $current_address['city'];
109
-			$address['country'] = isset( $donor_info['country'] ) ? $donor_info['country'] : $current_address['country'];
110
-			$address['zip']     = isset( $donor_info['zip'] ) ? $donor_info['zip'] : $current_address['zip'];
111
-			$address['state']   = isset( $donor_info['state'] ) ? $donor_info['state'] : $current_address['state'];
105
+			));
106
+			$address['line1']   = isset($donor_info['line1']) ? $donor_info['line1'] : $current_address['line1'];
107
+			$address['line2']   = isset($donor_info['line2']) ? $donor_info['line2'] : $current_address['line2'];
108
+			$address['city']    = isset($donor_info['city']) ? $donor_info['city'] : $current_address['city'];
109
+			$address['country'] = isset($donor_info['country']) ? $donor_info['country'] : $current_address['country'];
110
+			$address['zip']     = isset($donor_info['zip']) ? $donor_info['zip'] : $current_address['zip'];
111
+			$address['state']   = isset($donor_info['state']) ? $donor_info['state'] : $current_address['state'];
112 112
 		}
113 113
 	}
114 114
 
115 115
 	// Sanitize the inputs
116 116
 	$donor_data            = array();
117
-	$donor_data['name']    = strip_tags( stripslashes( $donor_info['name'] ) );
117
+	$donor_data['name']    = strip_tags(stripslashes($donor_info['name']));
118 118
 	$donor_data['user_id'] = $donor_info['user_id'];
119 119
 
120
-	$donor_data = apply_filters( 'give_edit_donor_info', $donor_data, $donor_id );
121
-	$address    = apply_filters( 'give_edit_donor_address', $address, $donor_id );
120
+	$donor_data = apply_filters('give_edit_donor_info', $donor_data, $donor_id);
121
+	$address    = apply_filters('give_edit_donor_address', $address, $donor_id);
122 122
 
123
-	$donor_data = array_map( 'sanitize_text_field', $donor_data );
124
-	$address    = array_map( 'sanitize_text_field', $address );
123
+	$donor_data = array_map('sanitize_text_field', $donor_data);
124
+	$address    = array_map('sanitize_text_field', $address);
125 125
 
126 126
 	/**
127 127
 	 * Fires before editing a donor.
@@ -132,27 +132,27 @@  discard block
 block discarded – undo
132 132
 	 * @param array $donor_data The donor data.
133 133
 	 * @param array $address    The donor's address.
134 134
 	 */
135
-	do_action( 'give_pre_edit_donor', $donor_id, $donor_data, $address );
135
+	do_action('give_pre_edit_donor', $donor_id, $donor_data, $address);
136 136
 
137 137
 	$output = array();
138 138
 
139
-	if ( $donor->update( $donor_data ) ) {
139
+	if ($donor->update($donor_data)) {
140 140
 
141
-		if ( ! empty( $donor->user_id ) && $donor->user_id > 0 ) {
142
-			update_user_meta( $donor->user_id, '_give_user_address', $address );
141
+		if ( ! empty($donor->user_id) && $donor->user_id > 0) {
142
+			update_user_meta($donor->user_id, '_give_user_address', $address);
143 143
 		}
144 144
 
145 145
 		// Update some donation meta if we need to.
146
-		$payments_array = explode( ',', $donor->payment_ids );
146
+		$payments_array = explode(',', $donor->payment_ids);
147 147
 
148
-		if ( $donor->user_id != $previous_user_id ) {
149
-			foreach ( $payments_array as $payment_id ) {
150
-				give_update_payment_meta( $payment_id, '_give_payment_user_id', $donor->user_id );
148
+		if ($donor->user_id != $previous_user_id) {
149
+			foreach ($payments_array as $payment_id) {
150
+				give_update_payment_meta($payment_id, '_give_payment_user_id', $donor->user_id);
151 151
 			}
152 152
 		}
153 153
 
154 154
 		$output['success']       = true;
155
-		$donor_data              = array_merge( $donor_data, $address );
155
+		$donor_data              = array_merge($donor_data, $address);
156 156
 		$output['customer_info'] = $donor_data;
157 157
 
158 158
 	} else {
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
 	 * @param int   $donor_id   The ID of the donor.
170 170
 	 * @param array $donor_data The donor data.
171 171
 	 */
172
-	do_action( 'give_post_edit_donor', $donor_id, $donor_data );
172
+	do_action('give_post_edit_donor', $donor_id, $donor_data);
173 173
 
174
-	if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
175
-		header( 'Content-Type: application/json' );
176
-		echo json_encode( $output );
174
+	if (defined('DOING_AJAX') && DOING_AJAX) {
175
+		header('Content-Type: application/json');
176
+		echo json_encode($output);
177 177
 		wp_die();
178 178
 	}
179 179
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 
182 182
 }
183 183
 
184
-add_action( 'give_edit-donor', 'give_edit_donor', 10, 1 );
184
+add_action('give_edit-donor', 'give_edit_donor', 10, 1);
185 185
 
186 186
 /**
187 187
  * Save a donor note.
@@ -192,40 +192,40 @@  discard block
 block discarded – undo
192 192
  *
193 193
  * @return int         The Note ID that was saved, or 0 if nothing was saved.
194 194
  */
195
-function give_donor_save_note( $args ) {
195
+function give_donor_save_note($args) {
196 196
 
197
-	$donor_view_role = apply_filters( 'give_view_donors_role', 'view_give_reports' );
197
+	$donor_view_role = apply_filters('give_view_donors_role', 'view_give_reports');
198 198
 
199
-	if ( ! is_admin() || ! current_user_can( $donor_view_role ) ) {
200
-		wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array(
199
+	if ( ! is_admin() || ! current_user_can($donor_view_role)) {
200
+		wp_die(__('You do not have permission to edit this donor.', 'give'), __('Error', 'give'), array(
201 201
 			'response' => 403,
202
-		) );
202
+		));
203 203
 	}
204 204
 
205
-	if ( empty( $args ) ) {
205
+	if (empty($args)) {
206 206
 		return false;
207 207
 	}
208 208
 
209
-	$donor_note = trim( sanitize_text_field( $args['donor_note'] ) );
209
+	$donor_note = trim(sanitize_text_field($args['donor_note']));
210 210
 	$donor_id   = (int) $args['customer_id'];
211 211
 	$nonce      = $args['add_donor_note_nonce'];
212 212
 
213
-	if ( ! wp_verify_nonce( $nonce, 'add-donor-note' ) ) {
214
-		wp_die( __( 'Cheatin’ uh?', 'give' ), __( 'Error', 'give' ), array(
213
+	if ( ! wp_verify_nonce($nonce, 'add-donor-note')) {
214
+		wp_die(__('Cheatin’ uh?', 'give'), __('Error', 'give'), array(
215 215
 			'response' => 400,
216
-		) );
216
+		));
217 217
 	}
218 218
 
219
-	if ( empty( $donor_note ) ) {
220
-		give_set_error( 'empty-donor-note', __( 'A note is required.', 'give' ) );
219
+	if (empty($donor_note)) {
220
+		give_set_error('empty-donor-note', __('A note is required.', 'give'));
221 221
 	}
222 222
 
223
-	if ( give_get_errors() ) {
223
+	if (give_get_errors()) {
224 224
 		return false;
225 225
 	}
226 226
 
227
-	$donor    = new Give_Donor( $donor_id );
228
-	$new_note = $donor->add_note( $donor_note );
227
+	$donor    = new Give_Donor($donor_id);
228
+	$new_note = $donor->add_note($donor_note);
229 229
 
230 230
 	/**
231 231
 	 * Fires before inserting donor note.
@@ -235,22 +235,22 @@  discard block
 block discarded – undo
235 235
 	 * @param int    $donor_id The ID of the donor.
236 236
 	 * @param string $new_note Note content.
237 237
 	 */
238
-	do_action( 'give_pre_insert_donor_note', $donor_id, $new_note );
238
+	do_action('give_pre_insert_donor_note', $donor_id, $new_note);
239 239
 
240
-	if ( ! empty( $new_note ) && ! empty( $donor->id ) ) {
240
+	if ( ! empty($new_note) && ! empty($donor->id)) {
241 241
 
242 242
 		ob_start();
243 243
 		?>
244 244
 		<div class="donor-note-wrapper dashboard-comment-wrap comment-item">
245 245
 			<span class="note-content-wrap">
246
-				<?php echo stripslashes( $new_note ); ?>
246
+				<?php echo stripslashes($new_note); ?>
247 247
 			</span>
248 248
 		</div>
249 249
 		<?php
250 250
 		$output = ob_get_contents();
251 251
 		ob_end_clean();
252 252
 
253
-		if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
253
+		if (defined('DOING_AJAX') && DOING_AJAX) {
254 254
 			echo $output;
255 255
 			exit;
256 256
 		}
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 
264 264
 }
265 265
 
266
-add_action( 'give_add-donor-note', 'give_donor_save_note', 10, 1 );
266
+add_action('give_add-donor-note', 'give_donor_save_note', 10, 1);
267 267
 
268 268
 /**
269 269
  * Delete a donor.
@@ -274,41 +274,41 @@  discard block
 block discarded – undo
274 274
  *
275 275
  * @return int Whether it was a successful deletion.
276 276
  */
277
-function give_donor_delete( $args ) {
277
+function give_donor_delete($args) {
278 278
 
279
-	$donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
279
+	$donor_edit_role = apply_filters('give_edit_donors_role', 'edit_give_payments');
280 280
 
281
-	if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) {
282
-		wp_die( __( 'You do not have permission to delete donors.', 'give' ), __( 'Error', 'give' ), array(
281
+	if ( ! is_admin() || ! current_user_can($donor_edit_role)) {
282
+		wp_die(__('You do not have permission to delete donors.', 'give'), __('Error', 'give'), array(
283 283
 			'response' => 403,
284
-		) );
284
+		));
285 285
 	}
286 286
 
287
-	if ( empty( $args ) ) {
287
+	if (empty($args)) {
288 288
 		return false;
289 289
 	}
290 290
 
291 291
 	$donor_id    = (int) $args['customer_id'];
292
-	$confirm     = ! empty( $args['give-donor-delete-confirm'] ) ? true : false;
293
-	$remove_data = ! empty( $args['give-donor-delete-records'] ) ? true : false;
292
+	$confirm     = ! empty($args['give-donor-delete-confirm']) ? true : false;
293
+	$remove_data = ! empty($args['give-donor-delete-records']) ? true : false;
294 294
 	$nonce       = $args['_wpnonce'];
295 295
 
296
-	if ( ! wp_verify_nonce( $nonce, 'delete-donor' ) ) {
297
-		wp_die( __( 'Cheatin&#8217; uh?', 'give' ), __( 'Error', 'give' ), array(
296
+	if ( ! wp_verify_nonce($nonce, 'delete-donor')) {
297
+		wp_die(__('Cheatin&#8217; uh?', 'give'), __('Error', 'give'), array(
298 298
 			'response' => 400,
299
-		) );
299
+		));
300 300
 	}
301 301
 
302
-	if ( ! $confirm ) {
303
-		give_set_error( 'donor-delete-no-confirm', __( 'Please confirm you want to delete this donor.', 'give' ) );
302
+	if ( ! $confirm) {
303
+		give_set_error('donor-delete-no-confirm', __('Please confirm you want to delete this donor.', 'give'));
304 304
 	}
305 305
 
306
-	if ( give_get_errors() ) {
307
-		wp_redirect( admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor_id ) );
306
+	if (give_get_errors()) {
307
+		wp_redirect(admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor_id));
308 308
 		exit;
309 309
 	}
310 310
 
311
-	$donor = new Give_Donor( $donor_id );
311
+	$donor = new Give_Donor($donor_id);
312 312
 
313 313
 	/**
314 314
 	 * Fires before deleting donor.
@@ -319,50 +319,50 @@  discard block
 block discarded – undo
319 319
 	 * @param bool $confirm     Delete confirmation.
320 320
 	 * @param bool $remove_data Records delete confirmation.
321 321
 	 */
322
-	do_action( 'give_pre_delete_donor', $donor_id, $confirm, $remove_data );
322
+	do_action('give_pre_delete_donor', $donor_id, $confirm, $remove_data);
323 323
 
324
-	if ( $donor->id > 0 ) {
324
+	if ($donor->id > 0) {
325 325
 
326
-		$payments_array = explode( ',', $donor->payment_ids );
327
-		$success        = Give()->donors->delete( $donor->id );
326
+		$payments_array = explode(',', $donor->payment_ids);
327
+		$success        = Give()->donors->delete($donor->id);
328 328
 
329
-		if ( $success ) {
329
+		if ($success) {
330 330
 
331
-			if ( $remove_data ) {
331
+			if ($remove_data) {
332 332
 
333 333
 				// Remove all donations, logs, etc
334
-				foreach ( $payments_array as $payment_id ) {
335
-					give_delete_donation( $payment_id );
334
+				foreach ($payments_array as $payment_id) {
335
+					give_delete_donation($payment_id);
336 336
 				}
337 337
 			} else {
338 338
 
339 339
 				// Just set the donations to customer_id of 0
340
-				foreach ( $payments_array as $payment_id ) {
341
-					give_update_payment_meta( $payment_id, '_give_payment_customer_id', 0 );
340
+				foreach ($payments_array as $payment_id) {
341
+					give_update_payment_meta($payment_id, '_give_payment_customer_id', 0);
342 342
 				}
343 343
 			}
344 344
 
345
-			$redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&give-message=donor-deleted' );
345
+			$redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&give-message=donor-deleted');
346 346
 
347 347
 		} else {
348 348
 
349
-			give_set_error( 'give-donor-delete-failed', esc_html__( 'Error deleting donor.', 'give' ) );
350
-			$redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=delete&id=' . $donor_id );
349
+			give_set_error('give-donor-delete-failed', esc_html__('Error deleting donor.', 'give'));
350
+			$redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&view=delete&id='.$donor_id);
351 351
 
352 352
 		}
353 353
 	} else {
354 354
 
355
-		give_set_error( 'give-donor-delete-invalid-id', esc_html__( 'Invalid Donor ID.', 'give' ) );
356
-		$redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors' );
355
+		give_set_error('give-donor-delete-invalid-id', esc_html__('Invalid Donor ID.', 'give'));
356
+		$redirect = admin_url('edit.php?post_type=give_forms&page=give-donors');
357 357
 
358 358
 	}
359 359
 
360
-	wp_redirect( $redirect );
360
+	wp_redirect($redirect);
361 361
 	exit;
362 362
 
363 363
 }
364 364
 
365
-add_action( 'give_delete-donor', 'give_donor_delete', 10, 1 );
365
+add_action('give_delete-donor', 'give_donor_delete', 10, 1);
366 366
 
367 367
 /**
368 368
  * Disconnect a user ID from a donor
@@ -373,17 +373,17 @@  discard block
 block discarded – undo
373 373
  *
374 374
  * @return bool|array        If the disconnect was successful.
375 375
  */
376
-function give_disconnect_donor_user_id( $args ) {
376
+function give_disconnect_donor_user_id($args) {
377 377
 
378
-	$donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
378
+	$donor_edit_role = apply_filters('give_edit_donors_role', 'edit_give_payments');
379 379
 
380
-	if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) {
381
-		wp_die( __( 'You do not have permission to edit this donor.', 'give' ), __( 'Error', 'give' ), array(
380
+	if ( ! is_admin() || ! current_user_can($donor_edit_role)) {
381
+		wp_die(__('You do not have permission to edit this donor.', 'give'), __('Error', 'give'), array(
382 382
 			'response' => 403,
383
-		) );
383
+		));
384 384
 	}
385 385
 
386
-	if ( empty( $args ) ) {
386
+	if (empty($args)) {
387 387
 		return false;
388 388
 	}
389 389
 
@@ -391,14 +391,14 @@  discard block
 block discarded – undo
391 391
 
392 392
 	$nonce = $args['_wpnonce'];
393 393
 
394
-	if ( ! wp_verify_nonce( $nonce, 'edit-donor' ) ) {
395
-		wp_die( __( 'Cheatin&#8217; uh?', 'give' ), __( 'Error', 'give' ), array(
394
+	if ( ! wp_verify_nonce($nonce, 'edit-donor')) {
395
+		wp_die(__('Cheatin&#8217; uh?', 'give'), __('Error', 'give'), array(
396 396
 			'response' => 400,
397
-		) );
397
+		));
398 398
 	}
399 399
 
400
-	$donor = new Give_Donor( $donor_id );
401
-	if ( empty( $donor->id ) ) {
400
+	$donor = new Give_Donor($donor_id);
401
+	if (empty($donor->id)) {
402 402
 		return false;
403 403
 	}
404 404
 
@@ -412,18 +412,18 @@  discard block
 block discarded – undo
412 412
 	 * @param int $donor_id The ID of the donor.
413 413
 	 * @param int $user_id  The ID of the user.
414 414
 	 */
415
-	do_action( 'give_pre_donor_disconnect_user_id', $donor_id, $user_id );
415
+	do_action('give_pre_donor_disconnect_user_id', $donor_id, $user_id);
416 416
 
417 417
 	$output     = array();
418 418
 	$donor_args = array(
419 419
 		'user_id' => 0,
420 420
 	);
421 421
 
422
-	if ( $donor->update( $donor_args ) ) {
422
+	if ($donor->update($donor_args)) {
423 423
 		global $wpdb;
424 424
 
425
-		if ( ! empty( $donor->payment_ids ) ) {
426
-			$wpdb->query( "UPDATE $wpdb->postmeta SET meta_value = 0 WHERE meta_key = '_give_payment_user_id' AND post_id IN ( $donor->payment_ids )" );
425
+		if ( ! empty($donor->payment_ids)) {
426
+			$wpdb->query("UPDATE $wpdb->postmeta SET meta_value = 0 WHERE meta_key = '_give_payment_user_id' AND post_id IN ( $donor->payment_ids )");
427 427
 		}
428 428
 
429 429
 		$output['success'] = true;
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
 	} else {
432 432
 
433 433
 		$output['success'] = false;
434
-		give_set_error( 'give-disconnect-user-fail', __( 'Failed to disconnect user from donor.', 'give' ) );
434
+		give_set_error('give-disconnect-user-fail', __('Failed to disconnect user from donor.', 'give'));
435 435
 	}
436 436
 
437 437
 	/**
@@ -441,11 +441,11 @@  discard block
 block discarded – undo
441 441
 	 *
442 442
 	 * @param int $donor_id The ID of the donor.
443 443
 	 */
444
-	do_action( 'give_post_donor_disconnect_user_id', $donor_id );
444
+	do_action('give_post_donor_disconnect_user_id', $donor_id);
445 445
 
446
-	if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
447
-		header( 'Content-Type: application/json' );
448
-		echo json_encode( $output );
446
+	if (defined('DOING_AJAX') && DOING_AJAX) {
447
+		header('Content-Type: application/json');
448
+		echo json_encode($output);
449 449
 		wp_die();
450 450
 	}
451 451
 
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 
454 454
 }
455 455
 
456
-add_action( 'give_disconnect-userid', 'give_disconnect_donor_user_id', 10, 1 );
456
+add_action('give_disconnect-userid', 'give_disconnect_donor_user_id', 10, 1);
457 457
 
458 458
 /**
459 459
  * Add an email address to the donor from within the admin and log a donor note.
@@ -464,84 +464,84 @@  discard block
 block discarded – undo
464 464
  *
465 465
  * @return mixed        If DOING_AJAX echos out JSON, otherwise returns array of success (bool) and message (string).
466 466
  */
467
-function give_add_donor_email( $args ) {
468
-	$donor_edit_role = apply_filters( 'give_edit_donors_role', 'edit_give_payments' );
467
+function give_add_donor_email($args) {
468
+	$donor_edit_role = apply_filters('give_edit_donors_role', 'edit_give_payments');
469 469
 
470
-	if ( ! is_admin() || ! current_user_can( $donor_edit_role ) ) {
471
-		wp_die( esc_html__( 'You do not have permission to edit this donor.', 'give' ), esc_html__( 'Error', 'give' ), array(
470
+	if ( ! is_admin() || ! current_user_can($donor_edit_role)) {
471
+		wp_die(esc_html__('You do not have permission to edit this donor.', 'give'), esc_html__('Error', 'give'), array(
472 472
 			'response' => 403,
473
-		) );
473
+		));
474 474
 	}
475 475
 
476 476
 	$output = array();
477
-	if ( empty( $args ) || empty( $args['email'] ) || empty( $args['customer_id'] ) ) {
477
+	if (empty($args) || empty($args['email']) || empty($args['customer_id'])) {
478 478
 		$output['success'] = false;
479
-		if ( empty( $args['email'] ) ) {
480
-			$output['message'] = __( 'Email address is required.', 'give' );
481
-		} elseif ( empty( $args['customer_id'] ) ) {
482
-			$output['message'] = __( 'Donor ID is required.', 'give' );
479
+		if (empty($args['email'])) {
480
+			$output['message'] = __('Email address is required.', 'give');
481
+		} elseif (empty($args['customer_id'])) {
482
+			$output['message'] = __('Donor ID is required.', 'give');
483 483
 		} else {
484
-			$output['message'] = __( 'An error has occurred. Please try again.', 'give' );
484
+			$output['message'] = __('An error has occurred. Please try again.', 'give');
485 485
 		}
486
-	} elseif ( ! wp_verify_nonce( $args['_wpnonce'], 'give_add_donor_email' ) ) {
486
+	} elseif ( ! wp_verify_nonce($args['_wpnonce'], 'give_add_donor_email')) {
487 487
 		$output = array(
488 488
 			'success' => false,
489
-			'message' => esc_html__( 'Nonce verification failed.', 'give' ),
489
+			'message' => esc_html__('Nonce verification failed.', 'give'),
490 490
 		);
491
-	} elseif ( ! is_email( $args['email'] ) ) {
491
+	} elseif ( ! is_email($args['email'])) {
492 492
 		$output = array(
493 493
 			'success' => false,
494
-			'message' => esc_html__( 'Invalid email.', 'give' ),
494
+			'message' => esc_html__('Invalid email.', 'give'),
495 495
 		);
496 496
 	} else {
497
-		$email    = sanitize_email( $args['email'] );
497
+		$email    = sanitize_email($args['email']);
498 498
 		$donor_id = (int) $args['customer_id'];
499 499
 		$primary  = 'true' === $args['primary'] ? true : false;
500
-		$donor    = new Give_Donor( $donor_id );
501
-		if ( false === $donor->add_email( $email, $primary ) ) {
502
-			if ( in_array( $email, $donor->emails ) ) {
500
+		$donor    = new Give_Donor($donor_id);
501
+		if (false === $donor->add_email($email, $primary)) {
502
+			if (in_array($email, $donor->emails)) {
503 503
 				$output = array(
504 504
 					'success' => false,
505
-					'message' => __( 'Email already associated with this donor.', 'give' ),
505
+					'message' => __('Email already associated with this donor.', 'give'),
506 506
 				);
507 507
 			} else {
508 508
 				$output = array(
509 509
 					'success' => false,
510
-					'message' => __( 'Email address is already associated with another donor.', 'give' ),
510
+					'message' => __('Email address is already associated with another donor.', 'give'),
511 511
 				);
512 512
 			}
513 513
 		} else {
514
-			$redirect = admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor_id . '&give-message=email-added' );
514
+			$redirect = admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor_id.'&give-message=email-added');
515 515
 			$output   = array(
516 516
 				'success'  => true,
517
-				'message'  => __( 'Email successfully added to donor.', 'give' ),
517
+				'message'  => __('Email successfully added to donor.', 'give'),
518 518
 				'redirect' => $redirect,
519 519
 			);
520 520
 
521 521
 			$user       = wp_get_current_user();
522
-			$user_login = ! empty( $user->user_login ) ? $user->user_login : __( 'System', 'give' );
523
-			$donor_note = sprintf( __( 'Email address %1$s added by %2$s', 'give' ), $email, $user_login );
524
-			$donor->add_note( $donor_note );
522
+			$user_login = ! empty($user->user_login) ? $user->user_login : __('System', 'give');
523
+			$donor_note = sprintf(__('Email address %1$s added by %2$s', 'give'), $email, $user_login);
524
+			$donor->add_note($donor_note);
525 525
 
526
-			if ( $primary ) {
527
-				$donor_note = sprintf( __( 'Email address %1$s set as primary by %2$s', 'give' ), $email, $user_login );
528
-				$donor->add_note( $donor_note );
526
+			if ($primary) {
527
+				$donor_note = sprintf(__('Email address %1$s set as primary by %2$s', 'give'), $email, $user_login);
528
+				$donor->add_note($donor_note);
529 529
 			}
530 530
 		}
531 531
 	}// End if().
532 532
 
533
-	do_action( 'give_post_add_donor_email', $donor_id, $args );
533
+	do_action('give_post_add_donor_email', $donor_id, $args);
534 534
 
535
-	if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
536
-		header( 'Content-Type: application/json' );
537
-		echo json_encode( $output );
535
+	if (defined('DOING_AJAX') && DOING_AJAX) {
536
+		header('Content-Type: application/json');
537
+		echo json_encode($output);
538 538
 		wp_die();
539 539
 	}
540 540
 
541 541
 	return $output;
542 542
 }
543 543
 
544
-add_action( 'give_add_donor_email', 'give_add_donor_email', 10, 1 );
544
+add_action('give_add_donor_email', 'give_add_donor_email', 10, 1);
545 545
 
546 546
 
547 547
 /**
@@ -551,39 +551,39 @@  discard block
 block discarded – undo
551 551
  * @return bool|null
552 552
  */
553 553
 function give_remove_donor_email() {
554
-	if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
554
+	if (empty($_GET['id']) || ! is_numeric($_GET['id'])) {
555 555
 		return false;
556 556
 	}
557
-	if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) {
557
+	if (empty($_GET['email']) || ! is_email($_GET['email'])) {
558 558
 		return false;
559 559
 	}
560
-	if ( empty( $_GET['_wpnonce'] ) ) {
560
+	if (empty($_GET['_wpnonce'])) {
561 561
 		return false;
562 562
 	}
563 563
 
564 564
 	$nonce = $_GET['_wpnonce'];
565
-	if ( ! wp_verify_nonce( $nonce, 'give-remove-donor-email' ) ) {
566
-		wp_die( esc_html__( 'Nonce verification failed', 'give' ), esc_html__( 'Error', 'give' ), array(
565
+	if ( ! wp_verify_nonce($nonce, 'give-remove-donor-email')) {
566
+		wp_die(esc_html__('Nonce verification failed', 'give'), esc_html__('Error', 'give'), array(
567 567
 			'response' => 403,
568
-		) );
568
+		));
569 569
 	}
570 570
 
571
-	$donor = new Give_Donor( $_GET['id'] );
572
-	if ( $donor->remove_email( $_GET['email'] ) ) {
573
-		$url        = add_query_arg( 'give-message', 'email-removed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) );
571
+	$donor = new Give_Donor($_GET['id']);
572
+	if ($donor->remove_email($_GET['email'])) {
573
+		$url        = add_query_arg('give-message', 'email-removed', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id));
574 574
 		$user       = wp_get_current_user();
575
-		$user_login = ! empty( $user->user_login ) ? $user->user_login : __( 'System', 'give' );
576
-		$donor_note = sprintf( __( 'Email address %1$s removed by %2$s', 'give' ), $_GET['email'], $user_login );
577
-		$donor->add_note( $donor_note );
575
+		$user_login = ! empty($user->user_login) ? $user->user_login : __('System', 'give');
576
+		$donor_note = sprintf(__('Email address %1$s removed by %2$s', 'give'), $_GET['email'], $user_login);
577
+		$donor->add_note($donor_note);
578 578
 	} else {
579
-		$url = add_query_arg( 'give-message', 'email-remove-failed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) );
579
+		$url = add_query_arg('give-message', 'email-remove-failed', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id));
580 580
 	}
581 581
 
582
-	wp_safe_redirect( $url );
582
+	wp_safe_redirect($url);
583 583
 	exit;
584 584
 }
585 585
 
586
-add_action( 'give_remove_donor_email', 'give_remove_donor_email', 10 );
586
+add_action('give_remove_donor_email', 'give_remove_donor_email', 10);
587 587
 
588 588
 
589 589
 /**
@@ -594,41 +594,41 @@  discard block
 block discarded – undo
594 594
  * @return bool|null
595 595
  */
596 596
 function give_set_donor_primary_email() {
597
-	if ( empty( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
597
+	if (empty($_GET['id']) || ! is_numeric($_GET['id'])) {
598 598
 		return false;
599 599
 	}
600 600
 
601
-	if ( empty( $_GET['email'] ) || ! is_email( $_GET['email'] ) ) {
601
+	if (empty($_GET['email']) || ! is_email($_GET['email'])) {
602 602
 		return false;
603 603
 	}
604 604
 
605
-	if ( empty( $_GET['_wpnonce'] ) ) {
605
+	if (empty($_GET['_wpnonce'])) {
606 606
 		return false;
607 607
 	}
608 608
 
609 609
 	$nonce = $_GET['_wpnonce'];
610 610
 
611
-	if ( ! wp_verify_nonce( $nonce, 'give-set-donor-primary-email' ) ) {
612
-		wp_die( esc_html__( 'Nonce verification failed', 'give' ), esc_html__( 'Error', 'give' ), array(
611
+	if ( ! wp_verify_nonce($nonce, 'give-set-donor-primary-email')) {
612
+		wp_die(esc_html__('Nonce verification failed', 'give'), esc_html__('Error', 'give'), array(
613 613
 			'response' => 403,
614
-		) );
614
+		));
615 615
 	}
616 616
 
617
-	$donor = new Give_Donor( $_GET['id'] );
617
+	$donor = new Give_Donor($_GET['id']);
618 618
 
619
-	if ( $donor->set_primary_email( $_GET['email'] ) ) {
620
-		$url        = add_query_arg( 'give-message', 'primary-email-updated', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) );
619
+	if ($donor->set_primary_email($_GET['email'])) {
620
+		$url        = add_query_arg('give-message', 'primary-email-updated', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id));
621 621
 		$user       = wp_get_current_user();
622
-		$user_login = ! empty( $user->user_login ) ? $user->user_login : esc_html__( 'System', 'give' );
623
-		$donor_note = sprintf( __( 'Email address %1$s set as primary by %2$s', 'give' ), $_GET['email'], $user_login );
622
+		$user_login = ! empty($user->user_login) ? $user->user_login : esc_html__('System', 'give');
623
+		$donor_note = sprintf(__('Email address %1$s set as primary by %2$s', 'give'), $_GET['email'], $user_login);
624 624
 
625
-		$donor->add_note( $donor_note );
625
+		$donor->add_note($donor_note);
626 626
 	} else {
627
-		$url = add_query_arg( 'give-message', 'primary-email-failed', admin_url( 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor->id ) );
627
+		$url = add_query_arg('give-message', 'primary-email-failed', admin_url('edit.php?post_type=give_forms&page=give-donors&view=overview&id='.$donor->id));
628 628
 	}
629 629
 
630
-	wp_safe_redirect( $url );
630
+	wp_safe_redirect($url);
631 631
 	exit;
632 632
 }
633 633
 
634
-add_action( 'give_set_donor_primary_email', 'give_set_donor_primary_email', 10 );
634
+add_action('give_set_donor_primary_email', 'give_set_donor_primary_email', 10);
Please login to merge, or discard this patch.