Completed
Pull Request — master (#1842)
by Ravinder
19:10
created
includes/emails/class-give-email-tags.php 1 patch
Spacing   +105 added lines, -105 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
 
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 	 * @param string   $description Email tag description text
56 56
 	 * @param callable $func        Hook to run when email tag is found
57 57
 	 */
58
-	public function add( $tag, $description, $func ) {
59
-		if ( is_callable( $func ) ) {
60
-			$this->tags[ $tag ] = array(
58
+	public function add($tag, $description, $func) {
59
+		if (is_callable($func)) {
60
+			$this->tags[$tag] = array(
61 61
 				'tag'         => $tag,
62 62
 				'description' => $description,
63 63
 				'func'        => $func
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @param string $tag Email tag to remove hook from
74 74
 	 */
75
-	public function remove( $tag ) {
76
-		unset( $this->tags[ $tag ] );
75
+	public function remove($tag) {
76
+		unset($this->tags[$tag]);
77 77
 	}
78 78
 
79 79
 	/**
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
 	 *
86 86
 	 * @return bool
87 87
 	 */
88
-	public function email_tag_exists( $tag ) {
89
-		return array_key_exists( $tag, $this->tags );
88
+	public function email_tag_exists($tag) {
89
+		return array_key_exists($tag, $this->tags);
90 90
 	}
91 91
 
92 92
 	/**
@@ -110,16 +110,16 @@  discard block
 block discarded – undo
110 110
 	 *
111 111
 	 * @return string Content with email tags filtered out.
112 112
 	 */
113
-	public function do_tags( $content, $payment_id ) {
113
+	public function do_tags($content, $payment_id) {
114 114
 
115 115
 		// Check if there is at least one tag added.
116
-		if ( empty( $this->tags ) || ! is_array( $this->tags ) ) {
116
+		if (empty($this->tags) || ! is_array($this->tags)) {
117 117
 			return $content;
118 118
 		}
119 119
 
120 120
 		$this->payment_id = $payment_id;
121 121
 
122
-		$new_content = preg_replace_callback( "/{([A-z0-9\-\_]+)}/s", array( $this, 'do_tag' ), $content );
122
+		$new_content = preg_replace_callback("/{([A-z0-9\-\_]+)}/s", array($this, 'do_tag'), $content);
123 123
 
124 124
 		$this->payment_id = null;
125 125
 
@@ -135,17 +135,17 @@  discard block
 block discarded – undo
135 135
 	 *
136 136
 	 * @return mixed
137 137
 	 */
138
-	public function do_tag( $m ) {
138
+	public function do_tag($m) {
139 139
 
140 140
 		// Get tag
141 141
 		$tag = $m[1];
142 142
 
143 143
 		// Return tag if tag not set
144
-		if ( ! $this->email_tag_exists( $tag ) ) {
144
+		if ( ! $this->email_tag_exists($tag)) {
145 145
 			return $m[0];
146 146
 		}
147 147
 
148
-		return call_user_func( $this->tags[ $tag ]['func'], $this->payment_id, $tag );
148
+		return call_user_func($this->tags[$tag]['func'], $this->payment_id, $tag);
149 149
 	}
150 150
 
151 151
 }
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
  * @param string   $description Description of the email tag added
160 160
  * @param callable $func        Hook to run when email tag is found
161 161
  */
162
-function give_add_email_tag( $tag, $description, $func ) {
163
-	Give()->email_tags->add( $tag, $description, $func );
162
+function give_add_email_tag($tag, $description, $func) {
163
+	Give()->email_tags->add($tag, $description, $func);
164 164
 }
165 165
 
166 166
 /**
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
  *
171 171
  * @param string $tag Email tag to remove hook from
172 172
  */
173
-function give_remove_email_tag( $tag ) {
174
-	Give()->email_tags->remove( $tag );
173
+function give_remove_email_tag($tag) {
174
+	Give()->email_tags->remove($tag);
175 175
 }
176 176
 
177 177
 /**
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
  *
184 184
  * @return bool
185 185
  */
186
-function give_email_tag_exists( $tag ) {
187
-	return Give()->email_tags->email_tag_exists( $tag );
186
+function give_email_tag_exists($tag) {
187
+	return Give()->email_tags->email_tag_exists($tag);
188 188
 }
189 189
 
190 190
 /**
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
 	$email_tags = give_get_email_tags();
212 212
 
213 213
 	ob_start();
214
-	if ( count( $email_tags ) > 0 ) : ?>
214
+	if (count($email_tags) > 0) : ?>
215 215
 		<div class="give-email-tags-wrap">
216
-			<?php foreach ( $email_tags as $email_tag ) : ?>
216
+			<?php foreach ($email_tags as $email_tag) : ?>
217 217
 				<span class="give_<?php echo $email_tag['tag']; ?>_tag">
218 218
 					<code>{<?php echo $email_tag['tag']; ?>}</code> - <?php echo $email_tag['description']; ?>
219 219
 				</span>
@@ -235,12 +235,12 @@  discard block
 block discarded – undo
235 235
  *
236 236
  * @return string Content with email tags filtered out.
237 237
  */
238
-function give_do_email_tags( $content, $payment_id ) {
238
+function give_do_email_tags($content, $payment_id) {
239 239
 
240 240
 	// Replace all tags
241
-	$content = Give()->email_tags->do_tags( $content, $payment_id );
241
+	$content = Give()->email_tags->do_tags($content, $payment_id);
242 242
 
243
-	$content = apply_filters( 'give_email_template_tags', $content, give_get_payment_meta( $payment_id ), $payment_id );
243
+	$content = apply_filters('give_email_template_tags', $content, give_get_payment_meta($payment_id), $payment_id);
244 244
 
245 245
 	// Return content
246 246
 	return $content;
@@ -259,9 +259,9 @@  discard block
 block discarded – undo
259 259
 	 *
260 260
 	 * @since 1.0
261 261
 	 */
262
-	do_action( 'give_add_email_tags' );
262
+	do_action('give_add_email_tags');
263 263
 }
264
-add_action( 'init', 'give_load_email_tags', - 999 );
264
+add_action('init', 'give_load_email_tags', - 999);
265 265
 
266 266
 
267 267
 /**
@@ -275,97 +275,97 @@  discard block
 block discarded – undo
275 275
 	$email_tags = array(
276 276
 		array(
277 277
 			'tag'         => 'donation',
278
-			'description' => esc_html__( 'The donation form name, and the donation level (if applicable).', 'give' ),
278
+			'description' => esc_html__('The donation form name, and the donation level (if applicable).', 'give'),
279 279
 			'function'    => 'give_email_tag_donation'
280 280
 		),
281 281
 		array(
282 282
 			'tag'         => 'form_title',
283
-			'description' => esc_html__( 'The donation form name.', 'give' ),
283
+			'description' => esc_html__('The donation form name.', 'give'),
284 284
 			'function'    => 'give_email_tag_form_title'
285 285
 		),
286 286
 		array(
287 287
 			'tag'         => 'amount',
288
-			'description' => esc_html__( 'The total donation amount with currency sign.', 'give' ),
288
+			'description' => esc_html__('The total donation amount with currency sign.', 'give'),
289 289
 			'function'    => 'give_email_tag_amount'
290 290
 		),
291 291
 		array(
292 292
 			'tag'         => 'price',
293
-			'description' => esc_html__( 'The total donation amount with currency sign.', 'give' ),
293
+			'description' => esc_html__('The total donation amount with currency sign.', 'give'),
294 294
 			'function'    => 'give_email_tag_price'
295 295
 		),
296 296
 		array(
297 297
 			'tag'         => 'name',
298
-			'description' => esc_html__( 'The donor\'s first name.', 'give' ),
298
+			'description' => esc_html__('The donor\'s first name.', 'give'),
299 299
 			'function'    => 'give_email_tag_first_name'
300 300
 		),
301 301
 		array(
302 302
 			'tag'         => 'fullname',
303
-			'description' => esc_html__( 'The donor\'s full name, first and last.', 'give' ),
303
+			'description' => esc_html__('The donor\'s full name, first and last.', 'give'),
304 304
 			'function'    => 'give_email_tag_fullname'
305 305
 		),
306 306
 		array(
307 307
 			'tag'         => 'username',
308
-			'description' => esc_html__( 'The donor\'s user name on the site, if they registered an account.', 'give' ),
308
+			'description' => esc_html__('The donor\'s user name on the site, if they registered an account.', 'give'),
309 309
 			'function'    => 'give_email_tag_username'
310 310
 		),
311 311
 		array(
312 312
 			'tag'         => 'user_email',
313
-			'description' => esc_html__( 'The donor\'s email address.', 'give' ),
313
+			'description' => esc_html__('The donor\'s email address.', 'give'),
314 314
 			'function'    => 'give_email_tag_user_email'
315 315
 		),
316 316
 		array(
317 317
 			'tag'         => 'billing_address',
318
-			'description' => esc_html__( 'The donor\'s billing address.', 'give' ),
318
+			'description' => esc_html__('The donor\'s billing address.', 'give'),
319 319
 			'function'    => 'give_email_tag_billing_address'
320 320
 		),
321 321
 		array(
322 322
 			'tag'         => 'date',
323
-			'description' => esc_html__( 'The date of the donation.', 'give' ),
323
+			'description' => esc_html__('The date of the donation.', 'give'),
324 324
 			'function'    => 'give_email_tag_date'
325 325
 		),
326 326
 		array(
327 327
 			'tag'         => 'payment_id',
328
-			'description' => esc_html__( 'The unique ID number for this donation.', 'give' ),
328
+			'description' => esc_html__('The unique ID number for this donation.', 'give'),
329 329
 			'function'    => 'give_email_tag_payment_id'
330 330
 		),
331 331
 		array(
332 332
 			'tag'         => 'receipt_id',
333
-			'description' => esc_html__( 'The unique ID number for this donation receipt.', 'give' ),
333
+			'description' => esc_html__('The unique ID number for this donation receipt.', 'give'),
334 334
 			'function'    => 'give_email_tag_receipt_id'
335 335
 		),
336 336
 		array(
337 337
 			'tag'         => 'payment_method',
338
-			'description' => esc_html__( 'The method of payment used for this donation.', 'give' ),
338
+			'description' => esc_html__('The method of payment used for this donation.', 'give'),
339 339
 			'function'    => 'give_email_tag_payment_method'
340 340
 		),
341 341
 		array(
342 342
 			'tag'         => 'sitename',
343
-			'description' => esc_html__( 'The name of your site.', 'give' ),
343
+			'description' => esc_html__('The name of your site.', 'give'),
344 344
 			'function'    => 'give_email_tag_sitename'
345 345
 		),
346 346
 		array(
347 347
 			'tag'         => 'receipt_link',
348
-			'description' => esc_html__( 'The donation receipt direct link, to view the receipt on the website.', 'give' ),
348
+			'description' => esc_html__('The donation receipt direct link, to view the receipt on the website.', 'give'),
349 349
 			'function'    => 'give_email_tag_receipt_link'
350 350
 		),
351 351
 		array(
352 352
 			'tag'         => 'receipt_link_url',
353
-			'description' => esc_html__( 'The donation receipt direct URL, to view the receipt on the website.', 'give' ),
353
+			'description' => esc_html__('The donation receipt direct URL, to view the receipt on the website.', 'give'),
354 354
 			'function'    => 'give_email_tag_receipt_link_url'
355 355
 		),
356 356
 	);
357 357
 
358 358
 	// Apply give_email_tags filter
359
-	$email_tags = apply_filters( 'give_email_tags', $email_tags );
359
+	$email_tags = apply_filters('give_email_tags', $email_tags);
360 360
 
361 361
 	// Add email tags
362
-	foreach ( $email_tags as $email_tag ) {
363
-		give_add_email_tag( $email_tag['tag'], $email_tag['description'], $email_tag['function'] );
362
+	foreach ($email_tags as $email_tag) {
363
+		give_add_email_tag($email_tag['tag'], $email_tag['description'], $email_tag['function']);
364 364
 	}
365 365
 
366 366
 }
367 367
 
368
-add_action( 'give_add_email_tags', 'give_setup_email_tags' );
368
+add_action('give_add_email_tags', 'give_setup_email_tags');
369 369
 
370 370
 
371 371
 /**
@@ -377,15 +377,15 @@  discard block
 block discarded – undo
377 377
  *
378 378
  * @return string name
379 379
  */
380
-function give_email_tag_first_name( $payment_id ) {
381
-	$payment   = new Give_Payment( $payment_id );
380
+function give_email_tag_first_name($payment_id) {
381
+	$payment   = new Give_Payment($payment_id);
382 382
 	$user_info = $payment->user_info;
383 383
 
384
-	if ( empty( $user_info ) ) {
384
+	if (empty($user_info)) {
385 385
 		return '';
386 386
 	}
387 387
 
388
-	$email_name = give_get_email_names( $user_info );
388
+	$email_name = give_get_email_names($user_info);
389 389
 
390 390
 	return $email_name['name'];
391 391
 }
@@ -399,15 +399,15 @@  discard block
 block discarded – undo
399 399
  *
400 400
  * @return string fullname
401 401
  */
402
-function give_email_tag_fullname( $payment_id ) {
403
-	$payment   = new Give_Payment( $payment_id );
402
+function give_email_tag_fullname($payment_id) {
403
+	$payment   = new Give_Payment($payment_id);
404 404
 	$user_info = $payment->user_info;
405 405
 
406
-	if ( empty( $user_info ) ) {
406
+	if (empty($user_info)) {
407 407
 		return '';
408 408
 	}
409 409
 
410
-	$email_name = give_get_email_names( $user_info );
410
+	$email_name = give_get_email_names($user_info);
411 411
 
412 412
 	return $email_name['fullname'];
413 413
 }
@@ -421,15 +421,15 @@  discard block
 block discarded – undo
421 421
  *
422 422
  * @return string username.
423 423
  */
424
-function give_email_tag_username( $payment_id ) {
425
-	$payment   = new Give_Payment( $payment_id );
424
+function give_email_tag_username($payment_id) {
425
+	$payment   = new Give_Payment($payment_id);
426 426
 	$user_info = $payment->user_info;
427 427
 
428
-	if ( empty( $user_info ) ) {
428
+	if (empty($user_info)) {
429 429
 		return '';
430 430
 	}
431 431
 
432
-	$email_name = give_get_email_names( $user_info );
432
+	$email_name = give_get_email_names($user_info);
433 433
 
434 434
 	return $email_name['username'];
435 435
 }
@@ -443,8 +443,8 @@  discard block
 block discarded – undo
443 443
  *
444 444
  * @return string user_email
445 445
  */
446
-function give_email_tag_user_email( $payment_id ) {
447
-	$payment = new Give_Payment( $payment_id );
446
+function give_email_tag_user_email($payment_id) {
447
+	$payment = new Give_Payment($payment_id);
448 448
 
449 449
 	return $payment->email;
450 450
 }
@@ -458,9 +458,9 @@  discard block
 block discarded – undo
458 458
  *
459 459
  * @return string billing_address
460 460
  */
461
-function give_email_tag_billing_address( $payment_id ) {
462
-	$user_info    = give_get_payment_meta_user_info( $payment_id );
463
-	$user_address = ! empty( $user_info['address'] ) ? $user_info['address'] : array(
461
+function give_email_tag_billing_address($payment_id) {
462
+	$user_info    = give_get_payment_meta_user_info($payment_id);
463
+	$user_address = ! empty($user_info['address']) ? $user_info['address'] : array(
464 464
 		'line1'   => '',
465 465
 		'line2'   => '',
466 466
 		'city'    => '',
@@ -469,11 +469,11 @@  discard block
 block discarded – undo
469 469
 		'zip'     => ''
470 470
 	);
471 471
 
472
-	$return = $user_address['line1'] . "\n";
473
-	if ( ! empty( $user_address['line2'] ) ) {
474
-		$return .= $user_address['line2'] . "\n";
472
+	$return = $user_address['line1']."\n";
473
+	if ( ! empty($user_address['line2'])) {
474
+		$return .= $user_address['line2']."\n";
475 475
 	}
476
-	$return .= $user_address['city'] . ' ' . $user_address['zip'] . ' ' . $user_address['state'] . "\n";
476
+	$return .= $user_address['city'].' '.$user_address['zip'].' '.$user_address['state']."\n";
477 477
 	$return .= $user_address['country'];
478 478
 
479 479
 	return $return;
@@ -488,10 +488,10 @@  discard block
 block discarded – undo
488 488
  *
489 489
  * @return string date
490 490
  */
491
-function give_email_tag_date( $payment_id ) {
492
-	$payment = new Give_Payment( $payment_id );
491
+function give_email_tag_date($payment_id) {
492
+	$payment = new Give_Payment($payment_id);
493 493
 
494
-	return date_i18n( give_date_format(), strtotime( $payment->date ) );
494
+	return date_i18n(give_date_format(), strtotime($payment->date));
495 495
 }
496 496
 
497 497
 /**
@@ -503,11 +503,11 @@  discard block
 block discarded – undo
503 503
  *
504 504
  * @return string amount
505 505
  */
506
-function give_email_tag_amount( $payment_id ) {
507
-	$payment     = new Give_Payment( $payment_id );
508
-	$give_amount = give_currency_filter( give_format_amount( $payment->total ), $payment->currency );
506
+function give_email_tag_amount($payment_id) {
507
+	$payment     = new Give_Payment($payment_id);
508
+	$give_amount = give_currency_filter(give_format_amount($payment->total), $payment->currency);
509 509
 
510
-	return html_entity_decode( $give_amount, ENT_COMPAT, 'UTF-8' );
510
+	return html_entity_decode($give_amount, ENT_COMPAT, 'UTF-8');
511 511
 }
512 512
 
513 513
 /**
@@ -519,8 +519,8 @@  discard block
 block discarded – undo
519 519
  *
520 520
  * @return string price
521 521
  */
522
-function give_email_tag_price( $payment_id ) {
523
-	return give_email_tag_amount( $payment_id );
522
+function give_email_tag_price($payment_id) {
523
+	return give_email_tag_amount($payment_id);
524 524
 }
525 525
 
526 526
 /**
@@ -532,8 +532,8 @@  discard block
 block discarded – undo
532 532
  *
533 533
  * @return int payment_id
534 534
  */
535
-function give_email_tag_payment_id( $payment_id ) {
536
-	$payment = new Give_Payment( $payment_id );
535
+function give_email_tag_payment_id($payment_id) {
536
+	$payment = new Give_Payment($payment_id);
537 537
 
538 538
 	return $payment->number;
539 539
 }
@@ -547,8 +547,8 @@  discard block
 block discarded – undo
547 547
  *
548 548
  * @return string receipt_id
549 549
  */
550
-function give_email_tag_receipt_id( $payment_id ) {
551
-	$payment = new Give_Payment( $payment_id );
550
+function give_email_tag_receipt_id($payment_id) {
551
+	$payment = new Give_Payment($payment_id);
552 552
 
553 553
 	return $payment->key;
554 554
 }
@@ -562,14 +562,14 @@  discard block
 block discarded – undo
562 562
  *
563 563
  * @return string $form_title
564 564
  */
565
-function give_email_tag_donation( $payment_id ) {
566
-	$payment      = new Give_Payment( $payment_id );
565
+function give_email_tag_donation($payment_id) {
566
+	$payment      = new Give_Payment($payment_id);
567 567
 	$payment_meta = $payment->payment_meta;
568
-	$level_title  = give_has_variable_prices( $payment->form_id );
568
+	$level_title  = give_has_variable_prices($payment->form_id);
569 569
 	$separator    = $level_title ? '-' : '';
570
-	$form_title   = strip_tags( give_get_payment_form_title( $payment_meta, false, $separator ) );
570
+	$form_title   = strip_tags(give_get_payment_form_title($payment_meta, false, $separator));
571 571
 
572
-	return ! empty( $form_title ) ? $form_title : '';
572
+	return ! empty($form_title) ? $form_title : '';
573 573
 
574 574
 }
575 575
 
@@ -582,11 +582,11 @@  discard block
 block discarded – undo
582 582
  *
583 583
  * @return string $form_title
584 584
  */
585
-function give_email_tag_form_title( $payment_id ) {
586
-	$payment      = new Give_Payment( $payment_id );
585
+function give_email_tag_form_title($payment_id) {
586
+	$payment      = new Give_Payment($payment_id);
587 587
 	$payment_meta = $payment->payment_meta;
588 588
 
589
-	return isset( $payment_meta['form_title'] ) ? strip_tags( $payment_meta['form_title'] ) : '';
589
+	return isset($payment_meta['form_title']) ? strip_tags($payment_meta['form_title']) : '';
590 590
 
591 591
 }
592 592
 
@@ -599,10 +599,10 @@  discard block
 block discarded – undo
599 599
  *
600 600
  * @return string gateway
601 601
  */
602
-function give_email_tag_payment_method( $payment_id ) {
603
-	$payment = new Give_Payment( $payment_id );
602
+function give_email_tag_payment_method($payment_id) {
603
+	$payment = new Give_Payment($payment_id);
604 604
 
605
-	return give_get_gateway_checkout_label( $payment->gateway );
605
+	return give_get_gateway_checkout_label($payment->gateway);
606 606
 }
607 607
 
608 608
 /**
@@ -614,8 +614,8 @@  discard block
 block discarded – undo
614 614
  *
615 615
  * @return string sitename
616 616
  */
617
-function give_email_tag_sitename( $payment_id ) {
618
-	return wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES );
617
+function give_email_tag_sitename($payment_id) {
618
+	return wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
619 619
 }
620 620
 
621 621
 /**
@@ -627,19 +627,19 @@  discard block
 block discarded – undo
627 627
  *
628 628
  * @return string receipt_link
629 629
  */
630
-function give_email_tag_receipt_link( $payment_id ) {
630
+function give_email_tag_receipt_link($payment_id) {
631 631
 
632
-	$receipt_url = esc_url( add_query_arg( array(
633
-		'payment_key' => give_get_payment_key( $payment_id ),
632
+	$receipt_url = esc_url(add_query_arg(array(
633
+		'payment_key' => give_get_payment_key($payment_id),
634 634
 		'give_action' => 'view_receipt'
635
-	), home_url() ) );
636
-	$formatted   = sprintf(
635
+	), home_url()));
636
+	$formatted = sprintf(
637 637
 		'<a href="%1$s">%2$s</a>',
638 638
 		$receipt_url,
639
-		esc_html__( 'View it in your browser', 'give' )
639
+		esc_html__('View it in your browser', 'give')
640 640
 	);
641 641
 
642
-	if ( give_get_option( 'email_template' ) !== 'none' ) {
642
+	if (give_get_option('email_template') !== 'none') {
643 643
 		return $formatted;
644 644
 	} else {
645 645
 		return $receipt_url;
@@ -658,12 +658,12 @@  discard block
 block discarded – undo
658 658
  *
659 659
  * @return string receipt_url
660 660
  */
661
-function give_email_tag_receipt_link_url( $payment_id ) {
661
+function give_email_tag_receipt_link_url($payment_id) {
662 662
 
663
-	$receipt_url = esc_url( add_query_arg( array(
664
-		'payment_key' => give_get_payment_key( $payment_id ),
663
+	$receipt_url = esc_url(add_query_arg(array(
664
+		'payment_key' => give_get_payment_key($payment_id),
665 665
 		'give_action' => 'view_receipt'
666
-	), home_url() ) );
666
+	), home_url()));
667 667
 
668 668
 	return $receipt_url;
669 669
 
Please login to merge, or discard this patch.