Completed
Push — issues/611 ( cbcc9a...382813 )
by Ravinder
18:21
created

Give_New_Donation_Email::get_email_message()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 29
rs 8.8571
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 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       2.0
12
 */
13
14
// Exit if access directly.
15
if ( ! defined( 'ABSPATH' ) ) {
16
	exit;
17
}
18
19
if ( ! class_exists( 'Give_New_Donation_Email' ) ) :
20
21
	/**
22
	 * Give_New_Donation_Email
23
	 *
24
	 * @abstract
25
	 * @since       2.0
26
	 */
27
	class Give_New_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   2.0
36
		 */
37
		public function init() {
38
			// Initialize empty payment.
39
			$this->payment = new Give_Payment( 0 );
40
41
			$this->load( array(
42
				'id'                   => 'new-donation',
43
				'label'                => __( 'New Donation', 'give' ),
44
				'description'          => __( 'Donation Notification will be sent to recipient(s) when new donation received except offline donation.', 'give' ),
45
				'has_recipient_field'  => true,
46
				'notification_status'  => 'enabled',
47
				'form_metabox_setting' => true,
48
49
			) );
50
51
			add_action( "give_{$this->config['id']}_email_notification", array( $this, 'setup_email_notification' ) );
52
		}
53
54
55
		/**
56
		 * Get email subject.
57
		 *
58
		 * @since  2.0
59
		 * @access public
60
		 * @return string
61
		 */
62
		public function get_email_subject() {
63
			$subject = wp_strip_all_tags( give_get_option( "{$this->config['id']}_email_subject", $this->get_default_email_subject() ) );
64
65
			/**
66
			 * Filters the donation notification subject.
67
			 * Note: This filter will deprecate soon.
68
			 *
69
			 * @since 1.0
70
			 */
71
			$subject = apply_filters( 'give_admin_donation_notification_subject', $subject, $this->payment );
72
73
			/**
74
			 * Filters the donation notification subject.
75
			 *
76
			 * @since 2.0
77
			 */
78
			$subject = apply_filters( "give_{$this->config['id']}_get_email_subject", $subject, $this );
79
80
			return $subject;
81
		}
82
83
84
		/**
85
		 * Get email attachment.
86
		 *
87
		 * @since  2.0
88
		 * @access public
89
		 * @return string
90
		 */
91
		public function get_email_message() {
92
			$message = give_get_option( "{$this->config['id']}_email_message", $this->get_default_email_message() );
93
94
			/**
95
			 * Filter the email message
96
			 * Note: This filter will deprecate soon.
97
			 *
98
			 * @since 1.0
99
			 */
100
			$message = apply_filters(
101
				'give_donation_notification',
102
				$message,
103
				$this->payment->ID,
104
				$this->payment->payment_meta
105
			);
106
107
			/**
108
			 * Filter the email message
109
			 *
110
			 * @since 2.0
111
			 */
112
			$message = apply_filters(
113
				"give_{$this->config['id']}_get_default_email_message",
114
				$message,
115
				$this
116
			);
117
118
			return $message;
119
		}
120
121
122
		/**
123
		 * Get email attachment.
124
		 *
125
		 * @since  2.0
126
		 * @access public
127
		 * @return array
128
		 */
129
		public function get_email_attachments() {
130
			/**
131
			 * Filters the donation notification email attachments.
132
			 * By default, there is no attachment but plugins can hook in to provide one more multiple.
133
			 * Note: This filter will deprecate soon.
134
			 *
135
			 * @since 1.0
136
			 */
137
			$attachments = apply_filters(
138
				'give_admin_donation_notification_attachments',
139
				array(),
140
				$this->payment->ID,
141
				$this->payment->payment_meta
142
			);
143
144
			/**
145
			 * Filters the donation notification email attachments.
146
			 * By default, there is no attachment but plugins can hook in to provide one more multiple.
147
			 *
148
			 * @since 2.0
149
			 */
150
			$attachments = apply_filters(
151
				"give_{$this->config['id']}_get_email_attachments",
152
				$attachments,
153
				$this
154
			);
155
156
			return $attachments;
157
		}
158
159
		/**
160
		 * Get default email subject.
161
		 *
162
		 * @since  2.0
163
		 * @access public
164
		 * @return string
165
		 */
166
		public function get_default_email_subject() {
167
			/**
168
			 * Filter the defaul email subject.
169
			 *
170
			 * @since 2.0
171
			 */
172
			return apply_filters(
173
				"give_{$this->config['id']}_get_default_email_subject",
174
				esc_attr__( 'New Donation - #{payment_id}', 'give' ),
175
				$this
176
			);
177
		}
178
179
180
		/**
181
		 * Get default email message.
182
		 *
183
		 * @since  2.0
184
		 * @access public
185
		 *
186
		 * @return string
187
		 */
188
		public function get_default_email_message() {
189
			/**
190
			 * Filter the new donation email message
191
			 *
192
			 * @since 2.0
193
			 *
194
			 * @param string $message
195
			 */
196
			return apply_filters(
197
				"give_{$this->config['id']}_get_default_email_message",
198
				give_get_default_donation_notification_email(),
199
				$this
200
			);
201
		}
202
203
204
		/**
205
		 * Set email data
206
		 *
207
		 * @since 2.0
208
		 */
209
		public function setup_email_data() {
210
			/**
211
			 * Filters the from name.
212
			 * Note: This filter will deprecate soon.
213
			 *
214
			 * @since 1.0
215
			 */
216
			$from_name = apply_filters(
217
				'give_donation_from_name',
218
				Give()->emails->get_from_name(),
219
				$this->payment->ID,
220
				$this->payment->payment_meta
221
			);
222
223
			/**
224
			 * Filters the from email.
225
			 * Note: This filter will deprecate soon.
226
			 *
227
			 * @since 1.0
228
			 */
229
			$from_email = apply_filters(
230
				'give_donation_from_address',
231
				Give()->emails->get_from_address(),
232
				$this->payment->ID,
233
				$this->payment->payment_meta
234
			);
235
236
			Give()->emails->__set( 'from_name', $from_name );
237
			Give()->emails->__set( 'from_email', $from_email );
238
			Give()->emails->__set( 'heading', esc_html__( 'New Donation!', 'give' ) );
239
			/**
240
			 * Filters the donation notification email headers.
241
			 *
242
			 * @since 1.0
243
			 */
244
			$headers = apply_filters(
245
				'give_admin_donation_notification_headers',
246
				Give()->emails->get_headers(),
247
				$this->payment->ID,
248
				$this->payment->payment_meta
249
			);
250
251
			Give()->emails->__set( 'headers', $headers );
252
		}
253
254
		/**
255
		 * Setup email notification.
256
		 *
257
		 * @since  2.0
258
		 * @access public
259
		 *
260
		 * @param int $payment_id
261
		 */
262
		public function setup_email_notification( $payment_id ) {
263
			$this->payment = new Give_Payment( $payment_id );
264
265
			// Set email data.
266
			$this->setup_email_data();
267
268
			// Send email.
269
			$this->send_email_notification( array(
270
				'payment_id' => $payment_id,
271
			) );
272
		}
273
	}
274
275
endif; // End class_exists check
276
277
return Give_New_Donation_Email::get_instance();
278