Completed
Push — backup/611 ( 661115 )
by Ravinder
1411:51 queued 1394:16
created

Give_New_Offline_Donation_Email::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 27 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * New Offline Donation Email
4
 *
5
 * This class handles all email notification settings.
6
 *
7
 * @package     Give
8
 * @subpackage  Classes/Emails
9
 * @copyright   Copyright (c) 2016, WordImpress
10
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
11
 * @since       1.9
12
 */
13
14
// Exit if access directly.
15
if ( ! defined( 'ABSPATH' ) ) {
16
	exit;
17
}
18
19
if ( ! class_exists( 'Give_New_Offline_Donation_Email' ) ) :
20
21
	/**
22
	 * Give_New_Offline_Donation_Email
23
	 *
24
	 * @abstract
25
	 * @since       1.9
26
	 */
27
	class Give_New_Offline_Donation_Email extends Give_Email_Notification {
28
		/* @var Give_Payment $payment */
29
		public $payment;
30
31
		/**
32
		 * Create a class instance.
33
		 *
34
		 * @access  public
35
		 * @since   1.9
36
		 */
37
		public function init() {
38
			$this->id          = 'new-offline-donation';
39
			$this->label       = __( 'New Offline Donation', 'give' );
40
			$this->description = __( 'Donation Notification will be sent to admin when new offline donation received.', 'give' );
41
42
			$this->has_recipient_field       = true;
43
			$this->notification_status       = 'enabled';
44
			$this->form_metabox_setting      = true;
45
			$this->preview_email_tags_values = array( 'payment_method' => esc_html__( 'Offline', 'give' ) );
46
47
			// Initialize empty payment.
48
			$this->payment = new Give_Payment(0);
49
50
			$this->load();
51
52
			add_action( 'give_insert_payment', array( $this, 'setup_email_notification' ) );
53
		}
54
55
		/**
56
		 * Get default email subject.
57
		 *
58
		 * @since  1.9
59
		 * @access public
60
		 * @return string
61
		 */
62
		public function get_default_email_subject() {
63
			/**
64
			 * Filter the default subject.
65
			 * Note: This filter will deprecate soon.
66
			 *
67
			 * @since 1.0
68
			 */
69
			$subject = apply_filters(
70
				'give_offline_admin_donation_notification_subject',
71
				__( 'New Pending Donation', 'give' )
72
			);
73
74
			/**
75
			 * Filter the default subject
76
			 *
77
			 * @since 1.9
78
			 */
79
			return apply_filters( "give_{$this->id}_get_default_email_subject", $subject, $this );
80
		}
81
82
83
		/**
84
		 * Get default email message.
85
		 *
86
		 * @since  1.9
87
		 * @access public
88
		 *
89
		 * @return string
90
		 */
91
		public function get_default_email_message() {
92
			$message = __( 'Dear Admin,', 'give' ) . "\n\n";
93
			$message .= __( 'An offline donation has been made on your website:', 'give' ) . ' ' . get_bloginfo( 'name' ) . ' ';
94
			$message .= __( 'Hooray! The donation is in a pending status and is awaiting payment. Donation instructions have been emailed to the donor. Once you receive payment, be sure to mark the donation as complete using the link below.', 'give' ) . "\n\n";
95
96
97
			$message .= '<strong>' . __( 'Donor:', 'give' ) . '</strong> {fullname}' . "\n";
98
			$message .= '<strong>' . __( 'Amount:', 'give' ) . '</strong> {amount}' . "\n\n";
99
100
			$message .= sprintf(
101
				'<a href="%1$s">%2$s</a>',
102
				admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-order-details&id=' . $this->payment->ID ),
103
				__( 'Click Here to View and/or Update Donation Details', 'give' )
104
			) . "\n\n";
105
106
107
			/**
108
			 * Filter the donation receipt email message
109
			 * Note: This filter will deprecate soon.
110
			 *
111
			 * @since 1.0
112
			 *
113
			 * @param string $message
114
			 */
115
			$message =  apply_filters(
116
				'give_default_new_offline_donation_email',
117
				$message,
118
				$this->payment->ID
119
			);
120
121
			/**
122
			 * Filter the default message
123
			 *
124
			 * @since 1.9
125
			 */
126
			return apply_filters( "give_{$this->id}_get_default_email_message", $message, $this );
127
		}
128
129
130
		/**
131
		 * Get message
132
		 *
133
		 * @since 1.9
134
		 * @return string
135
		 */
136
		public function get_email_message() {
137
			$message = give_get_option( "{$this->id}_email_message", $this->get_default_email_message() );
138
139
140
			/**
141
			 * Filter the email message.
142
			 * Note: This filter will deprecate soon.
143
			 *
144
			 * @since 1.0
145
			 */
146
			$message = apply_filters( 'give_offline_admin_donation_notification', $message, $this->payment->ID );
147
148
			/**
149
			 * Filter the email message
150
			 *
151
			 * @since 1.9
152
			 */
153
			return apply_filters( "give_{$this->id}_get_email_message", $message, $this );
154
		}
155
156
157
		/**
158
		 * Get attachments.
159
		 *
160
		 * @since 1.9
161
		 * @return array
162
		 */
163
		public function get_email_attachments() {
164
			/**
165
			 * Filter the attachments.
166
			 * Note: This filter will deprecate soon.
167
			 *
168
			 * @since 1.0
169
			 */
170
			$attachment = apply_filters(
171
				'give_offline_admin_donation_notification_attachments',
172
				array(),
173
				$this->payment->ID
174
			);
175
176
			/**
177
			 * Filter the attachments.
178
			 *
179
			 * @since 1.9
180
			 */
181
			return apply_filters( "give_{$this->id}_get_email_attachments", $attachment, $this );
182
		}
183
184
185
		/**
186
		 * Set email data.
187
		 *
188
		 * @since 1.9
189
		 */
190
		public function setup_email_data() {
191
			// Set recipient email.
192
			$this->recipient_email = $this->payment->email;
193
194
195
			// Set header.
196
			Give()->emails->__set(
197
				'headers',
198
				apply_filters(
199
					'give_offline_admin_donation_notification_headers',
200
					Give()->emails->get_headers(),
201
					$this->payment->ID
202
				)
203
			);
204
		}
205
206
		/**
207
		 * Setup email notification.
208
		 *
209
		 * @since  1.9
210
		 * @access public
211
		 *
212
		 * @param int $payment_id
213
		 */
214
		public function setup_email_notification( $payment_id ) {
215
			$this->payment = new Give_Payment( $payment_id );
216
217
218
			// Exit if not donation was not with offline donation.
219
			if ( 'offline' !== $this->payment->gateway ) {
220
				return;
221
			}
222
223
			// Set email data.
224
			$this->setup_email_data();
225
226
			// Send email.
227
			$this->send_email_notification( array( 'payment_id' => $this->payment->ID ) );
228
		}
229
	}
230
231
endif; // End class_exists check
232
233
return Give_New_Offline_Donation_Email::get_instance();