actions.php
8 years ago
class-give-email-tags.php
8 years ago
class-give-emails.php
8 years ago
functions.php
8 years ago
template.php
8 years ago
functions.php
268 lines
| 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 | /** |
| 31 | * Fire the action |
| 32 | */ |
| 33 | do_action( 'give_donation-receipt_email_notification', $payment_id ); |
| 34 | |
| 35 | // If admin notifications are on, send the admin notice. |
| 36 | if ( $admin_notice && give_is_setting_enabled( Give_Email_Notification::get_instance('new-donation' )->get_notification_status() ) ) { |
| 37 | /** |
| 38 | * Fires in the donation email receipt. |
| 39 | * |
| 40 | * When admin email notices are not disabled, you can add new email notices. |
| 41 | * |
| 42 | * @since 1.0 |
| 43 | * |
| 44 | * @param int $payment_id Payment id. |
| 45 | * @param mixed $payment_data Payment meta data. |
| 46 | */ |
| 47 | do_action( 'give_new-donation_email_notification', $payment_id, give_get_payment_meta( $payment_id ) ); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Sends the Admin Sale Notification Email |
| 53 | * |
| 54 | * @since 1.0 |
| 55 | * |
| 56 | * @param int $payment_id Payment ID (default: 0) |
| 57 | * |
| 58 | * @return void |
| 59 | */ |
| 60 | function give_admin_email_notice( $payment_id ) { |
| 61 | /** |
| 62 | * Fires in the donation email receipt. |
| 63 | * |
| 64 | * When admin email notices are not disabled, you can add new email notices. |
| 65 | * |
| 66 | * @since 1.0 |
| 67 | * |
| 68 | * @param int $payment_id Payment id. |
| 69 | * @param mixed $payment_data Payment meta data. |
| 70 | */ |
| 71 | do_action( 'give_new-donation_email_notification', $payment_id ); |
| 72 | } |
| 73 | |
| 74 | add_action( 'give_admin_donation_email', 'give_admin_email_notice' ); |
| 75 | |
| 76 | |
| 77 | /** |
| 78 | * Get default donation notification email text |
| 79 | * |
| 80 | * Returns the stored email text if available, the standard email text if not |
| 81 | * |
| 82 | * @since 1.0 |
| 83 | * @return string $message |
| 84 | */ |
| 85 | function give_get_default_donation_notification_email() { |
| 86 | |
| 87 | $default_email_body = __( 'Hi there,', 'give' ) . "\n\n"; |
| 88 | $default_email_body .= __( '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"; |
| 89 | $default_email_body .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {name}' . "\n"; |
| 90 | $default_email_body .= '<strong>' . __( 'Donation:', 'give' ) . '</strong> {donation}' . "\n"; |
| 91 | $default_email_body .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n"; |
| 92 | $default_email_body .= '<strong>' . __( 'Payment Method:', 'give' ) . '</strong> {payment_method}' . "\n\n"; |
| 93 | $default_email_body .= __( 'Thank you,', 'give' ) . "\n\n"; |
| 94 | $default_email_body .= '{sitename}' . "\n"; |
| 95 | |
| 96 | return apply_filters( 'give_default_donation_notification_email', $default_email_body ); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | /** |
| 101 | * Get default donation receipt email text |
| 102 | * |
| 103 | * Returns the stored email text if available, the standard email text if not |
| 104 | * |
| 105 | * @since 1.3.7 |
| 106 | * @return string $message |
| 107 | */ |
| 108 | function give_get_default_donation_receipt_email() { |
| 109 | |
| 110 | $default_email_body = __( 'Dear', 'give' ) . " {name},\n\n"; |
| 111 | $default_email_body .= __( 'Thank you for your donation. Your generosity is appreciated! Here are the details of your donation:', 'give' ) . "\n\n"; |
| 112 | $default_email_body .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {fullname}' . "\n"; |
| 113 | $default_email_body .= '<strong>' . __( 'Donation:', 'give' ) . '</strong> {donation}' . "\n"; |
| 114 | $default_email_body .= '<strong>' . __( 'Donation Date:', 'give' ) . '</strong> {date}' . "\n"; |
| 115 | $default_email_body .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n"; |
| 116 | $default_email_body .= '<strong>' . __( 'Payment Method:', 'give' ) . '</strong> {payment_method}' . "\n"; |
| 117 | $default_email_body .= '<strong>' . __( 'Payment ID:', 'give' ) . '</strong> {payment_id}' . "\n"; |
| 118 | $default_email_body .= '<strong>' . __( 'Receipt ID:', 'give' ) . '</strong> {receipt_id}' . "\n\n"; |
| 119 | $default_email_body .= '{receipt_link}' . "\n\n"; |
| 120 | $default_email_body .= "\n\n"; |
| 121 | $default_email_body .= __( 'Sincerely,', 'give' ) . "\n"; |
| 122 | $default_email_body .= '{sitename}' . "\n"; |
| 123 | |
| 124 | return apply_filters( 'give_default_donation_receipt_email', $default_email_body ); |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Get various correctly formatted names used in emails |
| 129 | * |
| 130 | * @since 1.0 |
| 131 | * |
| 132 | * @param $user_info |
| 133 | * @param $payment Give_Payment|bool for getting the names. |
| 134 | * |
| 135 | * @return array $email_names |
| 136 | */ |
| 137 | function give_get_email_names( $user_info, $payment = false ) { |
| 138 | $email_names = array(); |
| 139 | |
| 140 | if ( is_a( $payment, 'Give_Payment' ) ) { |
| 141 | |
| 142 | if ( $payment->user_id > 0 ) { |
| 143 | |
| 144 | $user_data = get_userdata( $payment->user_id ); |
| 145 | $email_names['name'] = $payment->first_name; |
| 146 | $email_names['fullname'] = trim( $payment->first_name . ' ' . $payment->last_name ); |
| 147 | $email_names['username'] = $user_data->user_login; |
| 148 | |
| 149 | } elseif ( ! empty( $payment->first_name ) ) { |
| 150 | |
| 151 | $email_names['name'] = $payment->first_name; |
| 152 | $email_names['fullname'] = trim( $payment->first_name . ' ' . $payment->last_name ); |
| 153 | $email_names['username'] = $payment->first_name; |
| 154 | |
| 155 | } else { |
| 156 | |
| 157 | $email_names['name'] = $payment->email; |
| 158 | $email_names['username'] = $payment->email; |
| 159 | |
| 160 | } |
| 161 | |
| 162 | } else { |
| 163 | |
| 164 | // Support for old serialized data. |
| 165 | if ( is_serialized( $user_info ) ) { |
| 166 | |
| 167 | // Security check. |
| 168 | preg_match( '/[oO]\s*:\s*\d+\s*:\s*"\s*(?!(?i)(stdClass))/', $user_info, $matches ); |
| 169 | if ( ! empty( $matches ) ) { |
| 170 | return array( |
| 171 | 'name' => '', |
| 172 | 'fullname' => '', |
| 173 | 'username' => '', |
| 174 | ); |
| 175 | } else { |
| 176 | $user_info = maybe_unserialize( $user_info ); |
| 177 | } |
| 178 | |
| 179 | } |
| 180 | |
| 181 | if ( isset( $user_info['id'] ) && $user_info['id'] > 0 && isset( $user_info['first_name'] ) ) { |
| 182 | $user_data = get_userdata( $user_info['id'] ); |
| 183 | $email_names['name'] = $user_info['first_name']; |
| 184 | $email_names['fullname'] = $user_info['first_name'] . ' ' . $user_info['last_name']; |
| 185 | $email_names['username'] = $user_data->user_login; |
| 186 | } elseif ( isset( $user_info['first_name'] ) ) { |
| 187 | $email_names['name'] = $user_info['first_name']; |
| 188 | $email_names['fullname'] = $user_info['first_name'] . ' ' . $user_info['last_name']; |
| 189 | $email_names['username'] = $user_info['first_name']; |
| 190 | } else { |
| 191 | $email_names['name'] = $user_info['email']; |
| 192 | $email_names['username'] = $user_info['email']; |
| 193 | } |
| 194 | |
| 195 | } |
| 196 | |
| 197 | return $email_names; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Send email to admin when user tries to login and restricted due to user - donor disconnection. |
| 202 | * |
| 203 | * @param int $user_id User ID. |
| 204 | * @param int $donor_id Donor ID. |
| 205 | * |
| 206 | * @since 1.8.14 |
| 207 | */ |
| 208 | function give_admin_email_user_donor_disconnection( $user_id, $donor_id ) { |
| 209 | |
| 210 | $user_id = absint( $user_id ); |
| 211 | $donor_id = absint( $donor_id ); |
| 212 | |
| 213 | // Bail Out, if user id doesn't exists. |
| 214 | if ( empty( $user_id ) ) { |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | // Bail Out, if donor id doesn't exists. |
| 219 | if ( empty( $donor_id ) ) { |
| 220 | return; |
| 221 | } |
| 222 | |
| 223 | $from_name = give_get_option( 'from_name', wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ) ); |
| 224 | |
| 225 | $from_email = give_get_option( 'from_email', get_bloginfo( 'admin_email' ) ); |
| 226 | |
| 227 | /* translators: %s: payment id */ |
| 228 | $subject = __( 'Attention: User tries to login whose Donor profile is disconnected!', 'give' ); |
| 229 | |
| 230 | /** |
| 231 | * Filters the Donor-User Disconnection notification subject. |
| 232 | * |
| 233 | * @since 1.8.14 |
| 234 | */ |
| 235 | $subject = apply_filters( 'give_admin_donor_user_disconnection_notification_subject', wp_strip_all_tags( $subject ) ); |
| 236 | |
| 237 | $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
| 238 | $headers .= "Reply-To: " . $from_email . "\r\n"; |
| 239 | $headers .= "Content-Type: text/html; charset=utf-8\r\n"; |
| 240 | |
| 241 | /** |
| 242 | * Filters the Donor-User Disconnection notification email headers. |
| 243 | * |
| 244 | * @since 1.8.14 |
| 245 | */ |
| 246 | $headers = apply_filters( 'give_admin_donor_user_disconnection_notification_headers', $headers ); |
| 247 | |
| 248 | $message = __( 'Hi Admin,', 'give' ) . "\n\n"; |
| 249 | $message .= __( 'This email is to inform you that a user has tried logging in. But, User was unable to login due to User-Donor profile disconnection.', 'give' ) . "\n\n"; |
| 250 | $message .= __( 'Do you want to reconnect User and Donor profile again?', 'give' ) . "\n\n"; |
| 251 | $message .= sprintf( |
| 252 | '<a href="%1$s">%2$s</a>', |
| 253 | esc_url( admin_url() . 'edit.php?post_type=give_forms&page=give-donors&view=overview&id=' . $donor_id . '&user_id=' . $user_id . '&give-message=reconnect-user' ), |
| 254 | __( 'Reconnect User', 'give' ) . "\n\n" |
| 255 | ); |
| 256 | $message .= __( 'Thank you,', 'give' ) . "\n\n"; |
| 257 | $message .= '{sitename}' . "\n"; |
| 258 | |
| 259 | $emails = Give()->emails; |
| 260 | $emails->__set( 'from_name', $from_name ); |
| 261 | $emails->__set( 'from_email', $from_email ); |
| 262 | $emails->__set( 'headers', $headers ); |
| 263 | $emails->__set( 'heading', __( 'User - Donor Profile Disconnection', 'give' ) ); |
| 264 | |
| 265 | $emails->send( give_get_admin_notice_emails(), $subject, give_do_email_tags( $message ) ); |
| 266 | |
| 267 | } |
| 268 |