Completed
Push — master ( 0975de...93c517 )
by Devin
30:08 queued 10:08
created
includes/emails/class-give-email-tags.php 1 patch
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  */
24 24
 
25 25
 // Exit if accessed directly
26
-if ( ! defined( 'ABSPATH' ) ) {
26
+if ( ! defined('ABSPATH')) {
27 27
 	exit;
28 28
 }
29 29
 
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
 	 * @param string $tag Email tag to be replace in email
55 55
 	 * @param callable $func Hook to run when email tag is found
56 56
 	 */
57
-	public function add( $tag, $description, $func ) {
58
-		if ( is_callable( $func ) ) {
59
-			$this->tags[ $tag ] = array(
57
+	public function add($tag, $description, $func) {
58
+		if (is_callable($func)) {
59
+			$this->tags[$tag] = array(
60 60
 				'tag'         => $tag,
61 61
 				'description' => $description,
62 62
 				'func'        => $func
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
 	 *
72 72
 	 * @param string $tag Email tag to remove hook from
73 73
 	 */
74
-	public function remove( $tag ) {
75
-		unset( $this->tags[ $tag ] );
74
+	public function remove($tag) {
75
+		unset($this->tags[$tag]);
76 76
 	}
77 77
 
78 78
 	/**
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 	 *
85 85
 	 * @return bool
86 86
 	 */
87
-	public function email_tag_exists( $tag ) {
88
-		return array_key_exists( $tag, $this->tags );
87
+	public function email_tag_exists($tag) {
88
+		return array_key_exists($tag, $this->tags);
89 89
 	}
90 90
 
91 91
 	/**
@@ -109,16 +109,16 @@  discard block
 block discarded – undo
109 109
 	 *
110 110
 	 * @return string Content with email tags filtered out.
111 111
 	 */
112
-	public function do_tags( $content, $payment_id ) {
112
+	public function do_tags($content, $payment_id) {
113 113
 
114 114
 		// Check if there is atleast one tag added
115
-		if ( empty( $this->tags ) || ! is_array( $this->tags ) ) {
115
+		if (empty($this->tags) || ! is_array($this->tags)) {
116 116
 			return $content;
117 117
 		}
118 118
 
119 119
 		$this->payment_id = $payment_id;
120 120
 
121
-		$new_content = preg_replace_callback( "/{([A-z0-9\-\_]+)}/s", array( $this, 'do_tag' ), $content );
121
+		$new_content = preg_replace_callback("/{([A-z0-9\-\_]+)}/s", array($this, 'do_tag'), $content);
122 122
 
123 123
 		$this->payment_id = null;
124 124
 
@@ -134,17 +134,17 @@  discard block
 block discarded – undo
134 134
 	 *
135 135
 	 * @return mixed
136 136
 	 */
137
-	public function do_tag( $m ) {
137
+	public function do_tag($m) {
138 138
 
139 139
 		// Get tag
140 140
 		$tag = $m[1];
141 141
 
142 142
 		// Return tag if tag not set
143
-		if ( ! $this->email_tag_exists( $tag ) ) {
143
+		if ( ! $this->email_tag_exists($tag)) {
144 144
 			return $m[0];
145 145
 		}
146 146
 
147
-		return call_user_func( $this->tags[ $tag ]['func'], $this->payment_id, $tag );
147
+		return call_user_func($this->tags[$tag]['func'], $this->payment_id, $tag);
148 148
 	}
149 149
 
150 150
 }
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
  * @param string $description Description of the email tag added
159 159
  * @param callable $func Hook to run when email tag is found
160 160
  */
161
-function give_add_email_tag( $tag, $description, $func ) {
162
-	Give()->email_tags->add( $tag, $description, $func );
161
+function give_add_email_tag($tag, $description, $func) {
162
+	Give()->email_tags->add($tag, $description, $func);
163 163
 }
164 164
 
165 165
 /**
@@ -169,8 +169,8 @@  discard block
 block discarded – undo
169 169
  *
170 170
  * @param string $tag Email tag to remove hook from
171 171
  */
172
-function give_remove_email_tag( $tag ) {
173
-	Give()->email_tags->remove( $tag );
172
+function give_remove_email_tag($tag) {
173
+	Give()->email_tags->remove($tag);
174 174
 }
175 175
 
176 176
 /**
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
  *
183 183
  * @return bool
184 184
  */
185
-function give_email_tag_exists( $tag ) {
186
-	return Give()->email_tags->email_tag_exists( $tag );
185
+function give_email_tag_exists($tag) {
186
+	return Give()->email_tags->email_tag_exists($tag);
187 187
 }
188 188
 
189 189
 /**
@@ -212,13 +212,13 @@  discard block
 block discarded – undo
212 212
 	$email_tags = give_get_email_tags();
213 213
 
214 214
 	// Check
215
-	if ( count( $email_tags ) > 0 ) {
215
+	if (count($email_tags) > 0) {
216 216
 
217 217
 		// Loop
218
-		foreach ( $email_tags as $email_tag ) {
218
+		foreach ($email_tags as $email_tag) {
219 219
 
220 220
 			// Add email tag to list
221
-			$list .= '<code>{' . $email_tag['tag'] . '}</code> - ' . $email_tag['description'] . '<br/>';
221
+			$list .= '<code>{'.$email_tag['tag'].'}</code> - '.$email_tag['description'].'<br/>';
222 222
 
223 223
 		}
224 224
 
@@ -238,13 +238,13 @@  discard block
 block discarded – undo
238 238
  *
239 239
  * @return string Content with email tags filtered out.
240 240
  */
241
-function give_do_email_tags( $content, $payment_id ) {
241
+function give_do_email_tags($content, $payment_id) {
242 242
 
243 243
 	// Replace all tags
244
-	$content = Give()->email_tags->do_tags( $content, $payment_id );
244
+	$content = Give()->email_tags->do_tags($content, $payment_id);
245 245
 
246 246
 	// Maintaining backwards compatibility
247
-	$content = apply_filters( 'give_email_template_tags', $content, give_get_payment_meta( $payment_id ), $payment_id );
247
+	$content = apply_filters('give_email_template_tags', $content, give_get_payment_meta($payment_id), $payment_id);
248 248
 
249 249
 	// Return content
250 250
 	return $content;
@@ -256,10 +256,10 @@  discard block
 block discarded – undo
256 256
  * @since 1.0
257 257
  */
258 258
 function give_load_email_tags() {
259
-	do_action( 'give_add_email_tags' );
259
+	do_action('give_add_email_tags');
260 260
 }
261 261
 
262
-add_action( 'init', 'give_load_email_tags', - 999 );
262
+add_action('init', 'give_load_email_tags', - 999);
263 263
 
264 264
 /**
265 265
  * Add default Give email template tags.
@@ -272,82 +272,82 @@  discard block
 block discarded – undo
272 272
 	$email_tags = array(
273 273
 		array(
274 274
 			'tag'         => 'donation',
275
-			'description' => esc_html__( 'The donation form name, and the donation level (if applicable).', 'give' ),
275
+			'description' => esc_html__('The donation form name, and the donation level (if applicable).', 'give'),
276 276
 			'function'    => 'give_email_tag_donation'
277 277
 		),
278 278
 		array(
279 279
 			'tag'         => 'name',
280
-			'description' => esc_html__( 'The donor\'s first name.', 'give' ),
280
+			'description' => esc_html__('The donor\'s first name.', 'give'),
281 281
 			'function'    => 'give_email_tag_first_name'
282 282
 		),
283 283
 		array(
284 284
 			'tag'         => 'fullname',
285
-			'description' => esc_html__( 'The donor\'s full name, first and last.', 'give' ),
285
+			'description' => esc_html__('The donor\'s full name, first and last.', 'give'),
286 286
 			'function'    => 'give_email_tag_fullname'
287 287
 		),
288 288
 		array(
289 289
 			'tag'         => 'username',
290
-			'description' => esc_html__( 'The donor\'s user name on the site, if they registered an account.', 'give' ),
290
+			'description' => esc_html__('The donor\'s user name on the site, if they registered an account.', 'give'),
291 291
 			'function'    => 'give_email_tag_username'
292 292
 		),
293 293
 		array(
294 294
 			'tag'         => 'user_email',
295
-			'description' => esc_html__( 'The donor\'s email address.', 'give' ),
295
+			'description' => esc_html__('The donor\'s email address.', 'give'),
296 296
 			'function'    => 'give_email_tag_user_email'
297 297
 		),
298 298
 		array(
299 299
 			'tag'         => 'billing_address',
300
-			'description' => esc_html__( 'The donor\'s billing address.', 'give' ),
300
+			'description' => esc_html__('The donor\'s billing address.', 'give'),
301 301
 			'function'    => 'give_email_tag_billing_address'
302 302
 		),
303 303
 		array(
304 304
 			'tag'         => 'date',
305
-			'description' => esc_html__( 'The date of the donation.', 'give' ),
305
+			'description' => esc_html__('The date of the donation.', 'give'),
306 306
 			'function'    => 'give_email_tag_date'
307 307
 		),
308 308
 		array(
309 309
 			'tag'         => 'price',
310
-			'description' => esc_html__( 'The total price of the donation.', 'give' ),
310
+			'description' => esc_html__('The total price of the donation.', 'give'),
311 311
 			'function'    => 'give_email_tag_price'
312 312
 		),
313 313
 		array(
314 314
 			'tag'         => 'payment_id',
315
-			'description' => esc_html__( 'The unique ID number for this donation.', 'give' ),
315
+			'description' => esc_html__('The unique ID number for this donation.', 'give'),
316 316
 			'function'    => 'give_email_tag_payment_id'
317 317
 		),
318 318
 		array(
319 319
 			'tag'         => 'receipt_id',
320
-			'description' => esc_html__( 'The unique ID number for this donation receipt.', 'give' ),
320
+			'description' => esc_html__('The unique ID number for this donation receipt.', 'give'),
321 321
 			'function'    => 'give_email_tag_receipt_id'
322 322
 		),
323 323
 		array(
324 324
 			'tag'         => 'payment_method',
325
-			'description' => esc_html__( 'The method of payment used for this donation.', 'give' ),
325
+			'description' => esc_html__('The method of payment used for this donation.', 'give'),
326 326
 			'function'    => 'give_email_tag_payment_method'
327 327
 		),
328 328
 		array(
329 329
 			'tag'         => 'sitename',
330
-			'description' => esc_html__( 'Your site name', 'give' ),
330
+			'description' => esc_html__('Your site name', 'give'),
331 331
 			'function'    => 'give_email_tag_sitename'
332 332
 		),
333 333
 		array(
334 334
 			'tag'         => 'receipt_link',
335
-			'description' => esc_html__( 'Adds a link so users can view their receipt directly on your website if they are unable to view it in the browser correctly.', 'give' ),
335
+			'description' => esc_html__('Adds a link so users can view their receipt directly on your website if they are unable to view it in the browser correctly.', 'give'),
336 336
 			'function'    => 'give_email_tag_receipt_link'
337 337
 		),
338 338
 	);
339 339
 
340 340
 	// Apply give_email_tags filter
341
-	$email_tags = apply_filters( 'give_email_tags', $email_tags );
341
+	$email_tags = apply_filters('give_email_tags', $email_tags);
342 342
 
343 343
 	// Add email tags
344
-	foreach ( $email_tags as $email_tag ) {
345
-		give_add_email_tag( $email_tag['tag'], $email_tag['description'], $email_tag['function'] );
344
+	foreach ($email_tags as $email_tag) {
345
+		give_add_email_tag($email_tag['tag'], $email_tag['description'], $email_tag['function']);
346 346
 	}
347 347
 
348 348
 }
349 349
 
350
-add_action( 'give_add_email_tags', 'give_setup_email_tags' );
350
+add_action('give_add_email_tags', 'give_setup_email_tags');
351 351
 
352 352
 
353 353
 /**
@@ -359,15 +359,15 @@  discard block
 block discarded – undo
359 359
  *
360 360
  * @return string name
361 361
  */
362
-function give_email_tag_first_name( $payment_id ) {
363
-	$payment   = new Give_Payment( $payment_id );
362
+function give_email_tag_first_name($payment_id) {
363
+	$payment   = new Give_Payment($payment_id);
364 364
 	$user_info = $payment->user_info;
365 365
 
366
-	if ( empty( $user_info ) ) {
366
+	if (empty($user_info)) {
367 367
 		return '';
368 368
 	}
369 369
 
370
-	$email_name = give_get_email_names( $user_info );
370
+	$email_name = give_get_email_names($user_info);
371 371
 
372 372
 	return $email_name['name'];
373 373
 }
@@ -381,15 +381,15 @@  discard block
 block discarded – undo
381 381
  *
382 382
  * @return string fullname
383 383
  */
384
-function give_email_tag_fullname( $payment_id ) {
385
-	$payment   = new Give_Payment( $payment_id );
384
+function give_email_tag_fullname($payment_id) {
385
+	$payment   = new Give_Payment($payment_id);
386 386
 	$user_info = $payment->user_info;
387 387
 
388
-	if ( empty( $user_info ) ) {
388
+	if (empty($user_info)) {
389 389
 		return '';
390 390
 	}
391 391
 
392
-	$email_name = give_get_email_names( $user_info );
392
+	$email_name = give_get_email_names($user_info);
393 393
 
394 394
 	return $email_name['fullname'];
395 395
 }
@@ -402,15 +402,15 @@  discard block
 block discarded – undo
402 402
  *
403 403
  * @return string username.
404 404
  */
405
-function give_email_tag_username( $payment_id ) {
406
-	$payment   = new Give_Payment( $payment_id );
405
+function give_email_tag_username($payment_id) {
406
+	$payment   = new Give_Payment($payment_id);
407 407
 	$user_info = $payment->user_info;
408 408
 
409
-	if ( empty( $user_info ) ) {
409
+	if (empty($user_info)) {
410 410
 		return '';
411 411
 	}
412 412
 
413
-	$email_name = give_get_email_names( $user_info );
413
+	$email_name = give_get_email_names($user_info);
414 414
 
415 415
 	return $email_name['username'];
416 416
 }
@@ -423,8 +423,8 @@  discard block
 block discarded – undo
423 423
  *
424 424
  * @return string user_email
425 425
  */
426
-function give_email_tag_user_email( $payment_id ) {
427
-	$payment = new Give_Payment( $payment_id );
426
+function give_email_tag_user_email($payment_id) {
427
+	$payment = new Give_Payment($payment_id);
428 428
 
429 429
 	return $payment->email;
430 430
 }
@@ -437,10 +437,10 @@  discard block
 block discarded – undo
437 437
  *
438 438
  * @return string billing_address
439 439
  */
440
-function give_email_tag_billing_address( $payment_id ) {
440
+function give_email_tag_billing_address($payment_id) {
441 441
 
442
-	$user_info    = give_get_payment_meta_user_info( $payment_id );
443
-	$user_address = ! empty( $user_info['address'] ) ? $user_info['address'] : array(
442
+	$user_info    = give_get_payment_meta_user_info($payment_id);
443
+	$user_address = ! empty($user_info['address']) ? $user_info['address'] : array(
444 444
 		'line1'   => '',
445 445
 		'line2'   => '',
446 446
 		'city'    => '',
@@ -449,11 +449,11 @@  discard block
 block discarded – undo
449 449
 		'zip'     => ''
450 450
 	);
451 451
 
452
-	$return = $user_address['line1'] . "\n";
453
-	if ( ! empty( $user_address['line2'] ) ) {
454
-		$return .= $user_address['line2'] . "\n";
452
+	$return = $user_address['line1']."\n";
453
+	if ( ! empty($user_address['line2'])) {
454
+		$return .= $user_address['line2']."\n";
455 455
 	}
456
-	$return .= $user_address['city'] . ' ' . $user_address['zip'] . ' ' . $user_address['state'] . "\n";
456
+	$return .= $user_address['city'].' '.$user_address['zip'].' '.$user_address['state']."\n";
457 457
 	$return .= $user_address['country'];
458 458
 
459 459
 	return $return;
@@ -467,10 +467,10 @@  discard block
 block discarded – undo
467 467
  *
468 468
  * @return string date
469 469
  */
470
-function give_email_tag_date( $payment_id ) {
471
-	$payment = new Give_Payment( $payment_id );
470
+function give_email_tag_date($payment_id) {
471
+	$payment = new Give_Payment($payment_id);
472 472
 
473
-	return date_i18n( get_option( 'date_format' ), strtotime( $payment->date ) );
473
+	return date_i18n(get_option('date_format'), strtotime($payment->date));
474 474
 }
475 475
 
476 476
 /**
@@ -481,11 +481,11 @@  discard block
 block discarded – undo
481 481
  *
482 482
  * @return string price
483 483
  */
484
-function give_email_tag_price( $payment_id ) {
485
-	$payment = new Give_Payment( $payment_id );
486
-	$price   = give_currency_filter( give_format_amount( $payment->total ), $payment->currency );
484
+function give_email_tag_price($payment_id) {
485
+	$payment = new Give_Payment($payment_id);
486
+	$price   = give_currency_filter(give_format_amount($payment->total), $payment->currency);
487 487
 
488
-	return html_entity_decode( $price, ENT_COMPAT, 'UTF-8' );
488
+	return html_entity_decode($price, ENT_COMPAT, 'UTF-8');
489 489
 }
490 490
 
491 491
 /**
@@ -496,8 +496,8 @@  discard block
 block discarded – undo
496 496
  *
497 497
  * @return int payment_id
498 498
  */
499
-function give_email_tag_payment_id( $payment_id ) {
500
-	$payment = new Give_Payment( $payment_id );
499
+function give_email_tag_payment_id($payment_id) {
500
+	$payment = new Give_Payment($payment_id);
501 501
 
502 502
 	return $payment->number;
503 503
 }
@@ -510,8 +510,8 @@  discard block
 block discarded – undo
510 510
  *
511 511
  * @return string receipt_id
512 512
  */
513
-function give_email_tag_receipt_id( $payment_id ) {
514
-	$payment = new Give_Payment( $payment_id );
513
+function give_email_tag_receipt_id($payment_id) {
514
+	$payment = new Give_Payment($payment_id);
515 515
 
516 516
 	return $payment->key;
517 517
 }
@@ -525,14 +525,14 @@  discard block
 block discarded – undo
525 525
  *
526 526
  * @return string $form_title
527 527
  */
528
-function give_email_tag_donation( $payment_id ) {
529
-	$payment      = new Give_Payment( $payment_id );
528
+function give_email_tag_donation($payment_id) {
529
+	$payment      = new Give_Payment($payment_id);
530 530
 	$payment_meta = $payment->meta;
531
-	$level_title  = give_has_variable_prices( $payment_meta['form_id'] );
531
+	$level_title  = give_has_variable_prices($payment_meta['form_id']);
532 532
 	$separator    = $level_title ? '-' : '';
533
-	$form_title   = strip_tags( give_get_payment_form_title( $payment_meta, $level_title, $separator ) );
533
+	$form_title   = strip_tags(give_get_payment_form_title($payment_meta, $level_title, $separator));
534 534
 
535
-	return ! empty( $form_title ) ? $form_title : esc_html__( 'There was an error retrieving the donation form name.', 'give' );
535
+	return ! empty($form_title) ? $form_title : esc_html__('There was an error retrieving the donation form name.', 'give');
536 536
 
537 537
 }
538 538
 
@@ -545,10 +545,10 @@  discard block
 block discarded – undo
545 545
  *
546 546
  * @return string gateway
547 547
  */
548
-function give_email_tag_payment_method( $payment_id ) {
549
-	$payment = new Give_Payment( $payment_id );
548
+function give_email_tag_payment_method($payment_id) {
549
+	$payment = new Give_Payment($payment_id);
550 550
 
551
-	return give_get_gateway_checkout_label( $payment->gateway );
551
+	return give_get_gateway_checkout_label($payment->gateway);
552 552
 }
553 553
 
554 554
 /**
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
  *
561 561
  * @return string sitename
562 562
  */
563
-function give_email_tag_sitename( $payment_id ) {
564
-	return wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
563
+function give_email_tag_sitename($payment_id) {
564
+	return wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
565 565
 }
566 566
 
567 567
 /**
@@ -573,19 +573,19 @@  discard block
 block discarded – undo
573 573
  *
574 574
  * @return string receipt_link
575 575
  */
576
-function give_email_tag_receipt_link( $payment_id ) {
576
+function give_email_tag_receipt_link($payment_id) {
577 577
 
578
-	$receipt_url = esc_url( add_query_arg( array(
579
-		'payment_key' => give_get_payment_key( $payment_id ),
578
+	$receipt_url = esc_url(add_query_arg(array(
579
+		'payment_key' => give_get_payment_key($payment_id),
580 580
 		'give_action' => 'view_receipt'
581
-	), home_url() ) );
582
-	$formatted   = sprintf(
581
+	), home_url()));
582
+	$formatted = sprintf(
583 583
 		'<a href="%1$s">%2$s</a>',
584 584
 		$receipt_url,
585
-		esc_html__( 'View it in your browser', 'give' )
585
+		esc_html__('View it in your browser', 'give')
586 586
 	);
587 587
 
588
-	if ( give_get_option( 'email_template' ) !== 'none' ) {
588
+	if (give_get_option('email_template') !== 'none') {
589 589
 		return $formatted;
590 590
 	} else {
591 591
 		return $receipt_url;
Please login to merge, or discard this patch.