Completed
Push — master ( e581eb...b18c62 )
by Devin
52:44 queued 32:39
created
includes/shortcodes.php 1 patch
Spacing   +108 added lines, -108 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
 
@@ -25,28 +25,28 @@  discard block
 block discarded – undo
25 25
  */
26 26
 function give_donation_history() {
27 27
 
28
-	$email_access = give_get_option( 'email_access' );
28
+	$email_access = give_get_option('email_access');
29 29
 
30 30
 	//Is user logged in? Does a session exist? Does an email-access token exist?
31
-	if ( is_user_logged_in() || Give()->session->get_session_expiration() !== false || ( $email_access == 'on' && Give()->email_access->token_exists ) ) {
31
+	if (is_user_logged_in() || Give()->session->get_session_expiration() !== false || ($email_access == 'on' && Give()->email_access->token_exists)) {
32 32
 		ob_start();
33
-		give_get_template_part( 'history', 'donations' );
33
+		give_get_template_part('history', 'donations');
34 34
 
35 35
 		return ob_get_clean();
36 36
 	} //Is Email-based access enabled?
37
-	elseif ( $email_access == 'on' ) {
37
+	elseif ($email_access == 'on') {
38 38
 
39 39
 		ob_start();
40
-		give_get_template_part( 'email', 'login-form' );
40
+		give_get_template_part('email', 'login-form');
41 41
 
42 42
 		return ob_get_clean();
43 43
 	} else {
44
-		$message = __( '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' );
45
-		echo apply_filters( 'give_donation_history_nonuser_message', give_output_error( $message, false ), $message );
44
+		$message = __('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');
45
+		echo apply_filters('give_donation_history_nonuser_message', give_output_error($message, false), $message);
46 46
 	}
47 47
 }
48 48
 
49
-add_shortcode( 'donation_history', 'give_donation_history' );
49
+add_shortcode('donation_history', 'give_donation_history');
50 50
 
51 51
 /**
52 52
  * Donation Form Shortcode
@@ -60,53 +60,53 @@  discard block
 block discarded – undo
60 60
  *
61 61
  * @return string
62 62
  */
63
-function give_form_shortcode( $atts, $content = null ) {
64
-	$atts = shortcode_atts( array(
63
+function give_form_shortcode($atts, $content = null) {
64
+	$atts = shortcode_atts(array(
65 65
 		'id'            => '',
66 66
 		'show_title'    => true,
67 67
 		'show_goal'     => true,
68 68
 		'show_content'  => '',
69 69
 		'float_labels'  => '',
70 70
 		'display_style' => '',
71
-	), $atts, 'give_form' );
71
+	), $atts, 'give_form');
72 72
 
73
-	foreach ( $atts as $key => $value ) {
73
+	foreach ($atts as $key => $value) {
74 74
 		//convert shortcode_atts values to booleans
75
-		if ( $key == 'show_title' ) {
76
-			$atts[ $key ] = filter_var( $atts[ $key ], FILTER_VALIDATE_BOOLEAN );
77
-		} elseif ( $key == 'show_goal' ) {
78
-			$atts[ $key ] = filter_var( $atts[ $key ], FILTER_VALIDATE_BOOLEAN );
75
+		if ($key == 'show_title') {
76
+			$atts[$key] = filter_var($atts[$key], FILTER_VALIDATE_BOOLEAN);
77
+		} elseif ($key == 'show_goal') {
78
+			$atts[$key] = filter_var($atts[$key], FILTER_VALIDATE_BOOLEAN);
79 79
 		}
80 80
 
81 81
 		//validate show_content value
82
-		if ( $key == 'show_content' ) {
83
-			if ( ! in_array( $value, array( 'none', 'above', 'below' ) ) ) {
84
-				$atts[ $key ] = '';
85
-			} else if ( $value == 'above' ) {
86
-				$atts[ $key ] = 'give_pre_form';
87
-			} else if ( $value == 'below' ) {
88
-				$atts[ $key ] = 'give_post_form';
82
+		if ($key == 'show_content') {
83
+			if ( ! in_array($value, array('none', 'above', 'below'))) {
84
+				$atts[$key] = '';
85
+			} else if ($value == 'above') {
86
+				$atts[$key] = 'give_pre_form';
87
+			} else if ($value == 'below') {
88
+				$atts[$key] = 'give_post_form';
89 89
 			}
90 90
 		}
91 91
 
92 92
 		//validate display_style and float_labels value
93
-		if ( ( $key == 'display_style' && ! in_array( $value, array( 'onpage', 'reveal', 'modal' ) ) )
94
-		     || ( $key == 'float_labels' && ! in_array( $value, array( 'enabled', 'disabled' ) ) )
93
+		if (($key == 'display_style' && ! in_array($value, array('onpage', 'reveal', 'modal')))
94
+		     || ($key == 'float_labels' && ! in_array($value, array('enabled', 'disabled')))
95 95
 		) {
96 96
 
97
-			$atts[ $key ] = '';
97
+			$atts[$key] = '';
98 98
 		}
99 99
 	}
100 100
 
101 101
 	//get the Give Form
102 102
 	ob_start();
103
-	give_get_donation_form( $atts );
103
+	give_get_donation_form($atts);
104 104
 	$final_output = ob_get_clean();
105 105
 
106
-	return apply_filters( 'give_donate_form', $final_output, $atts );
106
+	return apply_filters('give_donate_form', $final_output, $atts);
107 107
 }
108 108
 
109
-add_shortcode( 'give_form', 'give_form_shortcode' );
109
+add_shortcode('give_form', 'give_form_shortcode');
110 110
 
111 111
 /**
112 112
  * Donation Form Goal Shortcode
@@ -120,37 +120,37 @@  discard block
 block discarded – undo
120 120
  *
121 121
  * @return string
122 122
  */
123
-function give_goal_shortcode( $atts, $content = null ) {
124
-	$atts = shortcode_atts( array(
123
+function give_goal_shortcode($atts, $content = null) {
124
+	$atts = shortcode_atts(array(
125 125
 		'id'        => '',
126 126
 		'show_text' => true,
127 127
 		'show_bar'  => true,
128
-	), $atts, 'give_goal' );
128
+	), $atts, 'give_goal');
129 129
 
130 130
 
131 131
 	//get the Give Form
132 132
 	ob_start();
133 133
 
134 134
 	//Sanity check 1: ensure there is an ID Provided
135
-	if ( empty( $atts['id'] ) ) {
136
-		give_output_error( __( 'Error: No Donation form ID for the shortcode provided.', 'give' ), true );
135
+	if (empty($atts['id'])) {
136
+		give_output_error(__('Error: No Donation form ID for the shortcode provided.', 'give'), true);
137 137
 	}
138 138
 
139 139
 	//Sanity check 2: Check that this form even has Goals enabled
140
-	$goal_option = get_post_meta( $atts['id'], '_give_goal_option', true );
141
-	if ( empty( $goal_option ) || $goal_option !== 'yes' ) {
142
-		give_output_error( __( 'Error: This form does not have Goals enabled.', 'give' ), true );
140
+	$goal_option = get_post_meta($atts['id'], '_give_goal_option', true);
141
+	if (empty($goal_option) || $goal_option !== 'yes') {
142
+		give_output_error(__('Error: This form does not have Goals enabled.', 'give'), true);
143 143
 	} else {
144 144
 		//Passed all sanity checks: output Goal
145
-		give_show_goal_progress( $atts['id'], $atts );
145
+		give_show_goal_progress($atts['id'], $atts);
146 146
 	}
147 147
 
148 148
 	$final_output = ob_get_clean();
149 149
 
150
-	return apply_filters( 'give_goal_shortcode_output', $final_output, $atts );
150
+	return apply_filters('give_goal_shortcode_output', $final_output, $atts);
151 151
 }
152 152
 
153
-add_shortcode( 'give_goal', 'give_goal_shortcode' );
153
+add_shortcode('give_goal', 'give_goal_shortcode');
154 154
 
155 155
 
156 156
 /**
@@ -167,15 +167,15 @@  discard block
 block discarded – undo
167 167
  * @uses  give_login_form()
168 168
  * @return string
169 169
  */
170
-function give_login_form_shortcode( $atts, $content = null ) {
171
-	$atts = shortcode_atts( array(
170
+function give_login_form_shortcode($atts, $content = null) {
171
+	$atts = shortcode_atts(array(
172 172
 		'redirect' => '',
173
-	), $atts, 'give_login' );
173
+	), $atts, 'give_login');
174 174
 
175
-	return give_login_form( $atts['redirect'] );
175
+	return give_login_form($atts['redirect']);
176 176
 }
177 177
 
178
-add_shortcode( 'give_login', 'give_login_form_shortcode' );
178
+add_shortcode('give_login', 'give_login_form_shortcode');
179 179
 
180 180
 /**
181 181
  * Register Shortcode
@@ -190,15 +190,15 @@  discard block
 block discarded – undo
190 190
  * @uses  give_register_form()
191 191
  * @return string
192 192
  */
193
-function give_register_form_shortcode( $atts, $content = null ) {
194
-	$atts = shortcode_atts( array(
193
+function give_register_form_shortcode($atts, $content = null) {
194
+	$atts = shortcode_atts(array(
195 195
 		'redirect' => '',
196
-	), $atts, 'give_register' );
196
+	), $atts, 'give_register');
197 197
 
198
-	return give_register_form( $atts['redirect'] );
198
+	return give_register_form($atts['redirect']);
199 199
 }
200 200
 
201
-add_shortcode( 'give_register', 'give_register_form_shortcode' );
201
+add_shortcode('give_register', 'give_register_form_shortcode');
202 202
 
203 203
 
204 204
 /**
@@ -213,61 +213,61 @@  discard block
 block discarded – undo
213 213
  *
214 214
  * @return string
215 215
  */
216
-function give_receipt_shortcode( $atts, $content = null ) {
216
+function give_receipt_shortcode($atts, $content = null) {
217 217
 
218 218
 	global $give_receipt_args, $payment;
219 219
 
220
-	$give_receipt_args = shortcode_atts( array(
221
-		'error'          => esc_html__( 'Sorry, you are missing the payment key to view this donation receipt.', 'give' ),
220
+	$give_receipt_args = shortcode_atts(array(
221
+		'error'          => esc_html__('Sorry, you are missing the payment key to view this donation receipt.', 'give'),
222 222
 		'price'          => true,
223 223
 		'date'           => true,
224 224
 		'payment_key'    => false,
225 225
 		'payment_method' => true,
226 226
 		'payment_id'     => true
227
-	), $atts, 'give_receipt' );
227
+	), $atts, 'give_receipt');
228 228
 
229 229
 	//set $session var
230 230
 	$session = give_get_purchase_session();
231 231
 
232 232
 	//set payment key var
233
-	if ( isset( $_GET['payment_key'] ) ) {
234
-		$payment_key = urldecode( $_GET['payment_key'] );
235
-	} elseif ( $session ) {
233
+	if (isset($_GET['payment_key'])) {
234
+		$payment_key = urldecode($_GET['payment_key']);
235
+	} elseif ($session) {
236 236
 		$payment_key = $session['purchase_key'];
237
-	} elseif ( $give_receipt_args['payment_key'] ) {
237
+	} elseif ($give_receipt_args['payment_key']) {
238 238
 		$payment_key = $give_receipt_args['payment_key'];
239 239
 	}
240 240
 
241
-	$email_access = give_get_option( 'email_access' );
241
+	$email_access = give_get_option('email_access');
242 242
 
243 243
 	// No payment_key found & Email Access is Turned on:
244
-	if ( ! isset( $payment_key ) && $email_access == 'on' && ! Give()->email_access->token_exists ) {
244
+	if ( ! isset($payment_key) && $email_access == 'on' && ! Give()->email_access->token_exists) {
245 245
 
246 246
 		ob_start();
247 247
 
248
-		give_get_template_part( 'email-login-form' );
248
+		give_get_template_part('email-login-form');
249 249
 
250 250
 		return ob_get_clean();
251 251
 
252
-	} elseif ( ! isset( $payment_key ) ) {
252
+	} elseif ( ! isset($payment_key)) {
253 253
 
254
-		return give_output_error( $give_receipt_args['error'], false, 'error' );
254
+		return give_output_error($give_receipt_args['error'], false, 'error');
255 255
 
256 256
 	}
257 257
 
258
-	$payment_id    = give_get_purchase_id_by_key( $payment_key );
259
-	$user_can_view = give_can_view_receipt( $payment_key );
258
+	$payment_id    = give_get_purchase_id_by_key($payment_key);
259
+	$user_can_view = give_can_view_receipt($payment_key);
260 260
 
261 261
 	// Key was provided, but user is logged out. Offer them the ability to login and view the receipt
262
-	if ( ! $user_can_view && $email_access == 'on' && ! Give()->email_access->token_exists ) {
262
+	if ( ! $user_can_view && $email_access == 'on' && ! Give()->email_access->token_exists) {
263 263
 
264 264
 		ob_start();
265 265
 
266
-		give_get_template_part( 'email-login-form' );
266
+		give_get_template_part('email-login-form');
267 267
 
268 268
 		return ob_get_clean();
269 269
 
270
-	} elseif ( ! $user_can_view ) {
270
+	} elseif ( ! $user_can_view) {
271 271
 
272 272
 		global $give_login_redirect;
273 273
 
@@ -275,9 +275,9 @@  discard block
 block discarded – undo
275 275
 
276 276
 		ob_start();
277 277
 
278
-		give_output_error( apply_filters( 'give_must_be_logged_in_error_message', esc_html__( 'You must be logged in to view this donation payment receipt.', 'give' ) ) );
278
+		give_output_error(apply_filters('give_must_be_logged_in_error_message', esc_html__('You must be logged in to view this donation payment receipt.', 'give')));
279 279
 
280
-		give_get_template_part( 'shortcode', 'login' );
280
+		give_get_template_part('shortcode', 'login');
281 281
 
282 282
 		$login_form = ob_get_clean();
283 283
 
@@ -294,13 +294,13 @@  discard block
 block discarded – undo
294 294
 	 * Or if user is logged in and the user can view sensitive shop data
295 295
 	 *
296 296
 	 */
297
-	if ( ! apply_filters( 'give_user_can_view_receipt', $user_can_view, $give_receipt_args ) ) {
298
-		return give_output_error( $give_receipt_args['error'], false, 'error' );
297
+	if ( ! apply_filters('give_user_can_view_receipt', $user_can_view, $give_receipt_args)) {
298
+		return give_output_error($give_receipt_args['error'], false, 'error');
299 299
 	}
300 300
 
301 301
 	ob_start();
302 302
 
303
-	give_get_template_part( 'shortcode', 'receipt' );
303
+	give_get_template_part('shortcode', 'receipt');
304 304
 
305 305
 	$display = ob_get_clean();
306 306
 
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 
310 310
 }
311 311
 
312
-add_shortcode( 'give_receipt', 'give_receipt_shortcode' );
312
+add_shortcode('give_receipt', 'give_receipt_shortcode');
313 313
 
314 314
 /**
315 315
  * Profile Editor Shortcode
@@ -329,18 +329,18 @@  discard block
 block discarded – undo
329 329
  *
330 330
  * @return string Output generated from the profile editor
331 331
  */
332
-function give_profile_editor_shortcode( $atts, $content = null ) {
332
+function give_profile_editor_shortcode($atts, $content = null) {
333 333
 
334 334
 	ob_start();
335 335
 
336
-	give_get_template_part( 'shortcode', 'profile-editor' );
336
+	give_get_template_part('shortcode', 'profile-editor');
337 337
 
338 338
 	$display = ob_get_clean();
339 339
 
340 340
 	return $display;
341 341
 }
342 342
 
343
-add_shortcode( 'give_profile_editor', 'give_profile_editor_shortcode' );
343
+add_shortcode('give_profile_editor', 'give_profile_editor_shortcode');
344 344
 
345 345
 /**
346 346
  * Process Profile Updater Form
@@ -353,30 +353,30 @@  discard block
 block discarded – undo
353 353
  *
354 354
  * @return false
355 355
  */
356
-function give_process_profile_editor_updates( $data ) {
356
+function give_process_profile_editor_updates($data) {
357 357
 	// Profile field change request
358
-	if ( empty( $_POST['give_profile_editor_submit'] ) && ! is_user_logged_in() ) {
358
+	if (empty($_POST['give_profile_editor_submit']) && ! is_user_logged_in()) {
359 359
 		return false;
360 360
 	}
361 361
 
362 362
 	// Nonce security
363
-	if ( ! wp_verify_nonce( $data['give_profile_editor_nonce'], 'give-profile-editor-nonce' ) ) {
363
+	if ( ! wp_verify_nonce($data['give_profile_editor_nonce'], 'give-profile-editor-nonce')) {
364 364
 		return false;
365 365
 	}
366 366
 
367 367
 	$user_id       = get_current_user_id();
368
-	$old_user_data = get_userdata( $user_id );
369
-
370
-	$display_name = isset( $data['give_display_name'] ) ? sanitize_text_field( $data['give_display_name'] ) : $old_user_data->display_name;
371
-	$first_name   = isset( $data['give_first_name'] ) ? sanitize_text_field( $data['give_first_name'] ) : $old_user_data->first_name;
372
-	$last_name    = isset( $data['give_last_name'] ) ? sanitize_text_field( $data['give_last_name'] ) : $old_user_data->last_name;
373
-	$email        = isset( $data['give_email'] ) ? sanitize_email( $data['give_email'] ) : $old_user_data->user_email;
374
-	$line1        = ( isset( $data['give_address_line1'] ) ? sanitize_text_field( $data['give_address_line1'] ) : '' );
375
-	$line2        = ( isset( $data['give_address_line2'] ) ? sanitize_text_field( $data['give_address_line2'] ) : '' );
376
-	$city         = ( isset( $data['give_address_city'] ) ? sanitize_text_field( $data['give_address_city'] ) : '' );
377
-	$state        = ( isset( $data['give_address_state'] ) ? sanitize_text_field( $data['give_address_state'] ) : '' );
378
-	$zip          = ( isset( $data['give_address_zip'] ) ? sanitize_text_field( $data['give_address_zip'] ) : '' );
379
-	$country      = ( isset( $data['give_address_country'] ) ? sanitize_text_field( $data['give_address_country'] ) : '' );
368
+	$old_user_data = get_userdata($user_id);
369
+
370
+	$display_name = isset($data['give_display_name']) ? sanitize_text_field($data['give_display_name']) : $old_user_data->display_name;
371
+	$first_name   = isset($data['give_first_name']) ? sanitize_text_field($data['give_first_name']) : $old_user_data->first_name;
372
+	$last_name    = isset($data['give_last_name']) ? sanitize_text_field($data['give_last_name']) : $old_user_data->last_name;
373
+	$email        = isset($data['give_email']) ? sanitize_email($data['give_email']) : $old_user_data->user_email;
374
+	$line1        = (isset($data['give_address_line1']) ? sanitize_text_field($data['give_address_line1']) : '');
375
+	$line2        = (isset($data['give_address_line2']) ? sanitize_text_field($data['give_address_line2']) : '');
376
+	$city         = (isset($data['give_address_city']) ? sanitize_text_field($data['give_address_city']) : '');
377
+	$state        = (isset($data['give_address_state']) ? sanitize_text_field($data['give_address_state']) : '');
378
+	$zip          = (isset($data['give_address_zip']) ? sanitize_text_field($data['give_address_zip']) : '');
379
+	$country      = (isset($data['give_address_country']) ? sanitize_text_field($data['give_address_country']) : '');
380 380
 
381 381
 	$userdata = array(
382 382
 		'ID'           => $user_id,
@@ -396,45 +396,45 @@  discard block
 block discarded – undo
396 396
 		'country' => $country
397 397
 	);
398 398
 
399
-	do_action( 'give_pre_update_user_profile', $user_id, $userdata );
399
+	do_action('give_pre_update_user_profile', $user_id, $userdata);
400 400
 
401 401
 	// New password
402
-	if ( ! empty( $data['give_new_user_pass1'] ) ) {
403
-		if ( $data['give_new_user_pass1'] !== $data['give_new_user_pass2'] ) {
404
-			give_set_error( 'password_mismatch', __( 'The passwords you entered do not match. Please try again.', 'give' ) );
402
+	if ( ! empty($data['give_new_user_pass1'])) {
403
+		if ($data['give_new_user_pass1'] !== $data['give_new_user_pass2']) {
404
+			give_set_error('password_mismatch', __('The passwords you entered do not match. Please try again.', 'give'));
405 405
 		} else {
406 406
 			$userdata['user_pass'] = $data['give_new_user_pass1'];
407 407
 		}
408 408
 	}
409 409
 
410 410
 	// Make sure the new email doesn't belong to another user
411
-	if ( $email != $old_user_data->user_email ) {
412
-		if ( email_exists( $email ) ) {
413
-			give_set_error( 'email_exists', __( 'The email you entered belongs to another user. Please use another.', 'give' ) );
411
+	if ($email != $old_user_data->user_email) {
412
+		if (email_exists($email)) {
413
+			give_set_error('email_exists', __('The email you entered belongs to another user. Please use another.', 'give'));
414 414
 		}
415 415
 	}
416 416
 
417 417
 	// Check for errors
418 418
 	$errors = give_get_errors();
419 419
 
420
-	if ( $errors ) {
420
+	if ($errors) {
421 421
 		// Send back to the profile editor if there are errors
422
-		wp_redirect( $data['give_redirect'] );
422
+		wp_redirect($data['give_redirect']);
423 423
 		give_die();
424 424
 	}
425 425
 
426 426
 	// Update the user
427
-	$meta    = update_user_meta( $user_id, '_give_user_address', $address );
428
-	$updated = wp_update_user( $userdata );
427
+	$meta    = update_user_meta($user_id, '_give_user_address', $address);
428
+	$updated = wp_update_user($userdata);
429 429
 
430
-	if ( $updated ) {
431
-		do_action( 'give_user_profile_updated', $user_id, $userdata );
432
-		wp_redirect( add_query_arg( 'updated', 'true', $data['give_redirect'] ) );
430
+	if ($updated) {
431
+		do_action('give_user_profile_updated', $user_id, $userdata);
432
+		wp_redirect(add_query_arg('updated', 'true', $data['give_redirect']));
433 433
 		give_die();
434 434
 	}
435 435
 
436 436
 	return false;
437 437
 }
438 438
 
439
-add_action( 'give_edit_user_profile', 'give_process_profile_editor_updates' );
439
+add_action('give_edit_user_profile', 'give_process_profile_editor_updates');
440 440
 
Please login to merge, or discard this patch.