Completed
Pull Request — master (#416)
by Ibrahim
06:36
created
includes/shortcodes.php 1 patch
Spacing   +101 added lines, -101 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
 
@@ -24,17 +24,17 @@  discard block
 block discarded – undo
24 24
  * @return string
25 25
  */
26 26
 function give_donation_history() {
27
-	if ( is_user_logged_in() ) {
27
+	if (is_user_logged_in()) {
28 28
 		ob_start();
29
-		give_get_template_part( 'history', 'donations' );
29
+		give_get_template_part('history', 'donations');
30 30
 
31 31
 		return ob_get_clean();
32 32
 	} else {
33
-		echo apply_filters( 'give_donation_history_nonuser_message', '<div class="give_error give_warning"><p>' . __( 'You must be logged in to view your donation history. Please login using your account or create an account using the same email you used to donate with.', 'give' ) . '</p></div>' );
33
+		echo apply_filters('give_donation_history_nonuser_message', '<div class="give_error give_warning"><p>'.__('You must be logged in to view your donation history. Please login using your account or create an account using the same email you used to donate with.', 'give').'</p></div>');
34 34
 	}
35 35
 }
36 36
 
37
-add_shortcode( 'donation_history', 'give_donation_history' );
37
+add_shortcode('donation_history', 'give_donation_history');
38 38
 
39 39
 /**
40 40
  * Donation Form Shortcode
@@ -48,53 +48,53 @@  discard block
 block discarded – undo
48 48
  *
49 49
  * @return string
50 50
  */
51
-function give_form_shortcode( $atts, $content = null ) {
52
-	$atts = shortcode_atts( array(
51
+function give_form_shortcode($atts, $content = null) {
52
+	$atts = shortcode_atts(array(
53 53
 		'id'            => '',
54 54
 		'show_title'    => true,
55 55
 		'show_goal'     => true,
56 56
 		'show_content'  => '',
57 57
 		'float_labels'  => '',
58 58
 		'display_style' => '',
59
-	), $atts, 'give_form' );
59
+	), $atts, 'give_form');
60 60
 
61
-	foreach ( $atts as $key => $value ) {
61
+	foreach ($atts as $key => $value) {
62 62
 		//convert shortcode_atts values to booleans
63
-		if ( $key == 'show_title' ) {
64
-			$atts[ $key ] = filter_var( $atts[ $key ], FILTER_VALIDATE_BOOLEAN );
65
-		} elseif ( $key == 'show_goal' ) {
66
-			$atts[ $key ] = filter_var( $atts[ $key ], FILTER_VALIDATE_BOOLEAN );
63
+		if ($key == 'show_title') {
64
+			$atts[$key] = filter_var($atts[$key], FILTER_VALIDATE_BOOLEAN);
65
+		} elseif ($key == 'show_goal') {
66
+			$atts[$key] = filter_var($atts[$key], FILTER_VALIDATE_BOOLEAN);
67 67
 		}
68 68
 
69 69
 		//validate show_content value
70
-		if ( $key == 'show_content' ) {
71
-			if ( ! in_array( $value, array( 'none', 'above', 'below' ) ) ) {
72
-				$atts[ $key ] = '';
73
-			} else if ( $value == 'above' ) {
74
-				$atts[ $key ] = 'give_pre_form';
75
-			} else if ( $value == 'below' ) {
76
-				$atts[ $key ] = 'give_post_form';
70
+		if ($key == 'show_content') {
71
+			if ( ! in_array($value, array('none', 'above', 'below'))) {
72
+				$atts[$key] = '';
73
+			} else if ($value == 'above') {
74
+				$atts[$key] = 'give_pre_form';
75
+			} else if ($value == 'below') {
76
+				$atts[$key] = 'give_post_form';
77 77
 			}
78 78
 		}
79 79
 
80 80
 		//validate display_style and float_labels value
81
-		if ( ( $key == 'display_style' && ! in_array( $value, array( 'onpage', 'reveal', 'modal' ) ) )
82
-		     || ( $key == 'float_labels' && ! in_array( $value, array( 'enabled', 'disabled' ) ) )
81
+		if (($key == 'display_style' && ! in_array($value, array('onpage', 'reveal', 'modal')))
82
+		     || ($key == 'float_labels' && ! in_array($value, array('enabled', 'disabled')))
83 83
 		) {
84 84
 
85
-			$atts[ $key ] = '';
85
+			$atts[$key] = '';
86 86
 		}
87 87
 	}
88 88
 
89 89
 	//get the Give Form
90 90
 	ob_start();
91
-	give_get_donation_form( $atts );
91
+	give_get_donation_form($atts);
92 92
 	$final_output = ob_get_clean();
93 93
 
94
-	return apply_filters( 'give_donate_form', $final_output, $atts );
94
+	return apply_filters('give_donate_form', $final_output, $atts);
95 95
 }
96 96
 
97
-add_shortcode( 'give_form', 'give_form_shortcode' );
97
+add_shortcode('give_form', 'give_form_shortcode');
98 98
 
99 99
 /**
100 100
  * Donation Form Goal Shortcode
@@ -108,37 +108,37 @@  discard block
 block discarded – undo
108 108
  *
109 109
  * @return string
110 110
  */
111
-function give_goal_shortcode( $atts, $content = null ) {
112
-	$atts = shortcode_atts( array(
111
+function give_goal_shortcode($atts, $content = null) {
112
+	$atts = shortcode_atts(array(
113 113
 		'id'        => '',
114 114
 		'show_text' => true,
115 115
 		'show_bar'  => true,
116
-	), $atts, 'give_goal' );
116
+	), $atts, 'give_goal');
117 117
 
118 118
 
119 119
 	//get the Give Form
120 120
 	ob_start();
121 121
 
122 122
 	//Sanity check 1: ensure there is an ID Provided
123
-	if ( empty( $atts['id'] ) ) {
124
-		give_output_error( __( 'Error: No Donation form ID for the shortcode provided.', 'give' ), true );
123
+	if (empty($atts['id'])) {
124
+		give_output_error(__('Error: No Donation form ID for the shortcode provided.', 'give'), true);
125 125
 	}
126 126
 
127 127
 	//Sanity check 2: Check that this form even has Goals enabled
128
-	$goal_option = get_post_meta( $atts['id'], '_give_goal_option', true );
129
-	if ( empty( $goal_option ) || $goal_option !== 'yes' ) {
130
-		give_output_error( __( 'Error: This form does not have Goals enabled.', 'give' ), true );
128
+	$goal_option = get_post_meta($atts['id'], '_give_goal_option', true);
129
+	if (empty($goal_option) || $goal_option !== 'yes') {
130
+		give_output_error(__('Error: This form does not have Goals enabled.', 'give'), true);
131 131
 	} else {
132 132
 		//Passed all sanity checks: output Goal
133
-		give_show_goal_progress( $atts['id'], $atts );
133
+		give_show_goal_progress($atts['id'], $atts);
134 134
 	}
135 135
 
136 136
 	$final_output = ob_get_clean();
137 137
 
138
-	return apply_filters( 'give_goal_shortcode_output', $final_output, $atts );
138
+	return apply_filters('give_goal_shortcode_output', $final_output, $atts);
139 139
 }
140 140
 
141
-add_shortcode( 'give_goal', 'give_goal_shortcode' );
141
+add_shortcode('give_goal', 'give_goal_shortcode');
142 142
 
143 143
 
144 144
 /**
@@ -155,16 +155,16 @@  discard block
 block discarded – undo
155 155
  * @uses  give_login_form()
156 156
  * @return string
157 157
  */
158
-function give_login_form_shortcode( $atts, $content = null ) {
159
-	extract( shortcode_atts( array(
158
+function give_login_form_shortcode($atts, $content = null) {
159
+	extract(shortcode_atts(array(
160 160
 			'redirect' => '',
161
-		), $atts, 'give_login' )
161
+		), $atts, 'give_login')
162 162
 	);
163 163
 
164
-	return give_login_form( $redirect );
164
+	return give_login_form($redirect);
165 165
 }
166 166
 
167
-add_shortcode( 'give_login', 'give_login_form_shortcode' );
167
+add_shortcode('give_login', 'give_login_form_shortcode');
168 168
 
169 169
 /**
170 170
  * Register Shortcode
@@ -179,16 +179,16 @@  discard block
 block discarded – undo
179 179
  * @uses  give_register_form()
180 180
  * @return string
181 181
  */
182
-function give_register_form_shortcode( $atts, $content = null ) {
183
-	extract( shortcode_atts( array(
182
+function give_register_form_shortcode($atts, $content = null) {
183
+	extract(shortcode_atts(array(
184 184
 			'redirect' => '',
185
-		), $atts, 'give_register' )
185
+		), $atts, 'give_register')
186 186
 	);
187 187
 
188
-	return give_register_form( $redirect );
188
+	return give_register_form($redirect);
189 189
 }
190 190
 
191
-add_shortcode( 'give_register', 'give_register_form_shortcode' );
191
+add_shortcode('give_register', 'give_register_form_shortcode');
192 192
 
193 193
 
194 194
 /**
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
  *
204 204
  * @return string
205 205
  */
206
-function give_receipt_shortcode( $atts, $content = null ) {
206
+function give_receipt_shortcode($atts, $content = null) {
207 207
 
208 208
 	global $give_receipt_args, $payment;
209 209
 
@@ -211,48 +211,48 @@  discard block
 block discarded – undo
211 211
 	$session = give_get_purchase_session();
212 212
 
213 213
 	//set payment key var
214
-	if ( isset( $_GET['payment_key'] ) ) {
215
-		$payment_key = urldecode( $_GET['payment_key'] );
216
-	} elseif ( $give_receipt_args['payment_key'] ) {
214
+	if (isset($_GET['payment_key'])) {
215
+		$payment_key = urldecode($_GET['payment_key']);
216
+	} elseif ($give_receipt_args['payment_key']) {
217 217
 		$payment_key = $give_receipt_args['payment_key'];
218
-	} else if ( $session ) {
218
+	} else if ($session) {
219 219
 		$payment_key = $session['purchase_key'];
220 220
 	}
221 221
 
222 222
 	ob_start();
223 223
 
224 224
 	//Check for payment key
225
-	if ( empty( $payment_key ) ) { ?>
225
+	if (empty($payment_key)) { ?>
226 226
 
227 227
 		<div class="give_errors">
228
-			<p class="give_error"><?php echo apply_filters( 'give_receipt_no_payment_key', __( 'Sorry, there was a problem identifying this donation. Please contact the site owner for more information.', 'give' ) ); ?></p>
228
+			<p class="give_error"><?php echo apply_filters('give_receipt_no_payment_key', __('Sorry, there was a problem identifying this donation. Please contact the site owner for more information.', 'give')); ?></p>
229 229
 		</div>
230 230
 
231 231
 		<?php return ob_get_clean(); //return error
232 232
 	}
233 233
 
234 234
 	//Set our important payment information variables
235
-	$give_receipt_args['id'] = give_get_purchase_id_by_key( $payment_key );
236
-	$donor_id                = give_get_payment_user_id( $give_receipt_args['id'] );
237
-	$payment                 = get_post( $give_receipt_args['id'] );
235
+	$give_receipt_args['id'] = give_get_purchase_id_by_key($payment_key);
236
+	$donor_id                = give_get_payment_user_id($give_receipt_args['id']);
237
+	$payment                 = get_post($give_receipt_args['id']);
238 238
 
239 239
 
240
-	$give_receipt_args = shortcode_atts( array(
241
-		'error'          => __( 'Sorry, it appears the viewing window for this donation receipt has expired or you do not have the permission to view this donation receipt.', 'give' ),
240
+	$give_receipt_args = shortcode_atts(array(
241
+		'error'          => __('Sorry, it appears the viewing window for this donation receipt has expired or you do not have the permission to view this donation receipt.', 'give'),
242 242
 		'price'          => true,
243 243
 		'date'           => true,
244 244
 		'payment_key'    => false,
245 245
 		'payment_method' => true,
246 246
 		'payment_id'     => true
247
-	), $atts, 'give_receipt' );
247
+	), $atts, 'give_receipt');
248 248
 
249 249
 	//Is registration open? If so, add better error messaging to tell user their session expired
250
-	if ( get_option( 'users_can_register' ) ) {
250
+	if (get_option('users_can_register')) {
251 251
 
252
-		$email            = get_post_meta( $payment->ID, '_give_payment_user_email', true );
253
-		$donation_history = get_permalink( give_get_option( 'history_page' ) );
252
+		$email            = get_post_meta($payment->ID, '_give_payment_user_email', true);
253
+		$donation_history = get_permalink(give_get_option('history_page'));
254 254
 
255
-		$give_receipt_args['error'] .= sprintf( __( ' To view your receipt, please <a href="%s">create an account</a> using the following email %s (the email attached to this donation) and visit the <a href="%s">donation history page</a>' ), wp_registration_url(), '<strong>' . $email . '</strong>', $donation_history );
255
+		$give_receipt_args['error'] .= sprintf(__(' To view your receipt, please <a href="%s">create an account</a> using the following email %s (the email attached to this donation) and visit the <a href="%s">donation history page</a>'), wp_registration_url(), '<strong>'.$email.'</strong>', $donation_history);
256 256
 
257 257
 	}
258 258
 
@@ -266,9 +266,9 @@  discard block
 block discarded – undo
266 266
 	 *
267 267
 	 * Or if user is logged in and the user can view sensitive donor data
268 268
 	 */
269
-	$user_can_view = ( is_user_logged_in() && $donor_id == get_current_user_id() ) || ( ! is_user_logged_in() && give_get_purchase_session() ) || current_user_can( 'view_give_sensitive_data' );
269
+	$user_can_view = (is_user_logged_in() && $donor_id == get_current_user_id()) || ( ! is_user_logged_in() && give_get_purchase_session()) || current_user_can('view_give_sensitive_data');
270 270
 
271
-	if ( ! apply_filters( 'give_user_can_view_receipt', $user_can_view, $give_receipt_args ) ) { ?>
271
+	if ( ! apply_filters('give_user_can_view_receipt', $user_can_view, $give_receipt_args)) { ?>
272 272
 
273 273
 		<div class="give_errors">
274 274
 			<p class="give_error"><?php echo $give_receipt_args['error']; ?></p>
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 
279 279
 	<?php }
280 280
 
281
-	give_get_template_part( 'shortcode', 'receipt' );
281
+	give_get_template_part('shortcode', 'receipt');
282 282
 
283 283
 	$display = ob_get_clean();
284 284
 
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 
287 287
 }
288 288
 
289
-add_shortcode( 'give_receipt', 'give_receipt_shortcode' );
289
+add_shortcode('give_receipt', 'give_receipt_shortcode');
290 290
 
291 291
 /**
292 292
  * Profile Editor Shortcode
@@ -306,18 +306,18 @@  discard block
 block discarded – undo
306 306
  *
307 307
  * @return string Output generated from the profile editor
308 308
  */
309
-function give_profile_editor_shortcode( $atts, $content = null ) {
309
+function give_profile_editor_shortcode($atts, $content = null) {
310 310
 
311 311
 	ob_start();
312 312
 
313
-	give_get_template_part( 'shortcode', 'profile-editor' );
313
+	give_get_template_part('shortcode', 'profile-editor');
314 314
 
315 315
 	$display = ob_get_clean();
316 316
 
317 317
 	return $display;
318 318
 }
319 319
 
320
-add_shortcode( 'give_profile_editor', 'give_profile_editor_shortcode' );
320
+add_shortcode('give_profile_editor', 'give_profile_editor_shortcode');
321 321
 
322 322
 /**
323 323
  * Process Profile Updater Form
@@ -330,30 +330,30 @@  discard block
 block discarded – undo
330 330
  *
331 331
  * @return false
332 332
  */
333
-function give_process_profile_editor_updates( $data ) {
333
+function give_process_profile_editor_updates($data) {
334 334
 	// Profile field change request
335
-	if ( empty( $_POST['give_profile_editor_submit'] ) && ! is_user_logged_in() ) {
335
+	if (empty($_POST['give_profile_editor_submit']) && ! is_user_logged_in()) {
336 336
 		return false;
337 337
 	}
338 338
 
339 339
 	// Nonce security
340
-	if ( ! wp_verify_nonce( $data['give_profile_editor_nonce'], 'give-profile-editor-nonce' ) ) {
340
+	if ( ! wp_verify_nonce($data['give_profile_editor_nonce'], 'give-profile-editor-nonce')) {
341 341
 		return false;
342 342
 	}
343 343
 
344 344
 	$user_id       = get_current_user_id();
345
-	$old_user_data = get_userdata( $user_id );
346
-
347
-	$display_name = isset( $data['give_display_name'] ) ? sanitize_text_field( $data['give_display_name'] ) : $old_user_data->display_name;
348
-	$first_name   = isset( $data['give_first_name'] ) ? sanitize_text_field( $data['give_first_name'] ) : $old_user_data->first_name;
349
-	$last_name    = isset( $data['give_last_name'] ) ? sanitize_text_field( $data['give_last_name'] ) : $old_user_data->last_name;
350
-	$email        = isset( $data['give_email'] ) ? sanitize_email( $data['give_email'] ) : $old_user_data->user_email;
351
-	$line1        = ( isset( $data['give_address_line1'] ) ? sanitize_text_field( $data['give_address_line1'] ) : '' );
352
-	$line2        = ( isset( $data['give_address_line2'] ) ? sanitize_text_field( $data['give_address_line2'] ) : '' );
353
-	$city         = ( isset( $data['give_address_city'] ) ? sanitize_text_field( $data['give_address_city'] ) : '' );
354
-	$state        = ( isset( $data['give_address_state'] ) ? sanitize_text_field( $data['give_address_state'] ) : '' );
355
-	$zip          = ( isset( $data['give_address_zip'] ) ? sanitize_text_field( $data['give_address_zip'] ) : '' );
356
-	$country      = ( isset( $data['give_address_country'] ) ? sanitize_text_field( $data['give_address_country'] ) : '' );
345
+	$old_user_data = get_userdata($user_id);
346
+
347
+	$display_name = isset($data['give_display_name']) ? sanitize_text_field($data['give_display_name']) : $old_user_data->display_name;
348
+	$first_name   = isset($data['give_first_name']) ? sanitize_text_field($data['give_first_name']) : $old_user_data->first_name;
349
+	$last_name    = isset($data['give_last_name']) ? sanitize_text_field($data['give_last_name']) : $old_user_data->last_name;
350
+	$email        = isset($data['give_email']) ? sanitize_email($data['give_email']) : $old_user_data->user_email;
351
+	$line1        = (isset($data['give_address_line1']) ? sanitize_text_field($data['give_address_line1']) : '');
352
+	$line2        = (isset($data['give_address_line2']) ? sanitize_text_field($data['give_address_line2']) : '');
353
+	$city         = (isset($data['give_address_city']) ? sanitize_text_field($data['give_address_city']) : '');
354
+	$state        = (isset($data['give_address_state']) ? sanitize_text_field($data['give_address_state']) : '');
355
+	$zip          = (isset($data['give_address_zip']) ? sanitize_text_field($data['give_address_zip']) : '');
356
+	$country      = (isset($data['give_address_country']) ? sanitize_text_field($data['give_address_country']) : '');
357 357
 
358 358
 	$userdata = array(
359 359
 		'ID'           => $user_id,
@@ -373,45 +373,45 @@  discard block
 block discarded – undo
373 373
 		'country' => $country
374 374
 	);
375 375
 
376
-	do_action( 'give_pre_update_user_profile', $user_id, $userdata );
376
+	do_action('give_pre_update_user_profile', $user_id, $userdata);
377 377
 
378 378
 	// New password
379
-	if ( ! empty( $data['give_new_user_pass1'] ) ) {
380
-		if ( $data['give_new_user_pass1'] !== $data['give_new_user_pass2'] ) {
381
-			give_set_error( 'password_mismatch', __( 'The passwords you entered do not match. Please try again.', 'give' ) );
379
+	if ( ! empty($data['give_new_user_pass1'])) {
380
+		if ($data['give_new_user_pass1'] !== $data['give_new_user_pass2']) {
381
+			give_set_error('password_mismatch', __('The passwords you entered do not match. Please try again.', 'give'));
382 382
 		} else {
383 383
 			$userdata['user_pass'] = $data['give_new_user_pass1'];
384 384
 		}
385 385
 	}
386 386
 
387 387
 	// Make sure the new email doesn't belong to another user
388
-	if ( $email != $old_user_data->user_email ) {
389
-		if ( email_exists( $email ) ) {
390
-			give_set_error( 'email_exists', __( 'The email you entered belongs to another user. Please use another.', 'give' ) );
388
+	if ($email != $old_user_data->user_email) {
389
+		if (email_exists($email)) {
390
+			give_set_error('email_exists', __('The email you entered belongs to another user. Please use another.', 'give'));
391 391
 		}
392 392
 	}
393 393
 
394 394
 	// Check for errors
395 395
 	$errors = give_get_errors();
396 396
 
397
-	if ( $errors ) {
397
+	if ($errors) {
398 398
 		// Send back to the profile editor if there are errors
399
-		wp_redirect( $data['give_redirect'] );
399
+		wp_redirect($data['give_redirect']);
400 400
 		give_die();
401 401
 	}
402 402
 
403 403
 	// Update the user
404
-	$meta    = update_user_meta( $user_id, '_give_user_address', $address );
405
-	$updated = wp_update_user( $userdata );
404
+	$meta    = update_user_meta($user_id, '_give_user_address', $address);
405
+	$updated = wp_update_user($userdata);
406 406
 
407
-	if ( $updated ) {
408
-		do_action( 'give_user_profile_updated', $user_id, $userdata );
409
-		wp_redirect( add_query_arg( 'updated', 'true', $data['give_redirect'] ) );
407
+	if ($updated) {
408
+		do_action('give_user_profile_updated', $user_id, $userdata);
409
+		wp_redirect(add_query_arg('updated', 'true', $data['give_redirect']));
410 410
 		give_die();
411 411
 	}
412 412
 
413 413
 	return false;
414 414
 }
415 415
 
416
-add_action( 'give_edit_user_profile', 'give_process_profile_editor_updates' );
416
+add_action('give_edit_user_profile', 'give_process_profile_editor_updates');
417 417
 
Please login to merge, or discard this patch.