PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.1.0
GiveWP – Donation Plugin and Fundraising Platform v4.1.0
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / includes / emails / functions.php

functions.php in GiveWP – Donation Plugin and Fundraising Platform 4.1.0, at includes/emails/functions.php

202 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Email Functions
4 *
5 * @package Give
6 * @subpackage Emails
7 * @copyright Copyright (c) 2016, GiveWP
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 * @param int $payment_id Payment ID.
23 * @param bool $admin_notice Whether to send the admin email notification or not (default: true).
24 *
25 * @return void
26 * @since 1.0
27 */
28 function give_email_donation_receipt( $payment_id, $admin_notice = true ) {
29 /**
30 * Fire the action
31 */
32 do_action( 'give_donation-receipt_email_notification', $payment_id );
33
34 // If admin notifications are on, send the admin notice.
35 if ( $admin_notice && give_is_setting_enabled( Give_Email_Notification::get_instance( 'new-donation' )->get_notification_status() ) ) {
36 /**
37 * Fires in the donation email receipt.
38 *
39 * When admin email notices are not disabled, you can add new email notices.
40 *
41 * @param int $payment_id Payment id.
42 * @param mixed $payment_data Payment meta data.
43 *
44 * @since 1.0
45 */
46 do_action( 'give_new-donation_email_notification', $payment_id, give_get_payment_meta( $payment_id ) );
47 }
48 }
49
50 /**
51 * Sends the Admin Sale Notification Email
52 *
53 * @param int $payment_id Payment ID (default: 0)
54 *
55 * @return void
56 * @since 1.0
57 */
58 function give_admin_email_notice( $payment_id ) {
59 /**
60 * Fires in the donation email receipt.
61 *
62 * When admin email notices are not disabled, you can add new email notices.
63 *
64 * @param int $payment_id Payment id.
65 * @param mixed $payment_data Payment meta data.
66 *
67 * @since 1.0
68 */
69 do_action( 'give_new-donation_email_notification', $payment_id );
70 }
71
72 add_action( 'give_admin_donation_email', 'give_admin_email_notice' );
73
74
75 /**
76 * Get default donation notification email text
77 *
78 * Returns the stored email text if available, the standard email text if not
79 *
80 * @return string $message
81 * @since 1.0
82 */
83 function give_get_default_donation_notification_email() {
84
85 $default_email_body = __( 'Hi there,', 'give' ) . "\n\n";
86 $default_email_body .= __( 'This email is to inform you that a new donation has been made on your website:', 'give' ) . ' {site_url}' . ".\n\n";
87 $default_email_body .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {name}' . "\n";
88 $default_email_body .= '<strong>' . __( 'Donation:', 'give' ) . '</strong> {donation}' . "\n";
89 $default_email_body .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n";
90 $default_email_body .= '<strong>' . __( 'Payment Method:', 'give' ) . '</strong> {payment_method}' . "\n\n";
91 $default_email_body .= __( 'Thank you,', 'give' ) . "\n\n";
92 $default_email_body .= '{sitename}' . "\n";
93
94 return apply_filters( 'give_default_donation_notification_email', $default_email_body );
95 }
96
97
98 /**
99 * Get default donation receipt email text
100 *
101 * Returns the stored email text if available, the standard email text if not
102 *
103 * @return string $message
104 * @since 1.3.7
105 */
106 function give_get_default_donation_receipt_email() {
107
108 $default_email_body = __( 'Dear', 'give' ) . " {name},\n\n";
109 $default_email_body .= __( 'Thank you for your donation. Your generosity is appreciated! Here are the details of your donation:', 'give' ) . "\n\n";
110 $default_email_body .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {fullname}' . "\n";
111 $default_email_body .= '<strong>' . __( 'Donation:', 'give' ) . '</strong> {donation}' . "\n";
112 $default_email_body .= '<strong>' . __( 'Donation Date:', 'give' ) . '</strong> {date}' . "\n";
113 $default_email_body .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n";
114 $default_email_body .= '<strong>' . __( 'Payment Method:', 'give' ) . '</strong> {payment_method}' . "\n";
115 $default_email_body .= '<strong>' . __( 'Payment ID:', 'give' ) . '</strong> {payment_id}' . "\n\n";
116 $default_email_body .= '{receipt_link}' . "\n\n";
117 $default_email_body .= "\n\n";
118 $default_email_body .= __( 'Sincerely,', 'give' ) . "\n";
119 $default_email_body .= '{sitename}' . "\n";
120
121 return apply_filters( 'give_default_donation_receipt_email', $default_email_body );
122 }
123
124 /**
125 * Get various correctly formatted names used in emails
126 *
127 * @param array $user_info List of User Information.
128 * @param Give_Payment|bool $payment Payment Object.
129 *
130 * @return array $email_names
131 * @since 1.0
132 */
133 function give_get_email_names( $user_info, $payment = false ) {
134 $email_names = array();
135
136 if ( is_a( $payment, 'Give_Payment' ) ) {
137
138 if ( $payment->user_id > 0 ) {
139
140 $user_data = get_userdata( $payment->user_id );
141 $email_names['name'] = $payment->first_name;
142 $email_names['fullname'] = trim( $payment->first_name . ' ' . $payment->last_name );
143 $email_names['username'] = $user_data->user_login;
144
145 } elseif ( ! empty( $payment->first_name ) ) {
146
147 $email_names['name'] = $payment->first_name;
148 $email_names['fullname'] = trim( $payment->first_name . ' ' . $payment->last_name );
149 $email_names['username'] = $payment->first_name;
150
151 } else {
152
153 $email_names['name'] = $payment->email;
154 $email_names['username'] = $payment->email;
155
156 }
157 } else {
158
159 // Support for old serialized data.
160 if ( is_serialized( $user_info ) ) {
161
162 // Security check.
163 preg_match( '/[oO]\s*:\s*\d+\s*:\s*"\s*(?!(?i)(stdClass))/', $user_info, $matches );
164 if ( ! empty( $matches ) ) {
165 return array(
166 'name' => '',
167 'fullname' => '',
168 'username' => '',
169 );
170 } else {
171 $user_info = maybe_unserialize( $user_info );
172 }
173 }
174
175 if ( isset( $user_info['id'] ) && $user_info['id'] > 0 && isset( $user_info['first_name'] ) ) {
176 $user_data = get_userdata( $user_info['id'] );
177 $email_names['name'] = $user_info['first_name'];
178 $email_names['fullname'] = $user_info['first_name'] . ' ' . $user_info['last_name'];
179 $email_names['username'] = $user_data->user_login;
180 } elseif ( isset( $user_info['first_name'] ) ) {
181 $email_names['name'] = $user_info['first_name'];
182 $email_names['fullname'] = $user_info['first_name'] . ' ' . $user_info['last_name'];
183 $email_names['username'] = $user_info['first_name'];
184 } else {
185 $email_names['name'] = $user_info['email'];
186 $email_names['username'] = $user_info['email'];
187 }
188 } // End if().
189
190 // Set title prefix to name, if non empty.
191 if ( ! empty( $user_info['title'] ) && ! empty( $user_info['last_name'] ) ) {
192 $email_names['name'] = give_get_donor_name_with_title_prefixes( $user_info['title'], $user_info['last_name'] );
193 }
194
195 // Set title prefix to fullname, if non empty.
196 if ( ! empty( $user_info['title'] ) && ! empty( $email_names['fullname'] ) ) {
197 $email_names['fullname'] = give_get_donor_name_with_title_prefixes( $user_info['title'], $email_names['fullname'] );
198 }
199
200 return $email_names;
201 }
202