Test Failed
Push — feature/meta-tables ( 709186...4c8cbd )
by Ravinder
05:18
created

functions.php ➔ give_admin_notices_disabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Email Functions
4
 *
5
 * @package     Give
6
 * @subpackage  Emails
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Email Donation Receipt.
19
 *
20
 * Email the donation confirmation to the donor via the customizable "Donation Receipt" settings.
21
 *
22
 * @since 1.0
23
 *
24
 * @param int  $payment_id   Payment ID.
25
 * @param bool $admin_notice Whether to send the admin email notification or not (default: true).
26
 *
27
 * @return void
28
 */
29
function give_email_donation_receipt( $payment_id, $admin_notice = true ) {
30
	$payment = new Give_Payment( $payment_id );
31
	/**
32
	 * Fire the action
33
	 */
34
	do_action( 'give_donation-receipt_email_notification', $payment_id );
35
36
	//If admin notifications are on, send the admin notice.
37
	if ( $admin_notice && ! give_admin_notices_disabled( $payment_id ) ) {
0 ignored issues
show
Deprecated Code introduced by
The function give_admin_notices_disabled() has been deprecated with message: 2.0

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
38
		/**
39
		 * Fires in the donation email receipt.
40
		 *
41
		 * When admin email notices are not disabled, you can add new email notices.
42
		 *
43
		 * @since 1.0
44
		 *
45
		 * @param int   $payment_id   Payment id.
46
		 * @param mixed $payment_data Payment meta data.
47
		 */
48
		do_action( 'give_new-donation_email_notification', $payment_id, $payment->payment_meta );
49
	}
50
}
51
52
/**
53
 * Sends the Admin Sale Notification Email
54
 *
55
 * @since 1.0
56
 *
57
 * @param int $payment_id Payment ID (default: 0)
58
 *
59
 * @return void
60
 */
61
function give_admin_email_notice( $payment_id ) {
62
	/**
63
	 * Fires in the donation email receipt.
64
	 *
65
	 * When admin email notices are not disabled, you can add new email notices.
66
	 *
67
	 * @since 1.0
68
	 *
69
	 * @param int   $payment_id   Payment id.
70
	 * @param mixed $payment_data Payment meta data.
71
	 */
72
	do_action( 'give_new-donation_email_notification', $payment_id );
73
}
74
75
add_action( 'give_admin_donation_email', 'give_admin_email_notice' );
76
77
78
/**
79
 * Get default donation notification email text
80
 *
81
 * Returns the stored email text if available, the standard email text if not
82
 *
83
 * @since  1.0
84
 * @return string $message
85
 */
86
function give_get_default_donation_notification_email() {
87
88
	$default_email_body = esc_html__( 'Hi there,', 'give' ) . "\n\n";
89
	$default_email_body .= esc_html__( 'This email is to inform you that a new donation has been made on your website:', 'give' ) . ' <a href="' . get_bloginfo( 'url' ) . '" target="_blank">' . get_bloginfo( 'url' ) . '</a>' . ".\n\n";
90
	$default_email_body .= '<strong>' . esc_html__( 'Donor:', 'give' ) . '</strong> {name}' . "\n";
91
	$default_email_body .= '<strong>' . esc_html__( 'Donation:', 'give' ) . '</strong> {donation}' . "\n";
92
	$default_email_body .= '<strong>' . esc_html__( 'Amount:', 'give' ) . '</strong> {amount}' . "\n";
93
	$default_email_body .= '<strong>' . esc_html__( 'Payment Method:', 'give' ) . '</strong> {payment_method}' . "\n\n";
94
	$default_email_body .= esc_html__( 'Thank you,', 'give' ) . "\n\n";
95
	$default_email_body .= '{sitename}' . "\n";
96
97
	return apply_filters( 'give_default_donation_notification_email', $default_email_body );
98
}
99
100
101
/**
102
 * Get default donation receipt email text
103
 *
104
 * Returns the stored email text if available, the standard email text if not
105
 *
106
 * @since  1.3.7
107
 * @return string $message
108
 */
109
function give_get_default_donation_receipt_email() {
110
111
	$default_email_body = esc_html__( 'Dear', 'give' ) . " {name},\n\n";
112
	$default_email_body .= esc_html__( 'Thank you for your donation. Your generosity is appreciated! Here are the details of your donation:', 'give' ) . "\n\n";
113
	$default_email_body .= '<strong>' . esc_html__( 'Donor:', 'give' ) . '</strong> {fullname}' . "\n";
114
	$default_email_body .= '<strong>' . esc_html__( 'Donation:', 'give' ) . '</strong> {donation}' . "\n";
115
	$default_email_body .= '<strong>' . esc_html__( 'Donation Date:', 'give' ) . '</strong> {date}' . "\n";
116
	$default_email_body .= '<strong>' . esc_html__( 'Amount:', 'give' ) . '</strong> {amount}' . "\n";
117
	$default_email_body .= '<strong>' . esc_html__( 'Payment Method:', 'give' ) . '</strong> {payment_method}' . "\n";
118
	$default_email_body .= '<strong>' . esc_html__( 'Payment ID:', 'give' ) . '</strong> {payment_id}' . "\n";
119
	$default_email_body .= '<strong>' . esc_html__( 'Receipt ID:', 'give' ) . '</strong> {receipt_id}' . "\n\n";
120
	$default_email_body .= '{receipt_link}' . "\n\n";
121
	$default_email_body .= "\n\n";
122
	$default_email_body .= esc_html__( 'Sincerely,', 'give' ) . "\n";
123
	$default_email_body .= '{sitename}' . "\n";
124
125
	return apply_filters( 'give_default_donation_receipt_email', $default_email_body );
126
}
127
128
/**
129
 * Get various correctly formatted names used in emails
130
 *
131
 * @since 1.0
132
 *
133
 * @param $user_info
134
 *
135
 * @return array $email_names
136
 */
137
function give_get_email_names( $user_info ) {
138
	$email_names = array();
139
	$user_info   = maybe_unserialize( $user_info );
140
141
	$email_names['fullname'] = '';
142
	if ( isset( $user_info['id'] ) && $user_info['id'] > 0 && isset( $user_info['first_name'] ) ) {
143
		$user_data               = get_userdata( $user_info['id'] );
144
		$email_names['name']     = $user_info['first_name'];
145
		$email_names['fullname'] = $user_info['first_name'] . ' ' . $user_info['last_name'];
146
		$email_names['username'] = $user_data->user_login;
147
	} elseif ( isset( $user_info['first_name'] ) ) {
148
		$email_names['name']     = $user_info['first_name'];
149
		$email_names['fullname'] = $user_info['first_name'] . ' ' . $user_info['last_name'];
150
		$email_names['username'] = $user_info['first_name'];
151
	} else {
152
		$email_names['name']     = $user_info['email'];
153
		$email_names['username'] = $user_info['email'];
154
	}
155
156
	return $email_names;
157
}
158