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

Give_New_Donation_Email::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 16
rs 9.7333
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       1.9
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       1.9
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   1.9
36
		 */
37
		public function init() {
38
			$this->id          = 'new-donation';
39
			$this->label       = __( 'New Donation', 'give' );
40
			$this->description = __( 'Donation Notification will be sent to recipient(s) when new donation received except offline donation.', 'give' );
41
42
			$this->has_recipient_field = true;
43
			$this->notification_status = 'enabled';
44
			$this->form_metabox_setting = true;
45
46
			// Initialize empty payment.
47
			$this->payment = new Give_Payment( 0 );
48
49
			$this->load();
50
51
			add_action( "give_{$this->id}_email_notification", array( $this, 'setup_email_notification' ) );
52
		}
53
54
55
		/**
56
		 * Get email subject.
57
		 *
58
		 * @since 1.9
59
		 * @access public
60
		 * @return string
61
		 */
62
		public function get_email_subject() {
63
			$subject = wp_strip_all_tags( give_get_option( "{$this->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 1.9
77
			 */
78
			$subject = apply_filters( "give_{$this->id}_get_email_subject", $subject, $this );
79
80
			return $subject;
81
		}
82
83
84
		/**
85
		 * Get email attachment.
86
		 *
87
		 * @since 1.9
88
		 * @access public
89
		 * @return string
90
		 */
91
		public function get_email_message() {
92
			$message = give_get_option( "{$this->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( 'give_donation_notification', $message, $this->payment->ID, $this->payment->payment_meta );
101
102
			/**
103
			 * Filter the email message
104
			 *
105
			 * @since 1.9
106
			 */
107
			$message = apply_filters( "give_{$this->id}_get_default_email_message", $message, $this );
108
109
			return $message;
110
		}
111
112
113
		/**
114
		 * Get email attachment.
115
		 *
116
		 * @since 1.9
117
		 * @access public
118
		 * @return array
119
		 */
120
		public function get_email_attachments() {
121
			/**
122
			 * Filters the donation notification email attachments.
123
			 * By default, there is no attachment but plugins can hook in to provide one more multiple.
124
			 * Note: This filter will deprecate soon.
125
			 *
126
			 * @since 1.0
127
			 */
128
			$attachments = apply_filters( 'give_admin_donation_notification_attachments', array(), $this->payment->ID, $this->payment->payment_meta );
129
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
			 *
134
			 * @since 1.9
135
			 */
136
			$attachments = apply_filters( "give_{$this->id}_get_email_attachments", $attachments, $this );
137
138
			return $attachments;
139
		}
140
141
		/**
142
		 * Get default email subject.
143
		 *
144
		 * @since  1.9
145
		 * @access public
146
		 * @return string
147
		 */
148
		public function get_default_email_subject() {
149
			/**
150
			 * Filter the defaul email subject.
151
			 *
152
			 * @since 1.9
153
			 */
154
			return apply_filters( "give_{$this->id}_get_default_email_subject", esc_attr__( 'New Donation - #{payment_id}', 'give' ), $this );
155
		}
156
157
158
		/**
159
		 * Get default email message.
160
		 *
161
		 * @since  1.9
162
		 * @access public
163
		 *
164
		 * @return string
165
		 */
166
		public function get_default_email_message() {
167
			/**
168
			 * Filter the new donation email message
169
			 *
170
			 * @since 1.9
171
			 *
172
			 * @param string $message
173
			 */
174
			return apply_filters( "give_{$this->id}_get_default_email_message", give_get_default_donation_notification_email(), $this );
175
		}
176
177
178
		/**
179
		 * Set email data
180
		 *
181
		 * @since 1.9
182
		 */
183
		public function setup_email_data() {
184
			/**
185
			 * Filters the from name.
186
			 * Note: This filter will deprecate soon.
187
			 *
188
			 * @since 1.0
189
			 */
190
			$from_name = apply_filters( 'give_donation_from_name', Give()->emails->get_from_name(), $this->payment->ID, $this->payment->payment_meta );
191
192
			/**
193
			 * Filters the from email.
194
			 * Note: This filter will deprecate soon.
195
			 *
196
			 * @since 1.0
197
			 */
198
			$from_email = apply_filters( 'give_donation_from_address', Give()->emails->get_from_address(), $this->payment->ID, $this->payment->payment_meta );
199
200
			Give()->emails->__set( 'from_name', $from_name );
201
			Give()->emails->__set( 'from_email', $from_email );
202
			Give()->emails->__set( 'heading', esc_html__( 'New Donation!', 'give' ) );
203
			/**
204
			 * Filters the donation notification email headers.
205
			 *
206
			 * @since 1.0
207
			 */
208
			$headers = apply_filters( 'give_admin_donation_notification_headers', Give()->emails->get_headers(), $this->payment->ID, $this->payment->payment_meta );
209
210
			Give()->emails->__set( 'headers', $headers );
211
		}
212
213
		/**
214
		 * Setup email notification.
215
		 *
216
		 * @since  1.9
217
		 * @access public
218
		 *
219
		 * @param int $payment_id
220
		 */
221
		public function setup_email_notification( $payment_id ) {
222
			$this->payment = new Give_Payment( $payment_id );
223
224
			// Set email data.
225
			$this->setup_email_data();
226
227
			// Send email.
228
			$this->send_email_notification( array( 'payment_id' => $payment_id ) );
229
		}
230
	}
231
232
endif; // End class_exists check
233
234
return Give_New_Donation_Email::get_instance();