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

Give_Offline_Donation_Instruction_Email   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 213
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 213
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 4

8 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 17 1
A get_email_message() 0 23 2
A get_email_subject() 0 25 2
A get_email_attachments() 0 23 1
A get_default_email_subject() 0 8 1
A get_default_email_message() 0 12 1
A setup_email_data() 0 24 1
A setup_email_notification() 0 14 2
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
 * Offline Donation Instruction 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_Offline_Donation_Instruction_Email' ) ) :
20
21
	/**
22
	 * Give_Offline_Donation_Instruction_Email
23
	 *
24
	 * @abstract
25
	 * @since       1.9
26
	 */
27
	class Give_Offline_Donation_Instruction_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          = 'offline-donation-instruction';
39
			$this->label       = __( 'Offline Donation Instruction', 'give' );
40
			$this->description = __( 'Offline Donation Instruction will be sent to recipient(s) when offline donation received.', 'give' );
41
42
			$this->notification_status       = 'enabled';
43
			$this->recipient_group_name      = __( 'Donor', 'give' );
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
		/**
57
		 * Get email message
58
		 *
59
		 * @since 1.9
60
		 * @return string
61
		 */
62
		public function get_email_message() {
63
			$post_offline_customization_option = get_post_meta(
64
				$this->payment->form_id,
65
				'_give_customize_offline_donations',
66
				true
67
			);
68
69
			//Customize email content depending on whether the single form has been customized
70
			$message = give_get_option( "{$this->id}_email_message", $this->get_default_email_message() );
71
72
			if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) {
73
				$message = get_post_meta( $this->payment->form_id, '_give_offline_donation_email', true );
74
			}
75
76
			/**
77
			 * Filter the email message.
78
			 *
79
			 * @since 1.9
80
			 */
81
			$message = apply_filters( "give_{$this->id}_get_email_message", $message, $this );
82
83
			return $message;
84
		}
85
86
		/**
87
		 * Get email message
88
		 *
89
		 * @since 1.9
90
		 * @return string
91
		 */
92
		public function get_email_subject() {
93
			$post_offline_customization_option = get_post_meta(
94
				$this->payment->form_id,
95
				'_give_customize_offline_donations',
96
				true
97
			);
98
99
			$subject = give_get_option(
100
				"{$this->id}_email_subject",
101
				$this->get_default_email_subject()
102
			);
103
104
			if ( give_is_setting_enabled( $post_offline_customization_option, 'enabled' ) ) {
105
				$subject = get_post_meta( $this->payment->form_id, '_give_offline_donation_subject', true );
106
			}
107
108
			/**
109
			 * Filter the email subject.
110
			 *
111
			 * @since 1.9
112
			 */
113
			$subject = apply_filters( "give_{$this->id}_get_email_subject", $subject, $this );
114
115
			return $subject;
116
		}
117
118
		/**
119
		 * Get attachments.
120
		 *
121
		 * @since 1.9
122
		 * @return array
123
		 */
124
		public function get_email_attachments() {
125
			/**
126
			 * Filter the attachments.
127
			 * Note: This filter will deprecate soon.
128
			 *
129
			 * @since 1.0
130
			 */
131
			$attachment = apply_filters(
132
				'give_offline_donation_attachments',
133
				array(),
134
				$this->payment->ID,
135
				$this->payment->payment_meta
136
			);
137
138
			/**
139
			 * Filter the email attachment.
140
			 *
141
			 * @since 1.9
142
			 */
143
			$attachment = apply_filters( "give_{$this->id}_get_email_attachment", $attachment, $this );
144
145
			return $attachment;
146
		}
147
148
		/**
149
		 * Get default email subject.
150
		 *
151
		 * @since  1.9
152
		 * @access public
153
		 * @return string
154
		 */
155
		public function get_default_email_subject() {
156
			/**
157
			 * Filter the default subject.
158
			 *
159
			 * @since 1.9
160
			 */
161
			return apply_filters( "give_{$this->id}_get_default_email_subject", esc_attr__( '{donation} - Offline Donation Instructions', 'give' ), $this );
162
		}
163
164
165
		/**
166
		 * Get default email message.
167
		 *
168
		 * @since  1.9
169
		 * @access public
170
		 *
171
		 * @return string
172
		 */
173
		public function get_default_email_message() {
174
			$message = give_get_default_offline_donation_email_content();
175
176
			/**
177
			 * Filter the email message
178
			 *
179
			 * @since 1.9
180
			 *
181
			 * @param string $message
182
			 */
183
			return apply_filters( "give_{$this->id}_get_default_email_message", $message, $this );
184
		}
185
186
187
		/**
188
		 * Set email data.
189
		 *
190
		 * @since 1.9
191
		 */
192
		public function setup_email_data() {
193
			// Set recipient email.
194
			$this->recipient_email = $this->payment->email;
195
196
			/**
197
			 * Filters the from name.
198
			 *
199
			 * @since 1.7
200
			 */
201
			$from_name = apply_filters( 'give_donation_from_name', Give()->emails->get_from_name(), $this->payment->ID, $this->payment->payment_meta );
202
203
			/**
204
			 * Filters the from email.
205
			 *
206
			 * @since 1.7
207
			 */
208
			$from_email = apply_filters( 'give_donation_from_address', Give()->emails->get_from_address(), $this->payment->ID, $this->payment->payment_meta );
209
210
211
			Give()->emails->__set( 'from_name', $from_name );
212
			Give()->emails->__set( 'from_email', $from_email );
213
			Give()->emails->__set( 'heading', __( 'Offline Donation Instructions', 'give' ) );
214
			Give()->emails->__set( 'headers', apply_filters( 'give_receipt_headers', Give()->emails->get_headers(), $this->payment->ID, $this->payment->payment_meta ) );
215
		}
216
217
		/**
218
		 * Setup email notification.
219
		 *
220
		 * @since  1.9
221
		 * @access public
222
		 *
223
		 * @param int $payment_id
224
		 */
225
		public function setup_email_notification( $payment_id ) {
226
			$this->payment = new Give_Payment( $payment_id );
227
228
			// Exit if not donation was not with offline donation.
229
			if ( 'offline' !== $this->payment->gateway ) {
230
				return;
231
			}
232
233
			// Set email data.
234
			$this->setup_email_data();
235
236
			// Send email.
237
			$this->send_email_notification( array( 'payment_id' => $this->payment->ID ) );
238
		}
239
	}
240
241
endif; // End class_exists check
242
243
return Give_Offline_Donation_Instruction_Email::get_instance();
244