Passed
Push — master ( ab48b7...8bc67f )
by Brian
04:26
created
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +466 added lines, -466 removed lines patch added patch discarded remove patch
@@ -12,491 +12,491 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 *
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                 => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'           => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'            => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'                => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'       => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'     => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'        => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'         => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'     => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'         => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'     => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'        => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'        => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}'  => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'    => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'               => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
-
152
-		if ( is_array( $payment_form_data ) ) {
153
-
154
-			foreach ( $payment_form_data as $label => $value ) {
155
-
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
-
159
-				if ( is_scalar( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
-				}
162
-			}
163
-		}
164
-
165
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
-	}
167
-
168
-	/**
169
-	 * Helper function to send an email.
170
-	 *
171
-	 * @param WPInv_Invoice $invoice
172
-	 * @param GetPaid_Notification_Email $email
173
-	 * @param string $type
174
-	 * @param string|array $recipients
175
-	 * @param array $extra_args Extra template args.
176
-	 */
177
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
178
-
179
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
180
-
181
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
183
-			return;
184
-		}
185
-
186
-		$mailer     = new GetPaid_Notification_Email_Sender();
187
-		$merge_tags = $email->get_merge_tags();
188
-
189
-		$result = $mailer->send(
190
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
-			$email->get_content( $merge_tags, $extra_args ),
193
-			$email->get_attachments()
194
-		);
195
-
196
-		// Maybe send a copy to the admin.
197
-		if ( $email->include_admin_bcc() ) {
198
-			$mailer->send(
199
-				wpinv_get_admin_email(),
200
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
-				$email->get_content( $merge_tags ),
202
-				$email->get_attachments()
203
-			);
204
-		}
205
-
206
-		if ( $result ) {
207
-			$invoice->add_system_note(
208
-				sprintf(
209
-					// translators: %1 is the email type, %2 is the invoice recipient.
210
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
211
-					sanitize_key( $type ),
212
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
213
-				)
214
-			);
215
-		} else {
216
-			$invoice->add_system_note(
217
-				sprintf(
218
-					// translators: %1 is the email type, %2 is the invoice recipient.
219
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
220
-					sanitize_key( $type ),
221
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
222
-				)
223
-			);
224
-		}
225
-
226
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
-
228
-		return $result;
229
-	}
230
-
231
-	/**
232
-	 * Also send emails to any cc users.
233
-	 *
234
-	 * @param array $recipients
235
-	 * @param GetPaid_Notification_Email $email
236
-	 */
237
-	public function filter_email_recipients( $recipients, $email ) {
238
-
239
-		if ( ! $email->is_admin_email() ) {
240
-			$cc   = $email->object->get_email_cc();
241
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
-
243
-			if ( ! empty( $cc ) ) {
244
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
246
-			}
247
-
248
-			if ( ! empty( $cc_2 ) ) {
249
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
251
-			}
252
-		}
253
-
254
-		return $recipients;
255
-
256
-	}
257
-
258
-	/**
259
-	 * Sends a new invoice notification.
260
-	 *
261
-	 * @param WPInv_Invoice $invoice
262
-	 */
263
-	public function new_invoice( $invoice ) {
264
-
265
-		// Only send this email for invoices created via the admin page.
266
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
267
-			return;
268
-		}
269
-
270
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
-		$recipient = wpinv_get_admin_email();
272
-
273
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
-
275
-	}
276
-
277
-	/**
278
-	 * Sends a cancelled invoice notification.
279
-	 *
280
-	 * @param WPInv_Invoice $invoice
281
-	 */
282
-	public function cancelled_invoice( $invoice ) {
283
-
284
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
-		$recipient = $invoice->get_email();
286
-
287
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
-	}
289
-
290
-	/**
291
-	 * Sends a failed invoice notification.
292
-	 *
293
-	 * @param WPInv_Invoice $invoice
294
-	 */
295
-	public function failed_invoice( $invoice ) {
296
-
297
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
-		$recipient = wpinv_get_admin_email();
299
-
300
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301
-
302
-	}
303
-
304
-	/**
305
-	 * Sends a notification whenever an invoice is put on hold.
306
-	 *
307
-	 * @param WPInv_Invoice $invoice
308
-	 */
309
-	public function onhold_invoice( $invoice ) {
310
-
311
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
312
-		$recipient = $invoice->get_email();
313
-
314
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
315
-
316
-	}
317
-
318
-	/**
319
-	 * Sends a notification whenever an invoice is marked as processing payment.
320
-	 *
321
-	 * @param WPInv_Invoice $invoice
322
-	 */
323
-	public function processing_invoice( $invoice ) {
324
-
325
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
326
-		$recipient = $invoice->get_email();
327
-
328
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
329
-
330
-	}
331
-
332
-	/**
333
-	 * Sends a notification whenever an invoice is paid.
334
-	 *
335
-	 * @param WPInv_Invoice $invoice
336
-	 */
337
-	public function completed_invoice( $invoice ) {
338
-
339
-		// (Maybe) abort if it is a renewal invoice.
340
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
341
-			return;
342
-		}
343
-
344
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
345
-		$recipient = $invoice->get_email();
346
-
347
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
348
-
349
-	}
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     *
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                 => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'           => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'            => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'                => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'       => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'     => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'        => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
+            '{invoice_link}'         => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'     => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'         => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'     => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'        => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'        => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}'  => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'    => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'               => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        $payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+
152
+        if ( is_array( $payment_form_data ) ) {
153
+
154
+            foreach ( $payment_form_data as $label => $value ) {
155
+
156
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
+
159
+                if ( is_scalar( $value ) ) {
160
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
+                }
162
+            }
163
+        }
164
+
165
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
166
+    }
350 167
 
351
-	/**
352
-	 * Sends a notification whenever an invoice is refunded.
353
-	 *
354
-	 * @param WPInv_Invoice $invoice
355
-	 */
356
-	public function refunded_invoice( $invoice ) {
357
-
358
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
359
-		$recipient = $invoice->get_email();
360
-
361
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
362
-
363
-	}
168
+    /**
169
+     * Helper function to send an email.
170
+     *
171
+     * @param WPInv_Invoice $invoice
172
+     * @param GetPaid_Notification_Email $email
173
+     * @param string $type
174
+     * @param string|array $recipients
175
+     * @param array $extra_args Extra template args.
176
+     */
177
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
364 178
 
365
-	/**
366
-	 * Notifies a user about new invoices
367
-	 *
368
-	 * @param WPInv_Invoice $invoice
369
-	 * @param bool $force
370
-	 */
371
-	public function user_invoice( $invoice, $force = false ) {
179
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
372 180
 
373
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
374
-			return;
375
-		}
376
-
377
-		// Only send this email for invoices created via the admin page.
378
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
379
-			return;
380
-		}
381
-
382
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
383
-		$recipient = $invoice->get_email();
384
-
385
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
386
-
387
-	}
388
-
389
-	/**
390
-	 * Checks if an invoice is a payment form invoice.
391
-	 *
392
-	 * @param int $invoice
393
-	 * @return bool
394
-	 */
395
-	public function is_payment_form_invoice( $invoice ) {
396
-		$created_via             = get_post_meta( $invoice, 'wpinv_created_via', true );
397
-		$is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via;
398
-		$is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
399
-		return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice;
400
-	}
401
-
402
-	/**
403
-	 * Notifies admin about new invoice notes
404
-	 *
405
-	 * @param WPInv_Invoice $invoice
406
-	 * @param string $note
407
-	 */
408
-	public function user_note( $invoice, $note ) {
409
-
410
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
411
-		$recipient = $invoice->get_email();
412
-
413
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
414
-
415
-	}
416
-
417
-	/**
418
-	 * (Force) Sends overdue notices.
419
-	 *
420
-	 * @param WPInv_Invoice $invoice
421
-	 */
422
-	public function force_send_overdue_notice( $invoice ) {
423
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
424
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
425
-	}
426
-
427
-	/**
428
-	 * Sends overdue notices.
429
-	 *
430
-	 * @TODO: Create an invoices query class.
431
-	 */
432
-	public function overdue() {
433
-		global $wpdb;
434
-
435
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
436
-
437
-		// Fetch reminder days.
438
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
439
-
440
-		// Abort if non is set.
441
-		if ( empty( $reminder_days ) ) {
442
-			return;
443
-		}
444
-
445
-		// Retrieve date query.
446
-		$date_query = $this->get_date_query( $reminder_days );
447
-
448
-		// Invoices table.
449
-		$table = $wpdb->prefix . 'getpaid_invoices';
450
-
451
-		// Fetch invoices.
452
-		$invoices  = $wpdb->get_col(
453
-			"SELECT posts.ID FROM $wpdb->posts as posts
181
+        $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
+        if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
183
+            return;
184
+        }
185
+
186
+        $mailer     = new GetPaid_Notification_Email_Sender();
187
+        $merge_tags = $email->get_merge_tags();
188
+
189
+        $result = $mailer->send(
190
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
+            $email->get_content( $merge_tags, $extra_args ),
193
+            $email->get_attachments()
194
+        );
195
+
196
+        // Maybe send a copy to the admin.
197
+        if ( $email->include_admin_bcc() ) {
198
+            $mailer->send(
199
+                wpinv_get_admin_email(),
200
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
+                $email->get_content( $merge_tags ),
202
+                $email->get_attachments()
203
+            );
204
+        }
205
+
206
+        if ( $result ) {
207
+            $invoice->add_system_note(
208
+                sprintf(
209
+                    // translators: %1 is the email type, %2 is the invoice recipient.
210
+                    __( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
211
+                    sanitize_key( $type ),
212
+                    $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
213
+                )
214
+            );
215
+        } else {
216
+            $invoice->add_system_note(
217
+                sprintf(
218
+                    // translators: %1 is the email type, %2 is the invoice recipient.
219
+                    __( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
220
+                    sanitize_key( $type ),
221
+                    $email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
222
+                )
223
+            );
224
+        }
225
+
226
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
+
228
+        return $result;
229
+    }
230
+
231
+    /**
232
+     * Also send emails to any cc users.
233
+     *
234
+     * @param array $recipients
235
+     * @param GetPaid_Notification_Email $email
236
+     */
237
+    public function filter_email_recipients( $recipients, $email ) {
238
+
239
+        if ( ! $email->is_admin_email() ) {
240
+            $cc   = $email->object->get_email_cc();
241
+            $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
+
243
+            if ( ! empty( $cc ) ) {
244
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
246
+            }
247
+
248
+            if ( ! empty( $cc_2 ) ) {
249
+                $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
251
+            }
252
+        }
253
+
254
+        return $recipients;
255
+
256
+    }
257
+
258
+    /**
259
+     * Sends a new invoice notification.
260
+     *
261
+     * @param WPInv_Invoice $invoice
262
+     */
263
+    public function new_invoice( $invoice ) {
264
+
265
+        // Only send this email for invoices created via the admin page.
266
+        if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
267
+            return;
268
+        }
269
+
270
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
+        $recipient = wpinv_get_admin_email();
272
+
273
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274
+
275
+    }
276
+
277
+    /**
278
+     * Sends a cancelled invoice notification.
279
+     *
280
+     * @param WPInv_Invoice $invoice
281
+     */
282
+    public function cancelled_invoice( $invoice ) {
283
+
284
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
+        $recipient = $invoice->get_email();
286
+
287
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288
+    }
289
+
290
+    /**
291
+     * Sends a failed invoice notification.
292
+     *
293
+     * @param WPInv_Invoice $invoice
294
+     */
295
+    public function failed_invoice( $invoice ) {
296
+
297
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
+        $recipient = wpinv_get_admin_email();
299
+
300
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301
+
302
+    }
303
+
304
+    /**
305
+     * Sends a notification whenever an invoice is put on hold.
306
+     *
307
+     * @param WPInv_Invoice $invoice
308
+     */
309
+    public function onhold_invoice( $invoice ) {
310
+
311
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
312
+        $recipient = $invoice->get_email();
313
+
314
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
315
+
316
+    }
317
+
318
+    /**
319
+     * Sends a notification whenever an invoice is marked as processing payment.
320
+     *
321
+     * @param WPInv_Invoice $invoice
322
+     */
323
+    public function processing_invoice( $invoice ) {
324
+
325
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
326
+        $recipient = $invoice->get_email();
327
+
328
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
329
+
330
+    }
331
+
332
+    /**
333
+     * Sends a notification whenever an invoice is paid.
334
+     *
335
+     * @param WPInv_Invoice $invoice
336
+     */
337
+    public function completed_invoice( $invoice ) {
338
+
339
+        // (Maybe) abort if it is a renewal invoice.
340
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
341
+            return;
342
+        }
343
+
344
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
345
+        $recipient = $invoice->get_email();
346
+
347
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
348
+
349
+    }
350
+
351
+    /**
352
+     * Sends a notification whenever an invoice is refunded.
353
+     *
354
+     * @param WPInv_Invoice $invoice
355
+     */
356
+    public function refunded_invoice( $invoice ) {
357
+
358
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
359
+        $recipient = $invoice->get_email();
360
+
361
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
362
+
363
+    }
364
+
365
+    /**
366
+     * Notifies a user about new invoices
367
+     *
368
+     * @param WPInv_Invoice $invoice
369
+     * @param bool $force
370
+     */
371
+    public function user_invoice( $invoice, $force = false ) {
372
+
373
+        if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
374
+            return;
375
+        }
376
+
377
+        // Only send this email for invoices created via the admin page.
378
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
379
+            return;
380
+        }
381
+
382
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
383
+        $recipient = $invoice->get_email();
384
+
385
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
386
+
387
+    }
388
+
389
+    /**
390
+     * Checks if an invoice is a payment form invoice.
391
+     *
392
+     * @param int $invoice
393
+     * @return bool
394
+     */
395
+    public function is_payment_form_invoice( $invoice ) {
396
+        $created_via             = get_post_meta( $invoice, 'wpinv_created_via', true );
397
+        $is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via;
398
+        $is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
399
+        return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice;
400
+    }
401
+
402
+    /**
403
+     * Notifies admin about new invoice notes
404
+     *
405
+     * @param WPInv_Invoice $invoice
406
+     * @param string $note
407
+     */
408
+    public function user_note( $invoice, $note ) {
409
+
410
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
411
+        $recipient = $invoice->get_email();
412
+
413
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
414
+
415
+    }
416
+
417
+    /**
418
+     * (Force) Sends overdue notices.
419
+     *
420
+     * @param WPInv_Invoice $invoice
421
+     */
422
+    public function force_send_overdue_notice( $invoice ) {
423
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
424
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
425
+    }
426
+
427
+    /**
428
+     * Sends overdue notices.
429
+     *
430
+     * @TODO: Create an invoices query class.
431
+     */
432
+    public function overdue() {
433
+        global $wpdb;
434
+
435
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
436
+
437
+        // Fetch reminder days.
438
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
439
+
440
+        // Abort if non is set.
441
+        if ( empty( $reminder_days ) ) {
442
+            return;
443
+        }
444
+
445
+        // Retrieve date query.
446
+        $date_query = $this->get_date_query( $reminder_days );
447
+
448
+        // Invoices table.
449
+        $table = $wpdb->prefix . 'getpaid_invoices';
450
+
451
+        // Fetch invoices.
452
+        $invoices  = $wpdb->get_col(
453
+            "SELECT posts.ID FROM $wpdb->posts as posts
454 454
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
455 455
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"
456 456
         );
457 457
 
458
-		foreach ( $invoices as $invoice ) {
458
+        foreach ( $invoices as $invoice ) {
459 459
 
460
-			// Only send this email for invoices created via the admin page.
461
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
462
-				$invoice       = new WPInv_Invoice( $invoice );
463
-				$email->object = $invoice;
460
+            // Only send this email for invoices created via the admin page.
461
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
462
+                $invoice       = new WPInv_Invoice( $invoice );
463
+                $email->object = $invoice;
464 464
 
465
-				if ( $invoice->needs_payment() ) {
466
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
467
-				}
465
+                if ( $invoice->needs_payment() ) {
466
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
467
+                }
468 468
 }
469 469
 }
470 470
 
471
-	}
471
+    }
472 472
 
473
-	/**
474
-	 * Calculates the date query for an invoices query
475
-	 *
476
-	 * @param array $reminder_days
477
-	 * @return string
478
-	 */
479
-	public function get_date_query( $reminder_days ) {
473
+    /**
474
+     * Calculates the date query for an invoices query
475
+     *
476
+     * @param array $reminder_days
477
+     * @return string
478
+     */
479
+    public function get_date_query( $reminder_days ) {
480 480
 
481
-		$date_query = array(
482
-			'relation' => 'OR',
483
-		);
481
+        $date_query = array(
482
+            'relation' => 'OR',
483
+        );
484 484
 
485
-		foreach ( $reminder_days as $days ) {
486
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
485
+        foreach ( $reminder_days as $days ) {
486
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
487 487
 
488
-			$date_query[] = array(
489
-				'year'  => $date['year'],
490
-				'month' => $date['month'],
491
-				'day'   => $date['day'],
492
-			);
488
+            $date_query[] = array(
489
+                'year'  => $date['year'],
490
+                'month' => $date['month'],
491
+                'day'   => $date['day'],
492
+            );
493 493
 
494
-		}
494
+        }
495 495
 
496
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
496
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
497 497
 
498
-		return $date_query->get_sql();
498
+        return $date_query->get_sql();
499 499
 
500
-	}
500
+    }
501 501
 
502 502
 }
Please login to merge, or discard this patch.
Spacing   +126 added lines, -126 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',
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function init_hooks() {
52 52
 
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
53
+		add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2);
54
+		add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2);
55 55
 
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
56
+		foreach ($this->invoice_actions as $hook => $email_type) {
57
+			$this->init_email_type_hook($hook, $email_type);
58 58
 		}
59 59
 	}
60 60
 
@@ -64,25 +64,25 @@  discard block
 block discarded – undo
64 64
 	 * @param string $hook
65 65
 	 * @param string|array $email_type
66 66
 	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
67
+	public function init_email_type_hook($hook, $email_type) {
68 68
 
69
-		$email_type = wpinv_parse_list( $email_type );
69
+		$email_type = wpinv_parse_list($email_type);
70 70
 
71
-		foreach ( $email_type as $type ) {
71
+		foreach ($email_type as $type) {
72 72
 
73
-			$email = new GetPaid_Notification_Email( $type );
73
+			$email = new GetPaid_Notification_Email($type);
74 74
 
75 75
 			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
76
+			if (!$email->is_active()) {
77 77
 				continue;
78 78
 			}
79 79
 
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
80
+			if (method_exists($this, $type)) {
81
+				add_action($hook, array($this, $type), 100, 2);
82 82
 				continue;
83 83
 			}
84 84
 
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
85
+			do_action('getpaid_invoice_init_email_type_hook', $type, $hook);
86 86
 		}
87 87
 
88 88
 	}
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
 	 * @param array $merge_tags
94 94
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95 95
 	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
96
+	public function invoice_merge_tags($merge_tags, $object) {
97 97
 
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
98
+		if (is_a($object, 'WPInv_Invoice')) {
99 99
 			return array_merge(
100 100
 				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
101
+				$this->get_invoice_merge_tags($object)
102 102
 			);
103 103
 		}
104 104
 
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
105
+		if (is_a($object, 'WPInv_Subscription')) {
106 106
 			return array_merge(
107 107
 				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
108
+				$this->get_invoice_merge_tags($object->get_parent_payment())
109 109
 			);
110 110
 		}
111 111
 
@@ -119,50 +119,50 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return array
121 121
 	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
122
+	public function get_invoice_merge_tags($invoice) {
123 123
 
124 124
 		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
125
+		if (!$invoice->get_id()) {
126 126
 			return array();
127 127
 		}
128 128
 
129 129
 		$merge_tags = array(
130
-			'{name}'                 => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'           => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'            => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'                => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'       => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'     => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'        => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'         => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'     => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}' => esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'         => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'     => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'        => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'        => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}'  => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'    => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'               => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
130
+			'{name}'                 => sanitize_text_field($invoice->get_user_full_name()),
131
+			'{full_name}'            => sanitize_text_field($invoice->get_user_full_name()),
132
+			'{first_name}'           => sanitize_text_field($invoice->get_first_name()),
133
+			'{last_name}'            => sanitize_text_field($invoice->get_last_name()),
134
+			'{email}'                => sanitize_email($invoice->get_email()),
135
+			'{invoice_number}'       => sanitize_text_field($invoice->get_number()),
136
+			'{invoice_currency}'     => sanitize_text_field($invoice->get_currency()),
137
+			'{invoice_total}'        => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())),
138
+			'{invoice_link}'         => esc_url($invoice->get_view_url()),
139
+			'{invoice_pay_link}'     => esc_url($invoice->get_checkout_payment_url()),
140
+			'{invoice_receipt_link}' => esc_url($invoice->get_receipt_url()),
141
+			'{invoice_date}'         => getpaid_format_date_value($invoice->get_date_created()),
142
+			'{invoice_due_date}'     => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')),
143
+			'{invoice_quote}'        => sanitize_text_field(strtolower($invoice->get_label())),
144
+			'{invoice_label}'        => sanitize_text_field(ucfirst($invoice->get_label())),
145
+			'{invoice_description}'  => wp_kses_post($invoice->get_description()),
146
+			'{subscription_name}'    => wp_kses_post($invoice->get_subscription_name()),
147
+			'{is_was}'               => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
148 148
 		);
149 149
 
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
150
+		$payment_form_data = $invoice->get_meta('payment_form_data', true);
151 151
 
152
-		if ( is_array( $payment_form_data ) ) {
152
+		if (is_array($payment_form_data)) {
153 153
 
154
-			foreach ( $payment_form_data as $label => $value ) {
154
+			foreach ($payment_form_data as $label => $value) {
155 155
 
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
156
+				$label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label));
157
+				$value = is_array($value) ? implode(', ', $value) : $value;
158 158
 
159
-				if ( is_scalar( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
159
+				if (is_scalar($value)) {
160
+					$merge_tags["{{$label}}"] = wp_kses_post($value);
161 161
 				}
162 162
 			}
163 163
 		}
164 164
 
165
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
165
+		return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice);
166 166
 	}
167 167
 
168 168
 	/**
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 	 * @param string|array $recipients
175 175
 	 * @param array $extra_args Extra template args.
176 176
 	 */
177
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
177
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
178 178
 
179
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
179
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
180 180
 
181
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
182
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
181
+		$skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice');
182
+		if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) {
183 183
 			return;
184 184
 		}
185 185
 
@@ -187,43 +187,43 @@  discard block
 block discarded – undo
187 187
 		$merge_tags = $email->get_merge_tags();
188 188
 
189 189
 		$result = $mailer->send(
190
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
191
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
192
-			$email->get_content( $merge_tags, $extra_args ),
190
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
191
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
192
+			$email->get_content($merge_tags, $extra_args),
193 193
 			$email->get_attachments()
194 194
 		);
195 195
 
196 196
 		// Maybe send a copy to the admin.
197
-		if ( $email->include_admin_bcc() ) {
197
+		if ($email->include_admin_bcc()) {
198 198
 			$mailer->send(
199 199
 				wpinv_get_admin_email(),
200
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
201
-				$email->get_content( $merge_tags ),
200
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
201
+				$email->get_content($merge_tags),
202 202
 				$email->get_attachments()
203 203
 			);
204 204
 		}
205 205
 
206
-		if ( $result ) {
206
+		if ($result) {
207 207
 			$invoice->add_system_note(
208 208
 				sprintf(
209 209
 					// translators: %1 is the email type, %2 is the invoice recipient.
210
-					__( 'Successfully sent %1$s notification email to %2$s.', 'invoicing' ),
211
-					sanitize_key( $type ),
212
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
210
+					__('Successfully sent %1$s notification email to %2$s.', 'invoicing'),
211
+					sanitize_key($type),
212
+					$email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing')
213 213
 				)
214 214
 			);
215 215
 		} else {
216 216
 			$invoice->add_system_note(
217 217
 				sprintf(
218 218
 					// translators: %1 is the email type, %2 is the invoice recipient.
219
-					__( 'Failed sending %1$s notification email to %2$s.', 'invoicing' ),
220
-					sanitize_key( $type ),
221
-					$email->is_admin_email() ? __( 'admin', 'invoicing' ) : __( 'the customer', 'invoicing' )
219
+					__('Failed sending %1$s notification email to %2$s.', 'invoicing'),
220
+					sanitize_key($type),
221
+					$email->is_admin_email() ? __('admin', 'invoicing') : __('the customer', 'invoicing')
222 222
 				)
223 223
 			);
224 224
 		}
225 225
 
226
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
226
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
227 227
 
228 228
 		return $result;
229 229
 	}
@@ -234,20 +234,20 @@  discard block
 block discarded – undo
234 234
 	 * @param array $recipients
235 235
 	 * @param GetPaid_Notification_Email $email
236 236
 	 */
237
-	public function filter_email_recipients( $recipients, $email ) {
237
+	public function filter_email_recipients($recipients, $email) {
238 238
 
239
-		if ( ! $email->is_admin_email() ) {
239
+		if (!$email->is_admin_email()) {
240 240
 			$cc   = $email->object->get_email_cc();
241
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
241
+			$cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true);
242 242
 
243
-			if ( ! empty( $cc ) ) {
244
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
243
+			if (!empty($cc)) {
244
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
245
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
246 246
 			}
247 247
 
248
-			if ( ! empty( $cc_2 ) ) {
249
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
248
+			if (!empty($cc_2)) {
249
+				$cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2));
250
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc_2)));
251 251
 			}
252 252
 		}
253 253
 
@@ -260,17 +260,17 @@  discard block
 block discarded – undo
260 260
 	 *
261 261
 	 * @param WPInv_Invoice $invoice
262 262
 	 */
263
-	public function new_invoice( $invoice ) {
263
+	public function new_invoice($invoice) {
264 264
 
265 265
 		// Only send this email for invoices created via the admin page.
266
-		if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
266
+		if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) {
267 267
 			return;
268 268
 		}
269 269
 
270
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
270
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
271 271
 		$recipient = wpinv_get_admin_email();
272 272
 
273
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
273
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
274 274
 
275 275
 	}
276 276
 
@@ -279,12 +279,12 @@  discard block
 block discarded – undo
279 279
 	 *
280 280
 	 * @param WPInv_Invoice $invoice
281 281
 	 */
282
-	public function cancelled_invoice( $invoice ) {
282
+	public function cancelled_invoice($invoice) {
283 283
 
284
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
284
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
285 285
 		$recipient = $invoice->get_email();
286 286
 
287
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
287
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
288 288
 	}
289 289
 
290 290
 	/**
@@ -292,12 +292,12 @@  discard block
 block discarded – undo
292 292
 	 *
293 293
 	 * @param WPInv_Invoice $invoice
294 294
 	 */
295
-	public function failed_invoice( $invoice ) {
295
+	public function failed_invoice($invoice) {
296 296
 
297
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
297
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
298 298
 		$recipient = wpinv_get_admin_email();
299 299
 
300
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
300
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
301 301
 
302 302
 	}
303 303
 
@@ -306,12 +306,12 @@  discard block
 block discarded – undo
306 306
 	 *
307 307
 	 * @param WPInv_Invoice $invoice
308 308
 	 */
309
-	public function onhold_invoice( $invoice ) {
309
+	public function onhold_invoice($invoice) {
310 310
 
311
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
311
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
312 312
 		$recipient = $invoice->get_email();
313 313
 
314
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
314
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
315 315
 
316 316
 	}
317 317
 
@@ -320,12 +320,12 @@  discard block
 block discarded – undo
320 320
 	 *
321 321
 	 * @param WPInv_Invoice $invoice
322 322
 	 */
323
-	public function processing_invoice( $invoice ) {
323
+	public function processing_invoice($invoice) {
324 324
 
325
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
325
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
326 326
 		$recipient = $invoice->get_email();
327 327
 
328
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
328
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
329 329
 
330 330
 	}
331 331
 
@@ -334,17 +334,17 @@  discard block
 block discarded – undo
334 334
 	 *
335 335
 	 * @param WPInv_Invoice $invoice
336 336
 	 */
337
-	public function completed_invoice( $invoice ) {
337
+	public function completed_invoice($invoice) {
338 338
 
339 339
 		// (Maybe) abort if it is a renewal invoice.
340
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
340
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
341 341
 			return;
342 342
 		}
343 343
 
344
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
344
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
345 345
 		$recipient = $invoice->get_email();
346 346
 
347
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
347
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
348 348
 
349 349
 	}
350 350
 
@@ -353,12 +353,12 @@  discard block
 block discarded – undo
353 353
 	 *
354 354
 	 * @param WPInv_Invoice $invoice
355 355
 	 */
356
-	public function refunded_invoice( $invoice ) {
356
+	public function refunded_invoice($invoice) {
357 357
 
358
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
358
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
359 359
 		$recipient = $invoice->get_email();
360 360
 
361
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
361
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
362 362
 
363 363
 	}
364 364
 
@@ -368,21 +368,21 @@  discard block
 block discarded – undo
368 368
 	 * @param WPInv_Invoice $invoice
369 369
 	 * @param bool $force
370 370
 	 */
371
-	public function user_invoice( $invoice, $force = false ) {
371
+	public function user_invoice($invoice, $force = false) {
372 372
 
373
-		if ( ! $force && ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
373
+		if (!$force && !empty($GLOBALS['wpinv_skip_invoice_notification'])) {
374 374
 			return;
375 375
 		}
376 376
 
377 377
 		// Only send this email for invoices created via the admin page.
378
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $invoice->is_paid() ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
378
+		if (!$invoice->is_type('invoice') || (empty($force) && $invoice->is_paid()) || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) {
379 379
 			return;
380 380
 		}
381 381
 
382
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
382
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
383 383
 		$recipient = $invoice->get_email();
384 384
 
385
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
385
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
386 386
 
387 387
 	}
388 388
 
@@ -392,11 +392,11 @@  discard block
 block discarded – undo
392 392
 	 * @param int $invoice
393 393
 	 * @return bool
394 394
 	 */
395
-	public function is_payment_form_invoice( $invoice ) {
396
-		$created_via             = get_post_meta( $invoice, 'wpinv_created_via', true );
395
+	public function is_payment_form_invoice($invoice) {
396
+		$created_via             = get_post_meta($invoice, 'wpinv_created_via', true);
397 397
 		$is_payment_form_invoice = 'payment_form' === $created_via || 'geodirectory' === $created_via;
398
-		$is_payment_form_invoice = apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
399
-		return empty( $_GET['getpaid-admin-action'] ) && $is_payment_form_invoice;
398
+		$is_payment_form_invoice = apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice);
399
+		return empty($_GET['getpaid-admin-action']) && $is_payment_form_invoice;
400 400
 	}
401 401
 
402 402
 	/**
@@ -405,12 +405,12 @@  discard block
 block discarded – undo
405 405
 	 * @param WPInv_Invoice $invoice
406 406
 	 * @param string $note
407 407
 	 */
408
-	public function user_note( $invoice, $note ) {
408
+	public function user_note($invoice, $note) {
409 409
 
410
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
410
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
411 411
 		$recipient = $invoice->get_email();
412 412
 
413
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
413
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
414 414
 
415 415
 	}
416 416
 
@@ -419,9 +419,9 @@  discard block
 block discarded – undo
419 419
 	 *
420 420
 	 * @param WPInv_Invoice $invoice
421 421
 	 */
422
-	public function force_send_overdue_notice( $invoice ) {
423
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
424
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
422
+	public function force_send_overdue_notice($invoice) {
423
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
424
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
425 425
 	}
426 426
 
427 427
 	/**
@@ -432,38 +432,38 @@  discard block
 block discarded – undo
432 432
 	public function overdue() {
433 433
 		global $wpdb;
434 434
 
435
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
435
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
436 436
 
437 437
 		// Fetch reminder days.
438
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
438
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
439 439
 
440 440
 		// Abort if non is set.
441
-		if ( empty( $reminder_days ) ) {
441
+		if (empty($reminder_days)) {
442 442
 			return;
443 443
 		}
444 444
 
445 445
 		// Retrieve date query.
446
-		$date_query = $this->get_date_query( $reminder_days );
446
+		$date_query = $this->get_date_query($reminder_days);
447 447
 
448 448
 		// Invoices table.
449 449
 		$table = $wpdb->prefix . 'getpaid_invoices';
450 450
 
451 451
 		// Fetch invoices.
452
-		$invoices  = $wpdb->get_col(
452
+		$invoices = $wpdb->get_col(
453 453
 			"SELECT posts.ID FROM $wpdb->posts as posts
454 454
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
455 455
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"
456 456
         );
457 457
 
458
-		foreach ( $invoices as $invoice ) {
458
+		foreach ($invoices as $invoice) {
459 459
 
460 460
 			// Only send this email for invoices created via the admin page.
461
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
462
-				$invoice       = new WPInv_Invoice( $invoice );
461
+			if (!$this->is_payment_form_invoice($invoice)) {
462
+				$invoice       = new WPInv_Invoice($invoice);
463 463
 				$email->object = $invoice;
464 464
 
465
-				if ( $invoice->needs_payment() ) {
466
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
465
+				if ($invoice->needs_payment()) {
466
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
467 467
 				}
468 468
 }
469 469
 }
@@ -476,14 +476,14 @@  discard block
 block discarded – undo
476 476
 	 * @param array $reminder_days
477 477
 	 * @return string
478 478
 	 */
479
-	public function get_date_query( $reminder_days ) {
479
+	public function get_date_query($reminder_days) {
480 480
 
481 481
 		$date_query = array(
482 482
 			'relation' => 'OR',
483 483
 		);
484 484
 
485
-		foreach ( $reminder_days as $days ) {
486
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
485
+		foreach ($reminder_days as $days) {
486
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
487 487
 
488 488
 			$date_query[] = array(
489 489
 				'year'  => $date['year'],
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
 
494 494
 		}
495 495
 
496
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
496
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
497 497
 
498 498
 		return $date_query->get_sql();
499 499
 
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves an item by it's ID.
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
  * @param int the item ID to retrieve.
15 15
  * @return WPInv_Item|false
16 16
  */
17
-function wpinv_get_item_by_id( $id ) {
18
-    $item = wpinv_get_item( $id );
19
-    return empty( $item ) || $id != $item->get_id() ? false : $item;
17
+function wpinv_get_item_by_id($id) {
18
+    $item = wpinv_get_item($id);
19
+    return empty($item) || $id != $item->get_id() ? false : $item;
20 20
 }
21 21
 
22 22
 /**
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
  *
25 25
  * @return WPInv_Item|false
26 26
  */
27
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
27
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
28 28
 
29
-    if ( 'id' == strtolower( $field ) ) {
30
-        return wpinv_get_item_by_id( $field );
29
+    if ('id' == strtolower($field)) {
30
+        return wpinv_get_item_by_id($field);
31 31
     }
32 32
 
33
-    $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type );
34
-    return empty( $id ) ? false : wpinv_get_item( $id );
33
+    $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type);
34
+    return empty($id) ? false : wpinv_get_item($id);
35 35
 
36 36
 }
37 37
 
@@ -41,24 +41,24 @@  discard block
 block discarded – undo
41 41
  * @param int|WPInv_Item the item to retrieve.
42 42
  * @return WPInv_Item|false
43 43
  */
44
-function wpinv_get_item( $item = 0 ) {
44
+function wpinv_get_item($item = 0) {
45 45
 
46
-    if ( empty( $item ) ) {
46
+    if (empty($item)) {
47 47
         return false;
48 48
     }
49 49
 
50
-    $item = new WPInv_Item( $item );
50
+    $item = new WPInv_Item($item);
51 51
     return $item->exists() ? $item : false;
52 52
 
53 53
 }
54 54
 
55
-function wpinv_get_all_items( $args = array() ) {
55
+function wpinv_get_all_items($args = array()) {
56 56
 
57 57
     $args = wp_parse_args(
58 58
         $args,
59 59
         array(
60
-			'status'     => array( 'publish' ),
61
-			'limit'      => get_option( 'posts_per_page' ),
60
+			'status'     => array('publish'),
61
+			'limit'      => get_option('posts_per_page'),
62 62
 			'page'       => 1,
63 63
 			'exclude'    => array(),
64 64
 			'orderby'    => 'date',
@@ -78,44 +78,44 @@  discard block
 block discarded – undo
78 78
         'fields'         => 'ids',
79 79
         'orderby'        => $args['orderby'],
80 80
         'order'          => $args['order'],
81
-        'paged'          => absint( $args['page'] ),
81
+        'paged'          => absint($args['page']),
82 82
     );
83 83
 
84
-    if ( ! empty( $args['exclude'] ) ) {
85
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
84
+    if (!empty($args['exclude'])) {
85
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
86 86
     }
87 87
 
88
-    if ( ! $args['paginate'] ) {
88
+    if (!$args['paginate']) {
89 89
         $wp_query_args['no_found_rows'] = true;
90 90
     }
91 91
 
92
-    if ( ! empty( $args['search'] ) ) {
92
+    if (!empty($args['search'])) {
93 93
         $wp_query_args['s'] = $args['search'];
94 94
     }
95 95
 
96
-    if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) {
97
-        $types = wpinv_parse_list( $args['type'] );
96
+    if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) {
97
+        $types = wpinv_parse_list($args['type']);
98 98
         $wp_query_args['meta_query'][] = array(
99 99
             'key'     => '_wpinv_type',
100
-            'value'   => implode( ',', $types ),
100
+            'value'   => implode(',', $types),
101 101
             'compare' => 'IN',
102 102
         );
103 103
     }
104 104
 
105
-    $wp_query_args = apply_filters( 'wpinv_get_items_args', $wp_query_args, $args );
105
+    $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args);
106 106
 
107 107
     // Get results.
108
-    $items = new WP_Query( $wp_query_args );
108
+    $items = new WP_Query($wp_query_args);
109 109
 
110
-    if ( 'objects' === $args['return'] ) {
111
-        $return = array_map( 'wpinv_get_item_by_id', $items->posts );
112
-    } elseif ( 'self' === $args['return'] ) {
110
+    if ('objects' === $args['return']) {
111
+        $return = array_map('wpinv_get_item_by_id', $items->posts);
112
+    } elseif ('self' === $args['return']) {
113 113
         return $items;
114 114
     } else {
115 115
         $return = $items->posts;
116 116
     }
117 117
 
118
-    if ( $args['paginate'] ) {
118
+    if ($args['paginate']) {
119 119
         return (object) array(
120 120
             'items'         => $return,
121 121
             'total'         => $items->found_posts,
@@ -127,12 +127,12 @@  discard block
 block discarded – undo
127 127
 
128 128
 }
129 129
 
130
-function wpinv_is_free_item( $item_id = 0 ) {
131
-    if ( empty( $item_id ) ) {
130
+function wpinv_is_free_item($item_id = 0) {
131
+    if (empty($item_id)) {
132 132
         return false;
133 133
     }
134 134
 
135
-    $item = new WPInv_Item( $item_id );
135
+    $item = new WPInv_Item($item_id);
136 136
 
137 137
     return $item->is_free();
138 138
 }
@@ -142,21 +142,21 @@  discard block
 block discarded – undo
142 142
  *
143 143
  * @param WP_Post|WPInv_Item|Int $item The item to check for.
144 144
  */
145
-function wpinv_item_is_editable( $item = 0 ) {
145
+function wpinv_item_is_editable($item = 0) {
146 146
 
147 147
     // Fetch the item.
148
-    $item = new WPInv_Item( $item );
148
+    $item = new WPInv_Item($item);
149 149
 
150 150
     // Check if it is editable.
151 151
     return $item->is_editable();
152 152
 }
153 153
 
154
-function wpinv_get_item_price( $item_id = 0 ) {
155
-    if ( empty( $item_id ) ) {
154
+function wpinv_get_item_price($item_id = 0) {
155
+    if (empty($item_id)) {
156 156
         return false;
157 157
     }
158 158
 
159
-    $item = new WPInv_Item( $item_id );
159
+    $item = new WPInv_Item($item_id);
160 160
 
161 161
     return $item->get_price();
162 162
 }
@@ -166,88 +166,88 @@  discard block
 block discarded – undo
166 166
  *
167 167
  * @param WPInv_Item|int $item
168 168
  */
169
-function wpinv_is_recurring_item( $item = 0 ) {
170
-    $item = new WPInv_Item( $item );
169
+function wpinv_is_recurring_item($item = 0) {
170
+    $item = new WPInv_Item($item);
171 171
     return $item->is_recurring();
172 172
 }
173 173
 
174
-function wpinv_item_price( $item_id = 0 ) {
175
-    if ( empty( $item_id ) ) {
174
+function wpinv_item_price($item_id = 0) {
175
+    if (empty($item_id)) {
176 176
         return false;
177 177
     }
178 178
 
179
-    $price = wpinv_get_item_price( $item_id );
180
-    $price = wpinv_price( $price );
179
+    $price = wpinv_get_item_price($item_id);
180
+    $price = wpinv_price($price);
181 181
 
182
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
182
+    return apply_filters('wpinv_item_price', $price, $item_id);
183 183
 }
184 184
 
185
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
186
-    if ( is_null( $amount_override ) ) {
187
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
185
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
186
+    if (is_null($amount_override)) {
187
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
188 188
     } else {
189 189
         $original_price = $amount_override;
190 190
     }
191 191
 
192 192
     $price = $original_price;
193 193
 
194
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
194
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
195 195
 }
196 196
 
197
-function wpinv_item_custom_singular_name( $item_id ) {
198
-    if ( empty( $item_id ) ) {
197
+function wpinv_item_custom_singular_name($item_id) {
198
+    if (empty($item_id)) {
199 199
         return false;
200 200
     }
201 201
 
202
-    $item = new WPInv_Item( $item_id );
202
+    $item = new WPInv_Item($item_id);
203 203
 
204 204
     return $item->get_custom_singular_name();
205 205
 }
206 206
 
207 207
 function wpinv_get_item_types() {
208 208
     $item_types = array(
209
-		'custom' => __( 'Standard', 'invoicing' ),
210
-		'fee'    => __( 'Fee', 'invoicing' ),
209
+		'custom' => __('Standard', 'invoicing'),
210
+		'fee'    => __('Fee', 'invoicing'),
211 211
 	);
212
-    return apply_filters( 'wpinv_get_item_types', $item_types );
212
+    return apply_filters('wpinv_get_item_types', $item_types);
213 213
 }
214 214
 
215 215
 function wpinv_item_types() {
216 216
     $item_types = wpinv_get_item_types();
217 217
 
218
-    return ( ! empty( $item_types ) ? array_keys( $item_types ) : array() );
218
+    return (!empty($item_types) ? array_keys($item_types) : array());
219 219
 }
220 220
 
221
-function wpinv_get_item_type( $item_id ) {
222
-    if ( empty( $item_id ) ) {
221
+function wpinv_get_item_type($item_id) {
222
+    if (empty($item_id)) {
223 223
         return false;
224 224
     }
225 225
 
226
-    $item = new WPInv_Item( $item_id );
226
+    $item = new WPInv_Item($item_id);
227 227
 
228 228
     return $item->get_type();
229 229
 }
230 230
 
231
-function wpinv_item_type( $item_id ) {
231
+function wpinv_item_type($item_id) {
232 232
     $item_types = wpinv_get_item_types();
233 233
 
234
-    $item_type = wpinv_get_item_type( $item_id );
234
+    $item_type = wpinv_get_item_type($item_id);
235 235
 
236
-    if ( empty( $item_type ) ) {
236
+    if (empty($item_type)) {
237 237
         $item_type = '-';
238 238
     }
239 239
 
240
-    $item_type = isset( $item_types[ $item_type ] ) ? $item_types[ $item_type ] : __( $item_type, 'invoicing' );
240
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
241 241
 
242
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
242
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
243 243
 }
244 244
 
245
-function wpinv_get_random_item( $post_ids = true ) {
246
-    wpinv_get_random_items( 1, $post_ids );
245
+function wpinv_get_random_item($post_ids = true) {
246
+    wpinv_get_random_items(1, $post_ids);
247 247
 }
248 248
 
249
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
250
-    if ( $post_ids ) {
249
+function wpinv_get_random_items($num = 3, $post_ids = true) {
250
+    if ($post_ids) {
251 251
         $args = array(
252 252
 			'post_type'  => 'wpi_item',
253 253
 			'orderby'    => 'rand',
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
 		);
263 263
     }
264 264
 
265
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
265
+    $args = apply_filters('wpinv_get_random_items', $args);
266 266
 
267
-    return get_posts( $args );
267
+    return get_posts($args);
268 268
 }
269 269
 
270 270
 /**
@@ -273,13 +273,13 @@  discard block
 block discarded – undo
273 273
  * @param WPInv_Item|int $item
274 274
  * @param bool $html
275 275
  */
276
-function wpinv_get_item_suffix( $item, $html = true ) {
276
+function wpinv_get_item_suffix($item, $html = true) {
277 277
 
278
-    $item   = new WPInv_Item( $item );
279
-    $suffix = $item->is_recurring() ? ' ' . __( '(r)', 'invoicing' ) : '';
280
-    $suffix = $html ? $suffix : wp_strip_all_tags( $suffix );
278
+    $item   = new WPInv_Item($item);
279
+    $suffix = $item->is_recurring() ? ' ' . __('(r)', 'invoicing') : '';
280
+    $suffix = $html ? $suffix : wp_strip_all_tags($suffix);
281 281
 
282
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
282
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
283 283
 }
284 284
 
285 285
 /**
@@ -288,9 +288,9 @@  discard block
 block discarded – undo
288 288
  * @param WPInv_Item|int $item
289 289
  * @param bool $force_delete
290 290
  */
291
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
292
-    $item = new WPInv_Item( $item );
293
-    $item->delete( $force_delete );
291
+function wpinv_remove_item($item = 0, $force_delete = false) {
292
+    $item = new WPInv_Item($item);
293
+    $item->delete($force_delete);
294 294
 }
295 295
 
296 296
 /**
@@ -329,44 +329,44 @@  discard block
 block discarded – undo
329 329
  * @param bool $wp_error whether or not to return a WP_Error on failure.
330 330
  * @return bool|WP_Error|WPInv_Item
331 331
  */
332
-function wpinv_create_item( $args = array(), $wp_error = false ) {
332
+function wpinv_create_item($args = array(), $wp_error = false) {
333 333
 
334 334
     // Prepare the item.
335
-    if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) {
336
-        $type = empty( $args['type'] ) ? 'custom' : $args['type'];
337
-        $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type );
335
+    if (!empty($args['custom_id']) && empty($args['ID'])) {
336
+        $type = empty($args['type']) ? 'custom' : $args['type'];
337
+        $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type);
338 338
 
339
-        if ( ! empty( $item ) ) {
339
+        if (!empty($item)) {
340 340
             $args['ID'] = $item->get_id();
341 341
         }
342 342
     }
343 343
 
344 344
     // Do we have an item?
345
-    if ( ! empty( $args['ID'] ) ) {
346
-        $item = new WPInv_Item( $args['ID'] );
345
+    if (!empty($args['ID'])) {
346
+        $item = new WPInv_Item($args['ID']);
347 347
     } else {
348 348
         $item = new WPInv_Item();
349 349
     }
350 350
 
351 351
     // Do we have an error?
352
-    if ( ! empty( $item->last_error ) ) {
353
-        return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false;
352
+    if (!empty($item->last_error)) {
353
+        return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false;
354 354
     }
355 355
 
356 356
     // Update item props.
357
-    $item->set_props( $args );
357
+    $item->set_props($args);
358 358
 
359 359
     // Save the item.
360 360
     $item->save();
361 361
 
362 362
     // Do we have an error?
363
-    if ( ! empty( $item->last_error ) ) {
364
-        return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false;
363
+    if (!empty($item->last_error)) {
364
+        return $wp_error ? new WP_Error('not_saved', $item->last_error) : false;
365 365
     }
366 366
 
367 367
     // Was the item saved?
368
-    if ( ! $item->get_id() ) {
369
-        return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false;
368
+    if (!$item->get_id()) {
369
+        return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false;
370 370
     }
371 371
 
372 372
     return $item;
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
  *
379 379
  * @see wpinv_create_item()
380 380
  */
381
-function wpinv_update_item( $args = array(), $wp_error = false ) {
382
-    return wpinv_create_item( $args, $wp_error );
381
+function wpinv_update_item($args = array(), $wp_error = false) {
382
+    return wpinv_create_item($args, $wp_error);
383 383
 }
384 384
 
385 385
 /**
386 386
  * Sanitizes a recurring period
387 387
  */
388
-function getpaid_sanitize_recurring_period( $period, $full = false ) {
388
+function getpaid_sanitize_recurring_period($period, $full = false) {
389 389
 
390 390
     $periods = array(
391 391
         'D' => 'day',
@@ -394,16 +394,16 @@  discard block
 block discarded – undo
394 394
         'Y' => 'year',
395 395
     );
396 396
 
397
-    if ( ! isset( $periods[ $period ] ) ) {
397
+    if (!isset($periods[$period])) {
398 398
         $period = 'D';
399 399
     }
400 400
 
401
-    return $full ? $periods[ $period ] : $period;
401
+    return $full ? $periods[$period] : $period;
402 402
 
403 403
 }
404 404
 
405
-function wpinv_item_max_buyable_quantity( $item_id ) {
406
-    return apply_filters( 'wpinv_item_max_buyable_quantity', 5, $item_id );
405
+function wpinv_item_max_buyable_quantity($item_id) {
406
+    return apply_filters('wpinv_item_max_buyable_quantity', 5, $item_id);
407 407
 }
408 408
 
409 409
 /**
@@ -411,47 +411,47 @@  discard block
 block discarded – undo
411 411
  *
412 412
  * @param WPInv_Item|GetPaid_Form_Item $item
413 413
  */
414
-function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) {
414
+function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) {
415 415
 
416 416
     // Abort if it is not recurring.
417
-    if ( ! $item->is_recurring() ) {
417
+    if (!$item->is_recurring()) {
418 418
         return '';
419 419
     }
420 420
 
421
-    $initial_price   = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price;
422
-    $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price;
423
-    $period          = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' );
421
+    $initial_price   = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price;
422
+    $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price;
423
+    $period          = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '');
424 424
     $initial_class   = 'getpaid-item-initial-price';
425 425
     $recurring_class = 'getpaid-item-recurring-price';
426 426
     $bill_times      = $item->get_recurring_limit();
427 427
     $bill_times_less = $bill_times - 1;
428 428
 
429
-    if ( ! empty( $bill_times ) ) {
429
+    if (!empty($bill_times)) {
430 430
 		$bill_times = $item->get_recurring_interval() * $bill_times;
431
-        $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() );
432
-		$bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
431
+        $bill_times_less = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times - $item->get_recurring_interval());
432
+		$bill_times = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times);
433 433
 	}
434 434
 
435
-    if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) {
436
-        $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
437
-        $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency );
435
+    if ($item instanceof GetPaid_Form_Item && false === $_initial_price) {
436
+        $initial_price   = wpinv_price($item->get_sub_total(), $currency);
437
+        $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency);
438 438
     }
439 439
 
440
-    if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) {
441
-        return __( 'Free forever', 'invoicing' );
440
+    if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) {
441
+        return __('Free forever', 'invoicing');
442 442
     }
443 443
 
444 444
     // For free trial items.
445
-    if ( $item->has_free_trial() ) {
446
-        $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() );
445
+    if ($item->has_free_trial()) {
446
+        $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval());
447 447
 
448
-        if ( wpinv_price( 0, $currency ) == $initial_price ) {
448
+        if (wpinv_price(0, $currency) == $initial_price) {
449 449
 
450
-            if ( empty( $bill_times ) ) {
450
+            if (empty($bill_times)) {
451 451
 
452 452
                 return sprintf(
453 453
                     // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period
454
-                    _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ),
454
+                    _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'),
455 455
                     "<span class='getpaid-item-trial-period'>$trial_period</span>",
456 456
                     "<span class='$recurring_class'>$recurring_price</span>",
457 457
                     "<span class='getpaid-item-recurring-period'>$period</span>"
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 
462 462
             return sprintf(
463 463
                 // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period, $4: is the bill times
464
-                _x( 'Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing' ),
464
+                _x('Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing'),
465 465
                 "<span class='getpaid-item-trial-period'>$trial_period</span>",
466 466
                 "<span class='$recurring_class'>$recurring_price</span>",
467 467
                 "<span class='getpaid-item-recurring-period'>$period</span>",
@@ -470,11 +470,11 @@  discard block
 block discarded – undo
470 470
 
471 471
         }
472 472
 
473
-        if ( empty( $bill_times ) ) {
473
+        if (empty($bill_times)) {
474 474
 
475 475
             return sprintf(
476 476
                 // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period
477
-                _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ),
477
+                _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'),
478 478
                 "<span class='$initial_class'>$initial_price</span>",
479 479
                 "<span class='getpaid-item-trial-period'>$trial_period</span>",
480 480
                 "<span class='$recurring_class'>$recurring_price</span>",
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 
486 486
         return sprintf(
487 487
             // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period, $4: is the susbcription bill times
488
-            _x( '%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing' ),
488
+            _x('%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing'),
489 489
             "<span class='$initial_class'>$initial_price</span>",
490 490
             "<span class='getpaid-item-trial-period'>$trial_period</span>",
491 491
             "<span class='$recurring_class'>$recurring_price</span>",
@@ -495,13 +495,13 @@  discard block
 block discarded – undo
495 495
 
496 496
     }
497 497
 
498
-    if ( $initial_price == $recurring_price ) {
498
+    if ($initial_price == $recurring_price) {
499 499
 
500
-        if ( empty( $bill_times ) ) {
500
+        if (empty($bill_times)) {
501 501
 
502 502
             return sprintf(
503 503
                 // translators: $1: is the recurring price, $2: is the susbcription period
504
-                _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ),
504
+                _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'),
505 505
                 "<span class='$recurring_class'>$recurring_price</span>",
506 506
                 "<span class='getpaid-item-recurring-period'>$period</span>"
507 507
             );
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 
511 511
         return sprintf(
512 512
             // translators: $1: is the recurring price, $2: is the susbcription period, $3: is the susbcription bill times
513
-            _x( '%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
513
+            _x('%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'),
514 514
             "<span class='$recurring_class'>$recurring_price</span>",
515 515
             "<span class='getpaid-item-recurring-period'>$period</span>",
516 516
             "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>"
@@ -518,13 +518,13 @@  discard block
 block discarded – undo
518 518
 
519 519
     }
520 520
 
521
-    if ( $initial_price == wpinv_price( 0, $currency ) ) {
521
+    if ($initial_price == wpinv_price(0, $currency)) {
522 522
 
523
-        if ( empty( $bill_times ) ) {
523
+        if (empty($bill_times)) {
524 524
 
525 525
             return sprintf(
526 526
                 // translators: $1: is the recurring period, $2: is the recurring price
527
-                _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ),
527
+                _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'),
528 528
                 "<span class='getpaid-item-recurring-period'>$period</span>",
529 529
                 "<span class='$recurring_class'>$recurring_price</span>"
530 530
             );
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
 
534 534
         return sprintf(
535 535
             // translators: $1: is the recurring period, $2: is the recurring price, $3: is the bill times
536
-            _x( 'Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing' ),
536
+            _x('Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing'),
537 537
             "<span class='getpaid-item-recurring-period'>$period</span>",
538 538
             "<span class='$recurring_class'>$recurring_price</span>",
539 539
             "<span class='getpaid-item-recurring-bill-times'>$bill_times_less</span>"
@@ -541,11 +541,11 @@  discard block
 block discarded – undo
541 541
 
542 542
     }
543 543
 
544
-    if ( empty( $bill_times ) ) {
544
+    if (empty($bill_times)) {
545 545
 
546 546
         return sprintf(
547 547
             // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period
548
-            _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ),
548
+            _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'),
549 549
             "<span class='$initial_class'>$initial_price</span>",
550 550
             "<span class='$recurring_class'>$recurring_price</span>",
551 551
             "<span class='getpaid-item-recurring-period'>$period</span>"
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
 
556 556
     return sprintf(
557 557
         // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period, $4: is the susbcription bill times
558
-        _x( 'Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing' ),
558
+        _x('Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing'),
559 559
         "<span class='$initial_class'>$initial_price</span>",
560 560
         "<span class='$recurring_class'>$recurring_price</span>",
561 561
         "<span class='getpaid-item-recurring-period'>$period</span>",
Please login to merge, or discard this patch.