Completed
Pull Request — master (#601)
by Devin
20:16
created
includes/user-functions.php 1 patch
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Exit if accessed directly
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if ( ! defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
@@ -30,36 +30,36 @@  discard block
 block discarded – undo
30 30
  *
31 31
  * @return bool|object List of all user purchases
32 32
  */
33
-function give_get_users_purchases( $user = 0, $number = 20, $pagination = false, $status = 'complete' ) {
33
+function give_get_users_purchases($user = 0, $number = 20, $pagination = false, $status = 'complete') {
34 34
 
35
-	if ( empty( $user ) ) {
35
+	if (empty($user)) {
36 36
 		$user = get_current_user_id();
37 37
 	}
38 38
 
39
-	if ( 0 === $user && ! Give()->email_access->token_exists ) {
39
+	if (0 === $user && ! Give()->email_access->token_exists) {
40 40
 		return false;
41 41
 	}
42 42
 
43 43
 	$status = $status === 'complete' ? 'publish' : $status;
44 44
 
45
-	if ( $pagination ) {
46
-		if ( get_query_var( 'paged' ) ) {
47
-			$paged = get_query_var( 'paged' );
48
-		} else if ( get_query_var( 'page' ) ) {
49
-			$paged = get_query_var( 'page' );
45
+	if ($pagination) {
46
+		if (get_query_var('paged')) {
47
+			$paged = get_query_var('paged');
48
+		} else if (get_query_var('page')) {
49
+			$paged = get_query_var('page');
50 50
 		} else {
51 51
 			$paged = 1;
52 52
 		}
53 53
 	}
54 54
 
55
-	$args = apply_filters( 'give_get_users_purchases_args', array(
55
+	$args = apply_filters('give_get_users_purchases_args', array(
56 56
 		'user'    => $user,
57 57
 		'number'  => $number,
58 58
 		'status'  => $status,
59 59
 		'orderby' => 'date'
60
-	) );
60
+	));
61 61
 
62
-	if ( $pagination ) {
62
+	if ($pagination) {
63 63
 
64 64
 		$args['page'] = $paged;
65 65
 
@@ -69,20 +69,20 @@  discard block
 block discarded – undo
69 69
 
70 70
 	}
71 71
 
72
-	$by_user_id = is_numeric( $user ) ? true : false;
73
-	$customer   = new Give_Customer( $user, $by_user_id );
72
+	$by_user_id = is_numeric($user) ? true : false;
73
+	$customer   = new Give_Customer($user, $by_user_id);
74 74
 
75
-	if ( ! empty( $customer->payment_ids ) ) {
75
+	if ( ! empty($customer->payment_ids)) {
76 76
 
77
-		unset( $args['user'] );
78
-		$args['post__in'] = array_map( 'absint', explode( ',', $customer->payment_ids ) );
77
+		unset($args['user']);
78
+		$args['post__in'] = array_map('absint', explode(',', $customer->payment_ids));
79 79
 
80 80
 	}
81 81
 
82
-	$purchases = give_get_payments( apply_filters( 'give_get_users_purchases_args', $args ) );
82
+	$purchases = give_get_payments(apply_filters('give_get_users_purchases_args', $args));
83 83
 
84 84
 	// No purchases
85
-	if ( ! $purchases ) {
85
+	if ( ! $purchases) {
86 86
 		return false;
87 87
 	}
88 88
 
@@ -101,64 +101,64 @@  discard block
 block discarded – undo
101 101
  *
102 102
  * @return bool|object List of unique forms purchased by user
103 103
  */
104
-function give_get_users_completed_donations( $user = 0, $status = 'complete' ) {
105
-	if ( empty( $user ) ) {
104
+function give_get_users_completed_donations($user = 0, $status = 'complete') {
105
+	if (empty($user)) {
106 106
 		$user = get_current_user_id();
107 107
 	}
108 108
 
109
-	if ( empty( $user ) ) {
109
+	if (empty($user)) {
110 110
 		return false;
111 111
 	}
112 112
 
113
-	$by_user_id = is_numeric( $user ) ? true : false;
113
+	$by_user_id = is_numeric($user) ? true : false;
114 114
 
115
-	$customer = new Give_Customer( $user, $by_user_id );
115
+	$customer = new Give_Customer($user, $by_user_id);
116 116
 
117
-	if ( empty( $customer->payment_ids ) ) {
117
+	if (empty($customer->payment_ids)) {
118 118
 		return false;
119 119
 	}
120 120
 
121 121
 	// Get all the items purchased
122
-	$payment_ids    = array_reverse( explode( ',', $customer->payment_ids ) );
123
-	$limit_payments = apply_filters( 'give_users_completed_donations_payments', 50 );
124
-	if ( ! empty( $limit_payments ) ) {
125
-		$payment_ids = array_slice( $payment_ids, 0, $limit_payments );
122
+	$payment_ids    = array_reverse(explode(',', $customer->payment_ids));
123
+	$limit_payments = apply_filters('give_users_completed_donations_payments', 50);
124
+	if ( ! empty($limit_payments)) {
125
+		$payment_ids = array_slice($payment_ids, 0, $limit_payments);
126 126
 	}
127 127
 	$donation_data = array();
128
-	foreach ( $payment_ids as $payment_id ) {
129
-		$donation_data[] = give_get_payment_meta( $payment_id );
128
+	foreach ($payment_ids as $payment_id) {
129
+		$donation_data[] = give_get_payment_meta($payment_id);
130 130
 	}
131 131
 
132
-	if ( empty( $donation_data ) ) {
132
+	if (empty($donation_data)) {
133 133
 		return false;
134 134
 	}
135 135
 
136 136
 	// Grab only the post ids "form_id" of the forms purchased on this order
137 137
 	$completed_donations_ids = array();
138
-	foreach ( $donation_data as $purchase_meta ) {
138
+	foreach ($donation_data as $purchase_meta) {
139 139
 		$completed_donations_ids[] = $purchase_meta['form_id'];
140 140
 	}
141
-	if ( empty( $completed_donations_ids ) ) {
141
+	if (empty($completed_donations_ids)) {
142 142
 		return false;
143 143
 	}
144 144
 
145 145
 	// Only include each product purchased once
146
-	$form_ids = array_unique( $completed_donations_ids );
146
+	$form_ids = array_unique($completed_donations_ids);
147 147
 
148 148
 	// Make sure we still have some products and a first item
149
-	if ( empty ( $form_ids ) || ! isset( $form_ids[0] ) ) {
149
+	if (empty ($form_ids) || ! isset($form_ids[0])) {
150 150
 		return false;
151 151
 	}
152 152
 
153
-	$post_type = get_post_type( $form_ids[0] );
153
+	$post_type = get_post_type($form_ids[0]);
154 154
 
155
-	$args = apply_filters( 'give_get_users_completed_donations_args', array(
155
+	$args = apply_filters('give_get_users_completed_donations_args', array(
156 156
 		'include'        => $form_ids,
157 157
 		'post_type'      => $post_type,
158
-		'posts_per_page' => - 1
159
-	) );
158
+		'posts_per_page' => -1
159
+	));
160 160
 
161
-	return apply_filters( 'give_users_completed_donations_list', get_posts( $args ) );
161
+	return apply_filters('give_users_completed_donations_list', get_posts($args));
162 162
 }
163 163
 
164 164
 
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
  *
175 175
  * @return      bool - true if has purchased, false other wise.
176 176
  */
177
-function give_has_purchases( $user_id = null ) {
178
-	if ( empty( $user_id ) ) {
177
+function give_has_purchases($user_id = null) {
178
+	if (empty($user_id)) {
179 179
 		$user_id = get_current_user_id();
180 180
 	}
181 181
 
182
-	if ( give_get_users_purchases( $user_id, 1 ) ) {
182
+	if (give_get_users_purchases($user_id, 1)) {
183 183
 		return true; // User has at least one purchase
184 184
 	}
185 185
 
@@ -199,32 +199,32 @@  discard block
 block discarded – undo
199 199
  *
200 200
  * @return      array
201 201
  */
202
-function give_get_purchase_stats_by_user( $user = '' ) {
202
+function give_get_purchase_stats_by_user($user = '') {
203 203
 
204
-	if ( is_email( $user ) ) {
204
+	if (is_email($user)) {
205 205
 
206 206
 		$field = 'email';
207 207
 
208
-	} elseif ( is_numeric( $user ) ) {
208
+	} elseif (is_numeric($user)) {
209 209
 
210 210
 		$field = 'user_id';
211 211
 
212 212
 	}
213 213
 
214 214
 	$stats    = array();
215
-	$customer = Give()->customers->get_customer_by( $field, $user );
215
+	$customer = Give()->customers->get_customer_by($field, $user);
216 216
 
217
-	if ( $customer ) {
217
+	if ($customer) {
218 218
 
219
-		$customer = new Give_Customer( $customer->id );
219
+		$customer = new Give_Customer($customer->id);
220 220
 
221
-		$stats['purchases']   = absint( $customer->purchase_count );
222
-		$stats['total_spent'] = give_sanitize_amount( $customer->purchase_value );
221
+		$stats['purchases']   = absint($customer->purchase_count);
222
+		$stats['total_spent'] = give_sanitize_amount($customer->purchase_value);
223 223
 
224 224
 	}
225 225
 
226 226
 
227
-	return (array) apply_filters( 'give_purchase_stats_by_user', $stats, $user );
227
+	return (array) apply_filters('give_purchase_stats_by_user', $stats, $user);
228 228
 }
229 229
 
230 230
 
@@ -240,22 +240,22 @@  discard block
 block discarded – undo
240 240
  *
241 241
  * @return      int - the total number of purchases
242 242
  */
243
-function give_count_purchases_of_customer( $user = null ) {
243
+function give_count_purchases_of_customer($user = null) {
244 244
 
245 245
 	//Logged in?
246
-	if ( empty( $user ) ) {
246
+	if (empty($user)) {
247 247
 		$user = get_current_user_id();
248 248
 	}
249 249
 
250 250
 	//Email access?
251
-	if ( empty( $user ) && Give()->email_access->token_email ) {
251
+	if (empty($user) && Give()->email_access->token_email) {
252 252
 		$user = Give()->email_access->token_email;
253 253
 	}
254 254
 
255 255
 
256
-	$stats = ! empty( $user ) ? give_get_purchase_stats_by_user( $user ) : false;
256
+	$stats = ! empty($user) ? give_get_purchase_stats_by_user($user) : false;
257 257
 
258
-	return isset( $stats['purchases'] ) ? $stats['purchases'] : 0;
258
+	return isset($stats['purchases']) ? $stats['purchases'] : 0;
259 259
 }
260 260
 
261 261
 /**
@@ -268,9 +268,9 @@  discard block
 block discarded – undo
268 268
  *
269 269
  * @return      float - the total amount the user has spent
270 270
  */
271
-function give_purchase_total_of_user( $user = null ) {
271
+function give_purchase_total_of_user($user = null) {
272 272
 
273
-	$stats = give_get_purchase_stats_by_user( $user );
273
+	$stats = give_get_purchase_stats_by_user($user);
274 274
 
275 275
 	return $stats['total_spent'];
276 276
 }
@@ -286,11 +286,11 @@  discard block
 block discarded – undo
286 286
  *
287 287
  * @return      bool
288 288
  */
289
-function give_validate_username( $username ) {
290
-	$sanitized = sanitize_user( $username, false );
291
-	$valid     = ( $sanitized == $username );
289
+function give_validate_username($username) {
290
+	$sanitized = sanitize_user($username, false);
291
+	$valid     = ($sanitized == $username);
292 292
 
293
-	return (bool) apply_filters( 'give_validate_username', $valid, $username );
293
+	return (bool) apply_filters('give_validate_username', $valid, $username);
294 294
 }
295 295
 
296 296
 
@@ -307,32 +307,32 @@  discard block
 block discarded – undo
307 307
  *
308 308
  * @return      void
309 309
  */
310
-function give_add_past_purchases_to_new_user( $user_id ) {
310
+function give_add_past_purchases_to_new_user($user_id) {
311 311
 
312
-	$email = get_the_author_meta( 'user_email', $user_id );
312
+	$email = get_the_author_meta('user_email', $user_id);
313 313
 
314
-	$payments = give_get_payments( array( 's' => $email ) );
314
+	$payments = give_get_payments(array('s' => $email));
315 315
 
316
-	if ( $payments ) {
317
-		foreach ( $payments as $payment ) {
318
-			if ( intval( give_get_payment_user_id( $payment->ID ) ) > 0 ) {
316
+	if ($payments) {
317
+		foreach ($payments as $payment) {
318
+			if (intval(give_get_payment_user_id($payment->ID)) > 0) {
319 319
 				continue;
320 320
 			} // This payment already associated with an account
321 321
 
322
-			$meta                    = give_get_payment_meta( $payment->ID );
323
-			$meta['user_info']       = maybe_unserialize( $meta['user_info'] );
322
+			$meta                    = give_get_payment_meta($payment->ID);
323
+			$meta['user_info']       = maybe_unserialize($meta['user_info']);
324 324
 			$meta['user_info']['id'] = $user_id;
325 325
 			$meta['user_info']       = $meta['user_info'];
326 326
 
327 327
 			// Store the updated user ID in the payment meta
328
-			give_update_payment_meta( $payment->ID, '_give_payment_meta', $meta );
329
-			give_update_payment_meta( $payment->ID, '_give_payment_user_id', $user_id );
328
+			give_update_payment_meta($payment->ID, '_give_payment_meta', $meta);
329
+			give_update_payment_meta($payment->ID, '_give_payment_user_id', $user_id);
330 330
 		}
331 331
 	}
332 332
 
333 333
 }
334 334
 
335
-add_action( 'user_register', 'give_add_past_purchases_to_new_user' );
335
+add_action('user_register', 'give_add_past_purchases_to_new_user');
336 336
 
337 337
 
338 338
 /**
@@ -354,34 +354,34 @@  discard block
 block discarded – undo
354 354
  * @since         1.0
355 355
  * @return        array - The donor's address, if any
356 356
  */
357
-function give_get_donor_address( $user_id = 0 ) {
358
-	if ( empty( $user_id ) ) {
357
+function give_get_donor_address($user_id = 0) {
358
+	if (empty($user_id)) {
359 359
 		$user_id = get_current_user_id();
360 360
 	}
361 361
 
362
-	$address = get_user_meta( $user_id, '_give_user_address', true );
362
+	$address = get_user_meta($user_id, '_give_user_address', true);
363 363
 
364
-	if ( ! isset( $address['line1'] ) ) {
364
+	if ( ! isset($address['line1'])) {
365 365
 		$address['line1'] = '';
366 366
 	}
367 367
 
368
-	if ( ! isset( $address['line2'] ) ) {
368
+	if ( ! isset($address['line2'])) {
369 369
 		$address['line2'] = '';
370 370
 	}
371 371
 
372
-	if ( ! isset( $address['city'] ) ) {
372
+	if ( ! isset($address['city'])) {
373 373
 		$address['city'] = '';
374 374
 	}
375 375
 
376
-	if ( ! isset( $address['zip'] ) ) {
376
+	if ( ! isset($address['zip'])) {
377 377
 		$address['zip'] = '';
378 378
 	}
379 379
 
380
-	if ( ! isset( $address['country'] ) ) {
380
+	if ( ! isset($address['country'])) {
381 381
 		$address['country'] = '';
382 382
 	}
383 383
 
384
-	if ( ! isset( $address['state'] ) ) {
384
+	if ( ! isset($address['state'])) {
385 385
 		$address['state'] = '';
386 386
 	}
387 387
 
@@ -401,25 +401,25 @@  discard block
 block discarded – undo
401 401
  *
402 402
  * @return        void
403 403
  */
404
-function give_new_user_notification( $user_id = 0, $user_data = array() ) {
404
+function give_new_user_notification($user_id = 0, $user_data = array()) {
405 405
 
406
-	if ( empty( $user_id ) || empty( $user_data ) ) {
406
+	if (empty($user_id) || empty($user_data)) {
407 407
 		return;
408 408
 	}
409
-	$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
410
-	$message  = sprintf( esc_attr__( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n";
411
-	$message .= sprintf( esc_attr__( 'Username: %s' ), $user_data['user_login'] ) . "\r\n\r\n";
412
-	$message .= sprintf( esc_attr__( 'E-mail: %s' ), $user_data['user_email'] ) . "\r\n";
409
+	$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
410
+	$message  = sprintf(esc_attr__('New user registration on your site %s:'), $blogname)."\r\n\r\n";
411
+	$message .= sprintf(esc_attr__('Username: %s'), $user_data['user_login'])."\r\n\r\n";
412
+	$message .= sprintf(esc_attr__('E-mail: %s'), $user_data['user_email'])."\r\n";
413 413
 
414
-	@wp_mail( get_option( 'admin_email' ), sprintf( esc_attr__( '[%s] New User Registration' ), $blogname ), $message );
414
+	@wp_mail(get_option('admin_email'), sprintf(esc_attr__('[%s] New User Registration'), $blogname), $message);
415 415
 
416
-	$message = sprintf( esc_attr__( 'Username: %s' ), $user_data['user_login'] ) . "\r\n";
417
-	$message .= sprintf( esc_attr__( 'Password: %s' ), esc_attr__( '[Password entered during donation]', 'give' ) ) . "\r\n";
416
+	$message = sprintf(esc_attr__('Username: %s'), $user_data['user_login'])."\r\n";
417
+	$message .= sprintf(esc_attr__('Password: %s'), esc_attr__('[Password entered during donation]', 'give'))."\r\n";
418 418
 
419
-	$message .= '<a href="' . wp_login_url() . '"> ' . esc_attr__( 'Click Here to Login', 'give' ) . ' &raquo;</a>' . "\r\n";
419
+	$message .= '<a href="'.wp_login_url().'"> '.esc_attr__('Click Here to Login', 'give').' &raquo;</a>'."\r\n";
420 420
 
421
-	wp_mail( $user_data['user_email'], sprintf( esc_attr__( '[%s] Your username and password' ), $blogname ), $message );
421
+	wp_mail($user_data['user_email'], sprintf(esc_attr__('[%s] Your username and password'), $blogname), $message);
422 422
 
423 423
 }
424 424
 
425
-add_action( 'give_insert_user', 'give_new_user_notification', 10, 2 );
425
+add_action('give_insert_user', 'give_new_user_notification', 10, 2);
Please login to merge, or discard this patch.