| 1 |
<?php |
| 2 |
/** |
| 3 |
* Donor Note Email |
| 4 |
* |
| 5 |
* @package Give |
| 6 |
* @subpackage Classes/Emails |
| 7 |
* @copyright Copyright (c) 2018, GiveWP |
| 8 |
* @license https://opensource.org/licenses/gpl-license GNU Public License |
| 9 |
* @since 2.3.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
// Exit if access directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
if ( ! class_exists( 'Give_Donor_Note_Email' ) ) : |
| 18 |
|
| 19 |
/** |
| 20 |
* Give_Donor_Note_Email |
| 21 |
* |
| 22 |
* @abstract |
| 23 |
* @since 2.3.0 |
| 24 |
*/ |
| 25 |
class Give_Donor_Note_Email extends Give_Email_Notification { |
| 26 |
/* @var Give_Payment $payment */ |
| 27 |
public $payment; |
| 28 |
|
| 29 |
/** |
| 30 |
* Create a class instance. |
| 31 |
* |
| 32 |
* @access public |
| 33 |
* @since 2.3.0 |
| 34 |
*/ |
| 35 |
public function init() { |
| 36 |
// Initialize empty payment. |
| 37 |
$this->payment = new Give_Payment( 0 ); |
| 38 |
|
| 39 |
$this->load( |
| 40 |
array( |
| 41 |
'id' => 'donor-note', |
| 42 |
'label' => __( 'Donation Note', 'give' ), |
| 43 |
'description' => __( 'Sent when a donation note is added to a donation payment.', 'give' ), |
| 44 |
'notification_status' => 'enabled', |
| 45 |
'recipient_group_name' => __( 'Donor', 'give' ), |
| 46 |
'default_email_subject' => sprintf( |
| 47 |
esc_attr__( 'Note added to your %1$s donation from %2$s', 'give' ), |
| 48 |
'{donation}', |
| 49 |
'{date}' |
| 50 |
), |
| 51 |
'default_email_message' => sprintf( |
| 52 |
"Dear %s,\n\nA note has just been added to your donation:\n\n%s\n\nFor your reference, you may view your donation details by clicking the link below:\n%s\n\nThank you,\n%s", |
| 53 |
'{name}', |
| 54 |
'{donor_note}', |
| 55 |
'{receipt_link}', |
| 56 |
'{sitename}' |
| 57 |
), |
| 58 |
'default_email_header' => __( 'New Donation Note Added', 'give' ), |
| 59 |
'form_metabox_setting' => false, |
| 60 |
) |
| 61 |
); |
| 62 |
|
| 63 |
add_action( "give_{$this->config['id']}_email_notification", array( $this, 'send_note' ), 10, 2 ); |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Send donor note |
| 68 |
* |
| 69 |
* @since 2.3.0 |
| 70 |
* @access public |
| 71 |
* |
| 72 |
* @param int $donation_id Donation ID. |
| 73 |
* @param int $note_id Donor comment. |
| 74 |
*/ |
| 75 |
public function send_note( $note_id, $donation_id ) { |
| 76 |
if ( ! $note_id || ! $donation_id ) { |
| 77 |
wp_die( |
| 78 |
esc_html__( 'Cheatin’ uh?', 'give' ), |
| 79 |
esc_html__( 'Error', 'give' ), |
| 80 |
array( |
| 81 |
'response' => 400, |
| 82 |
) |
| 83 |
); |
| 84 |
} |
| 85 |
|
| 86 |
$this->recipient_email = give_get_donation_donor_email( $donation_id ); |
| 87 |
|
| 88 |
// Send email. |
| 89 |
$this->send_email_notification( |
| 90 |
array( |
| 91 |
'payment_id' => $donation_id, |
| 92 |
'note_id' => $note_id, |
| 93 |
) |
| 94 |
); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
endif; // End class_exists check |
| 99 |
|
| 100 |
return Give_Donor_Note_Email::get_instance(); |
| 101 |
|