Passed
Pull Request — master (#821)
by Kiran
04:42
created
includes/class-getpaid-invoice-notification-emails.php 1 patch
Spacing   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This class handles invoice notificaiton emails.
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		$this->invoice_actions = apply_filters(
29 29
 			'getpaid_notification_email_invoice_triggers',
30 30
 			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
31
+				'getpaid_new_invoice'                   => array('new_invoice', 'user_invoice'),
32 32
 				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33 33
 				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34 34
 				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 			)
42 42
 		);
43 43
 
44
-		add_action( 'init', array( $this, 'init_hooks' ) );
44
+		add_action('init', array($this, 'init_hooks'));
45 45
 	}
46 46
 
47 47
 	/**
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
 	 */
50 50
 	public function init_hooks() {
51 51
 
52
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
53
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
52
+		add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2);
53
+		add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2);
54 54
 
55
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
56
-			$this->init_email_type_hook( $hook, $email_type );
55
+		foreach ($this->invoice_actions as $hook => $email_type) {
56
+			$this->init_email_type_hook($hook, $email_type);
57 57
 		}
58 58
 	}
59 59
 
@@ -63,25 +63,25 @@  discard block
 block discarded – undo
63 63
 	 * @param string $hook
64 64
 	 * @param string|array $email_type
65 65
 	 */
66
-	public function init_email_type_hook( $hook, $email_type ) {
66
+	public function init_email_type_hook($hook, $email_type) {
67 67
 
68
-		$email_type = wpinv_parse_list( $email_type );
68
+		$email_type = wpinv_parse_list($email_type);
69 69
 
70
-		foreach ( $email_type as $type ) {
70
+		foreach ($email_type as $type) {
71 71
 
72
-			$email = new GetPaid_Notification_Email( $type );
72
+			$email = new GetPaid_Notification_Email($type);
73 73
 
74 74
 			// Abort if it is not active.
75
-			if ( ! $email->is_active() ) {
75
+			if (!$email->is_active()) {
76 76
 				continue;
77 77
 			}
78 78
 
79
-			if ( method_exists( $this, $type ) ) {
80
-				add_action( $hook, array( $this, $type ), 100, 2 );
79
+			if (method_exists($this, $type)) {
80
+				add_action($hook, array($this, $type), 100, 2);
81 81
 				continue;
82 82
 			}
83 83
 
84
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
84
+			do_action('getpaid_invoice_init_email_type_hook', $type, $hook);
85 85
 		}
86 86
 
87 87
 	}
@@ -92,19 +92,19 @@  discard block
 block discarded – undo
92 92
 	 * @param array $merge_tags
93 93
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
94 94
 	 */
95
-	public function invoice_merge_tags( $merge_tags, $object ) {
95
+	public function invoice_merge_tags($merge_tags, $object) {
96 96
 
97
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
97
+		if (is_a($object, 'WPInv_Invoice')) {
98 98
 			return array_merge(
99 99
 				$merge_tags,
100
-				$this->get_invoice_merge_tags( $object )
100
+				$this->get_invoice_merge_tags($object)
101 101
 			);
102 102
 		}
103 103
 
104
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
104
+		if (is_a($object, 'WPInv_Subscription')) {
105 105
 			return array_merge(
106 106
 				$merge_tags,
107
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
107
+				$this->get_invoice_merge_tags($object->get_parent_payment())
108 108
 			);
109 109
 		}
110 110
 
@@ -118,52 +118,52 @@  discard block
 block discarded – undo
118 118
 	 * @param WPInv_Invoice $invoice
119 119
 	 * @return array
120 120
 	 */
121
-	public function get_invoice_merge_tags( $invoice ) {
121
+	public function get_invoice_merge_tags($invoice) {
122 122
 
123 123
 		// Abort if it does not exist.
124
-		if ( ! $invoice->get_id() ) {
124
+		if (!$invoice->get_id()) {
125 125
 			return array();
126 126
 		}
127 127
 
128 128
 		$due_date   = $invoice->get_due_date();
129
-		$due_date   = empty( $due_date ) ? time() + MINUTE_IN_SECONDS : strtotime( $due_date ) + ( (int) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
129
+		$due_date   = empty($due_date) ? time() + MINUTE_IN_SECONDS : strtotime($due_date) + ((int) get_option('gmt_offset') * HOUR_IN_SECONDS);
130 130
 		$merge_tags = array(
131
-			'{name}'                 => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{full_name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
133
-			'{first_name}'           => sanitize_text_field( $invoice->get_first_name() ),
134
-			'{last_name}'            => sanitize_text_field( $invoice->get_last_name() ),
135
-			'{email}'                => sanitize_email( $invoice->get_email() ),
136
-			'{invoice_number}'       => sanitize_text_field( $invoice->get_number() ),
137
-			'{invoice_currency}'     => sanitize_text_field( $invoice->get_currency() ),
138
-			'{invoice_total}'        => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
139
-			'{invoice_link}'         => esc_url( $invoice->get_view_url() ),
140
-			'{invoice_pay_link}'     => esc_url( $invoice->get_checkout_payment_url() ),
141
-			'{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ),
142
-			'{invoice_date}'         => getpaid_format_date_value( $invoice->get_date_created() ),
143
-			'{invoice_due_date}'     => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
144
-			'{invoice_quote}'        => sanitize_text_field( strtolower( $invoice->get_label() ) ),
145
-			'{invoice_label}'        => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
146
-			'{invoice_description}'  => wp_kses_post( $invoice->get_description() ),
147
-			'{subscription_name}'    => wp_kses_post( $invoice->get_subscription_name() ),
148
-			'{is_was}'               => $due_date < time() ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
131
+			'{name}'                 => sanitize_text_field($invoice->get_user_full_name()),
132
+			'{full_name}'            => sanitize_text_field($invoice->get_user_full_name()),
133
+			'{first_name}'           => sanitize_text_field($invoice->get_first_name()),
134
+			'{last_name}'            => sanitize_text_field($invoice->get_last_name()),
135
+			'{email}'                => sanitize_email($invoice->get_email()),
136
+			'{invoice_number}'       => sanitize_text_field($invoice->get_number()),
137
+			'{invoice_currency}'     => sanitize_text_field($invoice->get_currency()),
138
+			'{invoice_total}'        => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())),
139
+			'{invoice_link}'         => esc_url($invoice->get_view_url()),
140
+			'{invoice_pay_link}'     => esc_url($invoice->get_checkout_payment_url()),
141
+			'{invoice_receipt_link}' => esc_url($invoice->get_receipt_url()),
142
+			'{invoice_date}'         => getpaid_format_date_value($invoice->get_date_created()),
143
+			'{invoice_due_date}'     => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')),
144
+			'{invoice_quote}'        => sanitize_text_field(strtolower($invoice->get_label())),
145
+			'{invoice_label}'        => sanitize_text_field(ucfirst($invoice->get_label())),
146
+			'{invoice_description}'  => wp_kses_post($invoice->get_description()),
147
+			'{subscription_name}'    => wp_kses_post($invoice->get_subscription_name()),
148
+			'{is_was}'               => $due_date < time() ? __('was', 'invoicing') : __('is', 'invoicing'),
149 149
 		);
150 150
 
151
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+		$payment_form_data = $invoice->get_meta('payment_form_data', true);
152 152
 
153
-		if ( is_array( $payment_form_data ) ) {
153
+		if (is_array($payment_form_data)) {
154 154
 
155
-			foreach ( $payment_form_data as $label => $value ) {
155
+			foreach ($payment_form_data as $label => $value) {
156 156
 
157
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
158
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
157
+				$label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label));
158
+				$value = is_array($value) ? implode(', ', $value) : $value;
159 159
 
160
-				if ( is_scalar( $value ) ) {
161
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
160
+				if (is_scalar($value)) {
161
+					$merge_tags["{{$label}}"] = wp_kses_post($value);
162 162
 				}
163 163
 			}
164 164
 		}
165 165
 
166
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
+		return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice);
167 167
 	}
168 168
 
169 169
 	/**
@@ -175,12 +175,12 @@  discard block
 block discarded – undo
175 175
 	 * @param string|array $recipients
176 176
 	 * @param array $extra_args Extra template args.
177 177
 	 */
178
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
178
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
179 179
 
180
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
180
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
181 181
 
182
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
183
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
182
+		$skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice');
183
+		if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) {
184 184
 			return;
185 185
 		}
186 186
 
@@ -188,43 +188,43 @@  discard block
 block discarded – undo
188 188
 		$merge_tags = $email->get_merge_tags();
189 189
 
190 190
 		$result = $mailer->send(
191
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
-			$email->get_content( $merge_tags, $extra_args ),
191
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
192
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
193
+			$email->get_content($merge_tags, $extra_args),
194 194
 			$email->get_attachments()
195 195
 		);
196 196
 
197 197
 		// Maybe send a copy to the admin.
198
-		if ( $email->include_admin_bcc() ) {
198
+		if ($email->include_admin_bcc()) {
199 199
 			$mailer->send(
200 200
 				wpinv_get_admin_email(),
201
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
-				$email->get_content( $merge_tags ),
201
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
202
+				$email->get_content($merge_tags),
203 203
 				$email->get_attachments()
204 204
 			);
205 205
 		}
206 206
 
207
-		if ( $result ) {
207
+		if ($result) {
208 208
 			$invoice->add_system_note(
209 209
 				sprintf(
210 210
 					// translators: %1 is the email type, %2 is the invoice recipient.
211
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
212
-					sanitize_key( $type ),
213
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
211
+					__('Successfully sent %1$s notification email to %2$s.', 'invoicing'),
212
+					sanitize_key($type),
213
+					$email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing')
214 214
 				)
215 215
 			);
216 216
 		} else {
217 217
 			$invoice->add_system_note(
218 218
 				sprintf(
219 219
 					// translators: %1 is the email type, %2 is the invoice recipient.
220
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
221
-					sanitize_key( $type ),
222
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
220
+					__('Failed sending %1$s notification email to %2$s.', 'invoicing'),
221
+					sanitize_key($type),
222
+					$email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing')
223 223
 				)
224 224
 			);
225 225
 		}
226 226
 
227
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
228 228
 
229 229
 		return $result;
230 230
 	}
@@ -235,20 +235,20 @@  discard block
 block discarded – undo
235 235
 	 * @param array $recipients
236 236
 	 * @param GetPaid_Notification_Email $email
237 237
 	 */
238
-	public function filter_email_recipients( $recipients, $email ) {
238
+	public function filter_email_recipients($recipients, $email) {
239 239
 
240
-		if ( ! $email->is_admin_email() ) {
240
+		if (!$email->is_admin_email()) {
241 241
 			$cc   = $email->object->get_email_cc();
242
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
+			$cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true);
243 243
 
244
-			if ( ! empty( $cc ) ) {
245
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
246
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
244
+			if (!empty($cc)) {
245
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
246
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
247 247
 			}
248 248
 
249
-			if ( ! empty( $cc_2 ) ) {
250
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
251
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
249
+			if (!empty($cc_2)) {
250
+				$cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2));
251
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc_2)));
252 252
 			}
253 253
 		}
254 254
 
@@ -261,17 +261,17 @@  discard block
 block discarded – undo
261 261
 	 *
262 262
 	 * @param WPInv_Invoice $invoice
263 263
 	 */
264
-	public function new_invoice( $invoice ) {
264
+	public function new_invoice($invoice) {
265 265
 
266 266
 		// Only send this email for invoices created via the admin page.
267
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
267
+		if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) {
268 268
 			return;
269 269
 		}
270 270
 
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
272 272
 		$recipient = wpinv_get_admin_email();
273 273
 
274
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
275 275
 
276 276
 	}
277 277
 
@@ -280,12 +280,12 @@  discard block
 block discarded – undo
280 280
 	 *
281 281
 	 * @param WPInv_Invoice $invoice
282 282
 	 */
283
-	public function cancelled_invoice( $invoice ) {
283
+	public function cancelled_invoice($invoice) {
284 284
 
285
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
286 286
 		$recipient = $invoice->get_email();
287 287
 
288
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
289 289
 	}
290 290
 
291 291
 	/**
@@ -293,12 +293,12 @@  discard block
 block discarded – undo
293 293
 	 *
294 294
 	 * @param WPInv_Invoice $invoice
295 295
 	 */
296
-	public function failed_invoice( $invoice ) {
296
+	public function failed_invoice($invoice) {
297 297
 
298
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
299 299
 		$recipient = wpinv_get_admin_email();
300 300
 
301
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
302 302
 
303 303
 	}
304 304
 
@@ -307,12 +307,12 @@  discard block
 block discarded – undo
307 307
 	 *
308 308
 	 * @param WPInv_Invoice $invoice
309 309
 	 */
310
-	public function onhold_invoice( $invoice ) {
310
+	public function onhold_invoice($invoice) {
311 311
 
312
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
312
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
313 313
 		$recipient = $invoice->get_email();
314 314
 
315
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
315
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
316 316
 
317 317
 	}
318 318
 
@@ -321,12 +321,12 @@  discard block
 block discarded – undo
321 321
 	 *
322 322
 	 * @param WPInv_Invoice $invoice
323 323
 	 */
324
-	public function processing_invoice( $invoice ) {
324
+	public function processing_invoice($invoice) {
325 325
 
326
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
326
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
327 327
 		$recipient = $invoice->get_email();
328 328
 
329
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
329
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
330 330
 
331 331
 	}
332 332
 
@@ -335,17 +335,17 @@  discard block
 block discarded – undo
335 335
 	 *
336 336
 	 * @param WPInv_Invoice $invoice
337 337
 	 */
338
-	public function completed_invoice( $invoice ) {
338
+	public function completed_invoice($invoice) {
339 339
 
340 340
 		// (Maybe) abort if it is a renewal invoice.
341
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
341
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
342 342
 			return;
343 343
 		}
344 344
 
345
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
345
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
346 346
 		$recipient = $invoice->get_email();
347 347
 
348
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
348
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
349 349
 
350 350
 	}
351 351
 
@@ -354,12 +354,12 @@  discard block
 block discarded – undo
354 354
 	 *
355 355
 	 * @param WPInv_Invoice $invoice
356 356
 	 */
357
-	public function refunded_invoice( $invoice ) {
357
+	public function refunded_invoice($invoice) {
358 358
 
359
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
359
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
360 360
 		$recipient = $invoice->get_email();
361 361
 
362
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
362
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
363 363
 
364 364
 	}
365 365
 
@@ -369,21 +369,21 @@  discard block
 block discarded – undo
369 369
 	 * @param WPInv_Invoice $invoice
370 370
 	 * @param bool $force
371 371
 	 */
372
-	public function user_invoice( $invoice, $force = false ) {
372
+	public function user_invoice($invoice, $force = false) {
373 373
 
374
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
374
+		if (!$force && !empty($GLOBALS['wpinv_skip_invoice_notification'])) {
375 375
 			return;
376 376
 		}
377 377
 
378 378
 		// Only send this email for invoices created via the admin page.
379
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
379
+		if (!$invoice->is_type('invoice') || (empty($force) && $invoice->is_paid()) || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) {
380 380
 			return;
381 381
 		}
382 382
 
383
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
383
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
384 384
 		$recipient = $invoice->get_email();
385 385
 
386
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
386
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
387 387
 
388 388
 	}
389 389
 
@@ -393,11 +393,11 @@  discard block
 block discarded – undo
393 393
 	 * @param int $invoice
394 394
 	 * @return bool
395 395
 	 */
396
-	public function is_payment_form_invoice( $invoice ) {
397
-		$created_via             = get_post_meta( $invoice, 'wpinv_created_via', true );
396
+	public function is_payment_form_invoice($invoice) {
397
+		$created_via             = get_post_meta($invoice, 'wpinv_created_via', true);
398 398
 		$is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via;
399
-		$is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
400
-		return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice;
399
+		$is_payment_form_invoice = apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice);
400
+		return empty($_GET['getpaid-admin-action']) && $is_payment_form_invoice;
401 401
 	}
402 402
 
403 403
 	/**
@@ -406,12 +406,12 @@  discard block
 block discarded – undo
406 406
 	 * @param WPInv_Invoice $invoice
407 407
 	 * @param string $note
408 408
 	 */
409
-	public function user_note( $invoice, $note ) {
409
+	public function user_note($invoice, $note) {
410 410
 
411
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
411
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
412 412
 		$recipient = $invoice->get_email();
413 413
 
414
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
414
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
415 415
 
416 416
 	}
417 417
 
@@ -420,9 +420,9 @@  discard block
 block discarded – undo
420 420
 	 *
421 421
 	 * @param WPInv_Invoice $invoice
422 422
 	 */
423
-	public function force_send_overdue_notice( $invoice ) {
424
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
425
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
423
+	public function force_send_overdue_notice($invoice) {
424
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
425
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
426 426
 	}
427 427
 
428 428
 	/**
@@ -433,38 +433,38 @@  discard block
 block discarded – undo
433 433
 	public function overdue() {
434 434
 		global $wpdb;
435 435
 
436
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
436
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
437 437
 
438 438
 		// Fetch reminder days.
439
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
439
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
440 440
 
441 441
 		// Abort if non is set.
442
-		if ( empty( $reminder_days ) ) {
442
+		if (empty($reminder_days)) {
443 443
 			return;
444 444
 		}
445 445
 
446 446
 		// Retrieve date query.
447
-		$date_query = $this->get_date_query( $reminder_days );
447
+		$date_query = $this->get_date_query($reminder_days);
448 448
 
449 449
 		// Invoices table.
450 450
 		$table = $wpdb->prefix . 'getpaid_invoices';
451 451
 
452 452
 		// Fetch invoices.
453
-		$invoices  = $wpdb->get_col(
453
+		$invoices = $wpdb->get_col(
454 454
 			"SELECT posts.ID FROM $wpdb->posts as posts
455 455
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
456 456
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"
457 457
         );
458 458
 
459
-		foreach ( $invoices as $invoice ) {
459
+		foreach ($invoices as $invoice) {
460 460
 
461 461
 			// Only send this email for invoices created via the admin page.
462
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
463
-				$invoice       = new WPInv_Invoice( $invoice );
462
+			if (!$this->is_payment_form_invoice($invoice)) {
463
+				$invoice       = new WPInv_Invoice($invoice);
464 464
 				$email->object = $invoice;
465 465
 
466
-				if ( $invoice->needs_payment() && ! $invoice->is_renewal() ) {
467
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
466
+				if ($invoice->needs_payment() && !$invoice->is_renewal()) {
467
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
468 468
 				}
469 469
 			}
470 470
 		}
@@ -477,14 +477,14 @@  discard block
 block discarded – undo
477 477
 	 * @param array $reminder_days
478 478
 	 * @return string
479 479
 	 */
480
-	public function get_date_query( $reminder_days ) {
480
+	public function get_date_query($reminder_days) {
481 481
 
482 482
 		$date_query = array(
483 483
 			'relation' => 'OR',
484 484
 		);
485 485
 
486
-		foreach ( $reminder_days as $days ) {
487
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
486
+		foreach ($reminder_days as $days) {
487
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
488 488
 
489 489
 			$date_query[] = array(
490 490
 				'year'  => $date['year'],
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
 
495 495
 		}
496 496
 
497
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
497
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
498 498
 
499 499
 		return $date_query->get_sql();
500 500
 
Please login to merge, or discard this patch.
includes/class-getpaid-subscription-notification-emails.php 1 patch
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This class handles subscription notificaiton emails.
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 			)
38 38
 		);
39 39
 
40
-		add_action( 'init', array( $this, 'init_hooks' ) );
40
+		add_action('init', array($this, 'init_hooks'));
41 41
 	}
42 42
 
43 43
     /**
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
45 45
 	 */
46 46
 	public function init_hooks() {
47 47
 
48
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'subscription_merge_tags' ), 10, 2 );
49
-		foreach ( $this->subscription_actions as $hook => $email_type ) {
48
+		add_filter('getpaid_get_email_merge_tags', array($this, 'subscription_merge_tags'), 10, 2);
49
+		foreach ($this->subscription_actions as $hook => $email_type) {
50 50
 
51
-			$email = new GetPaid_Notification_Email( $email_type );
51
+			$email = new GetPaid_Notification_Email($email_type);
52 52
 
53
-			if ( ! $email->is_active() ) {
53
+			if (!$email->is_active()) {
54 54
 				continue;
55 55
 			}
56 56
 
57
-			if ( method_exists( $this, $email_type ) ) {
58
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
57
+			if (method_exists($this, $email_type)) {
58
+				add_action($hook, array($this, $email_type), 100, 2);
59 59
 				continue;
60 60
 			}
61 61
 
62
-			do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
62
+			do_action('getpaid_subscription_notification_email_register_hook', $email_type, $hook);
63 63
 
64 64
 		}
65 65
 
@@ -71,12 +71,12 @@  discard block
 block discarded – undo
71 71
 	 * @param array $merge_tags
72 72
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73 73
 	 */
74
-	public function subscription_merge_tags( $merge_tags, $object ) {
74
+	public function subscription_merge_tags($merge_tags, $object) {
75 75
 
76
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
76
+		if (is_a($object, 'WPInv_Subscription')) {
77 77
 			$merge_tags = array_merge(
78 78
 				$merge_tags,
79
-				$this->get_subscription_merge_tags( $object )
79
+				$this->get_subscription_merge_tags($object)
80 80
 			);
81 81
 		}
82 82
 
@@ -90,25 +90,25 @@  discard block
 block discarded – undo
90 90
 	 * @param WPInv_Subscription $subscription
91 91
 	 * @return array
92 92
 	 */
93
-	public function get_subscription_merge_tags( $subscription ) {
93
+	public function get_subscription_merge_tags($subscription) {
94 94
 
95 95
 		// Abort if it does not exist.
96
-		if ( ! $subscription->get_id() ) {
96
+		if (!$subscription->get_id()) {
97 97
 			return array();
98 98
 		}
99 99
 
100
-		$invoice    = $subscription->get_parent_invoice();
100
+		$invoice = $subscription->get_parent_invoice();
101 101
 		return array(
102
-			'{subscription_renewal_date}'     => getpaid_format_date_value( $subscription->get_next_renewal_date(), __( 'Never', 'invoicing' ) ),
103
-			'{subscription_created}'          => getpaid_format_date_value( $subscription->get_date_created() ),
104
-			'{subscription_status}'           => sanitize_text_field( $subscription->get_status_label() ),
105
-			'{subscription_profile_id}'       => sanitize_text_field( $subscription->get_profile_id() ),
106
-			'{subscription_id}'               => absint( $subscription->get_id() ),
107
-			'{subscription_recurring_amount}' => sanitize_text_field( wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ) ),
108
-			'{subscription_initial_amount}'   => sanitize_text_field( wpinv_price( $subscription->get_initial_amount(), $invoice->get_currency() ) ),
109
-			'{subscription_recurring_period}' => getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ),
102
+			'{subscription_renewal_date}'     => getpaid_format_date_value($subscription->get_next_renewal_date(), __('Never', 'invoicing')),
103
+			'{subscription_created}'          => getpaid_format_date_value($subscription->get_date_created()),
104
+			'{subscription_status}'           => sanitize_text_field($subscription->get_status_label()),
105
+			'{subscription_profile_id}'       => sanitize_text_field($subscription->get_profile_id()),
106
+			'{subscription_id}'               => absint($subscription->get_id()),
107
+			'{subscription_recurring_amount}' => sanitize_text_field(wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency())),
108
+			'{subscription_initial_amount}'   => sanitize_text_field(wpinv_price($subscription->get_initial_amount(), $invoice->get_currency())),
109
+			'{subscription_recurring_period}' => getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''),
110 110
 			'{subscription_bill_times}'       => $subscription->get_bill_times(),
111
-			'{subscription_url}'              => esc_url( $subscription->get_view_url() ),
111
+			'{subscription_url}'              => esc_url($subscription->get_view_url()),
112 112
 		);
113 113
 
114 114
 	}
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return bool
121 121
 	 */
122
-	public function should_send_notification( $invoice ) {
122
+	public function should_send_notification($invoice) {
123 123
 		return 0 != $invoice->get_id();
124 124
 	}
125 125
 
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
 	 * @param WPInv_Invoice $invoice
130 130
 	 * @return array
131 131
 	 */
132
-	public function get_recipients( $invoice ) {
133
-		$recipients = array( $invoice->get_email() );
132
+	public function get_recipients($invoice) {
133
+		$recipients = array($invoice->get_email());
134 134
 
135 135
 		$cc = $invoice->get_email_cc();
136 136
 
137
-		if ( ! empty( $cc ) ) {
138
-			$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
139
-			$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
137
+		if (!empty($cc)) {
138
+			$cc = array_map('sanitize_email', wpinv_parse_list($cc));
139
+			$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
140 140
 		}
141 141
 
142 142
 		return $recipients;
@@ -150,75 +150,75 @@  discard block
 block discarded – undo
150 150
 	 * @param string $type
151 151
 	 * @param array $extra_args Extra template args.
152 152
 	 */
153
-	public function send_email( $subscription, $email, $type, $extra_args = array() ) {
153
+	public function send_email($subscription, $email, $type, $extra_args = array()) {
154 154
 
155
-		if ( empty( $subscription ) ) {
155
+		if (empty($subscription)) {
156 156
 			return;
157 157
 		}
158 158
 
159
-		if ( is_array( $subscription ) ) {
160
-			$subscription = current( $subscription );
159
+		if (is_array($subscription)) {
160
+			$subscription = current($subscription);
161 161
 		}
162 162
 
163
-		if ( ! $subscription instanceof WPInv_Subscription ) {
163
+		if (!$subscription instanceof WPInv_Subscription) {
164 164
 			return;
165 165
 		}
166 166
 
167 167
 		// Abort in case the parent invoice does not exist.
168 168
 		$invoice = $subscription->get_parent_invoice();
169
-		if ( ! $this->should_send_notification( $invoice ) ) {
169
+		if (!$this->should_send_notification($invoice)) {
170 170
 			return;
171 171
 		}
172 172
 
173
-		if ( apply_filters( 'getpaid_skip_subscription_email', false, $type, $subscription ) ) {
173
+		if (apply_filters('getpaid_skip_subscription_email', false, $type, $subscription)) {
174 174
 			return;
175 175
 		}
176 176
 
177
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
177
+		do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email);
178 178
 
179
-		$recipients  = $this->get_recipients( $invoice );
179
+		$recipients  = $this->get_recipients($invoice);
180 180
 		$mailer      = new GetPaid_Notification_Email_Sender();
181 181
 		$merge_tags  = $email->get_merge_tags();
182
-		$content     = $email->get_content( $merge_tags, $extra_args );
183
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
182
+		$content     = $email->get_content($merge_tags, $extra_args);
183
+		$subject     = $email->add_merge_tags($email->get_subject(), $merge_tags);
184 184
 		$attachments = $email->get_attachments();
185 185
 
186 186
 		$result = $mailer->send(
187
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
187
+			apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email),
188 188
 			$subject,
189 189
 			$content,
190 190
 			$attachments
191 191
 		);
192 192
 
193 193
 		// Maybe send a copy to the admin.
194
-		if ( $email->include_admin_bcc() ) {
194
+		if ($email->include_admin_bcc()) {
195 195
 			$mailer->send(
196 196
 				wpinv_get_admin_email(),
197
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
197
+				$subject . __(' - ADMIN BCC COPY', 'invoicing'),
198 198
 				$content,
199 199
 				$attachments
200 200
 			);
201 201
 		}
202 202
 
203
-		if ( $result ) {
203
+		if ($result) {
204 204
 			$invoice->add_system_note(
205 205
 				sprintf(
206
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
207
-					sanitize_key( $type ),
208
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
206
+					__('Successfully sent %1$s notification email to %2$s.', 'invoicing'),
207
+					sanitize_key($type),
208
+					$email->is_admin_email() ? __('admin') : __('the customer')
209 209
 				)
210 210
 			);
211 211
 		} else {
212 212
 			$invoice->add_system_note(
213 213
 				sprintf(
214
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
215
-					sanitize_key( $type ),
216
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
214
+					__('Failed sending %1$s notification email to %2$s.', 'invoicing'),
215
+					sanitize_key($type),
216
+					$email->is_admin_email() ? __('admin') : __('the customer')
217 217
 				)
218 218
 			);
219 219
 		}
220 220
 
221
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
221
+		do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email);
222 222
 
223 223
 	}
224 224
 
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
 	 *
230 230
 	 * @param WPInv_Subscription $subscription
231 231
 	 */
232
-	public function subscription_active( $subscription ) {
233
-		$email = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
232
+	public function subscription_active($subscription) {
233
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
234 234
 
235
-		$this->send_email( $subscription, $email, __FUNCTION__ );
235
+		$this->send_email($subscription, $email, __FUNCTION__);
236 236
 	}
237 237
 
238 238
     /**
@@ -240,10 +240,10 @@  discard block
 block discarded – undo
240 240
 	 *
241 241
 	 * @param WPInv_Subscription $subscription
242 242
 	 */
243
-	public function subscription_trial( $subscription ) {
243
+	public function subscription_trial($subscription) {
244 244
 
245
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
246
-		$this->send_email( $subscription, $email, __FUNCTION__ );
245
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
246
+		$this->send_email($subscription, $email, __FUNCTION__);
247 247
 
248 248
 	}
249 249
 
@@ -252,10 +252,10 @@  discard block
 block discarded – undo
252 252
 	 *
253 253
 	 * @param WPInv_Subscription $subscription
254 254
 	 */
255
-	public function subscription_cancelled( $subscription ) {
255
+	public function subscription_cancelled($subscription) {
256 256
 
257
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
258
-		$this->send_email( $subscription, $email, __FUNCTION__ );
257
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
258
+		$this->send_email($subscription, $email, __FUNCTION__);
259 259
 
260 260
 	}
261 261
 
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
 	 *
265 265
 	 * @param WPInv_Subscription $subscription
266 266
 	 */
267
-	public function subscription_expired( $subscription ) {
267
+	public function subscription_expired($subscription) {
268 268
 
269
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
270
-		$this->send_email( $subscription, $email, __FUNCTION__ );
269
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
270
+		$this->send_email($subscription, $email, __FUNCTION__);
271 271
 
272 272
 	}
273 273
 
@@ -276,10 +276,10 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @param WPInv_Subscription $subscription
278 278
 	 */
279
-	public function subscription_complete( $subscription ) {
279
+	public function subscription_complete($subscription) {
280 280
 
281
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
282
-		$this->send_email( $subscription, $email, __FUNCTION__ );
281
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
282
+		$this->send_email($subscription, $email, __FUNCTION__);
283 283
 
284 284
 	}
285 285
 
@@ -289,18 +289,18 @@  discard block
 block discarded – undo
289 289
 	 */
290 290
 	public function renewal_reminder() {
291 291
 
292
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
292
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
293 293
 
294 294
 		// Fetch reminder days.
295
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
295
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
296 296
 
297 297
 		// Abort if non is set.
298
-		if ( empty( $reminder_days ) ) {
298
+		if (empty($reminder_days)) {
299 299
 			return;
300 300
 		}
301 301
 
302 302
 		// Fetch matching subscriptions.
303
-        $args  = array(
303
+        $args = array(
304 304
             'number'             => -1,
305 305
 			'count_total'        => false,
306 306
 			'status'             => 'trialling active',
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
             ),
310 310
 		);
311 311
 
312
-		foreach ( $reminder_days as $days ) {
313
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
312
+		foreach ($reminder_days as $days) {
313
+			$date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp'))));
314 314
 
315 315
 			$args['date_expires_query'][] = array(
316 316
 				'year'  => $date['year'],
@@ -320,14 +320,14 @@  discard block
 block discarded – undo
320 320
 
321 321
 		}
322 322
 
323
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
323
+		$subscriptions = new GetPaid_Subscriptions_Query($args);
324 324
 
325
-        foreach ( $subscriptions->get_results() as $subscription ) {
325
+        foreach ($subscriptions->get_results() as $subscription) {
326 326
 
327 327
 			// Skip packages.
328
-			if ( apply_filters( 'getpaid_send_subscription_renewal_reminder_email', true ) ) {
328
+			if (apply_filters('getpaid_send_subscription_renewal_reminder_email', true)) {
329 329
 				$email->object = $subscription;
330
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
330
+            	$this->send_email($subscription, $email, __FUNCTION__);
331 331
 			}
332 332
 		}
333 333
 
Please login to merge, or discard this patch.