Passed
Push — master ( 8e2340...fa5b2a )
by Brian
05:03
created
includes/invoice-functions.php 1 patch
Spacing   +344 added lines, -344 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 the current invoice.
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
 function getpaid_get_current_invoice_id() {
15 15
 
16 16
     // Ensure that we have an invoice key.
17
-    if ( empty( $_GET['invoice_key'] ) ) {
17
+    if (empty($_GET['invoice_key'])) {
18 18
         return 0;
19 19
     }
20 20
 
21 21
     // Retrieve an invoice using the key.
22
-    $invoice = new WPInv_Invoice( $_GET['invoice_key'] );
22
+    $invoice = new WPInv_Invoice($_GET['invoice_key']);
23 23
 
24 24
     // Compare the invoice key and the parsed key.
25
-    if ( $invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key'] ) {
25
+    if ($invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key']) {
26 26
         return $invoice->get_id();
27 27
     }
28 28
 
@@ -32,42 +32,42 @@  discard block
 block discarded – undo
32 32
 /**
33 33
  * Checks if the current user cna view an invoice.
34 34
  */
35
-function wpinv_user_can_view_invoice( $invoice ) {
36
-    $invoice = new WPInv_Invoice( $invoice );
35
+function wpinv_user_can_view_invoice($invoice) {
36
+    $invoice = new WPInv_Invoice($invoice);
37 37
 
38 38
     // Abort if the invoice does not exist.
39
-    if ( 0 == $invoice->get_id() ) {
39
+    if (0 == $invoice->get_id()) {
40 40
         return false;
41 41
     }
42 42
 
43 43
     // Don't allow trash, draft status
44
-    if ( $invoice->is_draft() ) {
44
+    if ($invoice->is_draft()) {
45 45
         return false;
46 46
     }
47 47
 
48 48
     // If users are not required to login to check out, compare the invoice keys.
49
-    if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && trim( $_GET['invoice_key'] ) == $invoice->get_key() ) {
49
+    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && trim($_GET['invoice_key']) == $invoice->get_key()) {
50 50
         return true;
51 51
     }
52 52
 
53 53
     // Always enable for admins..
54
-    if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user
54
+    if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->get_id())) { // Admin user
55 55
         return true;
56 56
     }
57 57
 
58 58
     // Else, ensure that this is their invoice.
59
-    if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) {
59
+    if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) {
60 60
         return true;
61 61
     }
62 62
 
63
-    return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice );
63
+    return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice);
64 64
 }
65 65
 
66 66
 /**
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69
-function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
69
+function wpinv_can_view_receipt($invoice) {
70
+	return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice);
71 71
 }
72 72
 
73 73
 /**
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function getpaid_get_invoice_post_types() {
79 79
     $post_types = array(
80
-        'wpi_quote'   => __( 'Quote', 'invoicing' ),
81
-        'wpi_invoice' => __( 'Invoice', 'invoicing' ),
80
+        'wpi_quote'   => __('Quote', 'invoicing'),
81
+        'wpi_invoice' => __('Invoice', 'invoicing'),
82 82
     );
83 83
 
84
-    return apply_filters( 'getpaid_invoice_post_types', $post_types );
84
+    return apply_filters('getpaid_invoice_post_types', $post_types);
85 85
 }
86 86
 
87 87
 /**
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
  * 
91 91
  * @param string $post_type The post type to check for.
92 92
  */
93
-function getpaid_is_invoice_post_type( $post_type ) {
94
-    return is_scalar( $post_type ) && ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() );
93
+function getpaid_is_invoice_post_type($post_type) {
94
+    return is_scalar($post_type) && !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types());
95 95
 }
96 96
 
97 97
 /**
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
102 102
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
103 103
  */
104
-function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) {
105
-    $data[ 'invoice_id' ] = 0;
106
-    return wpinv_insert_invoice( $data, $wp_error );
104
+function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) {
105
+    $data['invoice_id'] = 0;
106
+    return wpinv_insert_invoice($data, $wp_error);
107 107
 }
108 108
 
109 109
 /**
@@ -113,36 +113,36 @@  discard block
 block discarded – undo
113 113
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
114 114
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
115 115
  */
116
-function wpinv_update_invoice( $data = array(), $wp_error = false ) {
116
+function wpinv_update_invoice($data = array(), $wp_error = false) {
117 117
 
118 118
     // Backwards compatibility.
119
-    if ( ! empty( $data['ID'] ) ) {
119
+    if (!empty($data['ID'])) {
120 120
         $data['invoice_id'] = $data['ID'];
121 121
     }
122 122
 
123 123
     // Do we have an invoice id?
124
-    if ( empty( $data['invoice_id'] ) ) {
125
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0;
124
+    if (empty($data['invoice_id'])) {
125
+        return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0;
126 126
     }
127 127
 
128 128
     // Retrieve the invoice.
129
-    $invoice = wpinv_get_invoice( $data['invoice_id'] );
129
+    $invoice = wpinv_get_invoice($data['invoice_id']);
130 130
 
131 131
     // And abort if it does not exist.
132
-    if ( empty( $invoice ) ) {
133
-        return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0;
132
+    if (empty($invoice)) {
133
+        return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0;
134 134
     }
135 135
 
136 136
     // Do not update totals for paid / refunded invoices.
137
-    if ( $invoice->is_paid() || $invoice->is_refunded() ) {
137
+    if ($invoice->is_paid() || $invoice->is_refunded()) {
138 138
 
139
-        if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) {
140
-            return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0;
139
+        if (!empty($data['items']) || !empty($data['cart_details'])) {
140
+            return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0;
141 141
         }
142 142
 
143 143
     }
144 144
 
145
-    return wpinv_insert_invoice( $data, $wp_error );
145
+    return wpinv_insert_invoice($data, $wp_error);
146 146
 
147 147
 }
148 148
 
@@ -153,34 +153,34 @@  discard block
 block discarded – undo
153 153
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
154 154
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
155 155
  */
156
-function wpinv_insert_invoice( $data = array(), $wp_error = false ) {
156
+function wpinv_insert_invoice($data = array(), $wp_error = false) {
157 157
 
158 158
     // Ensure that we have invoice data.
159
-    if ( empty( $data ) ) {
159
+    if (empty($data)) {
160 160
         return false;
161 161
     }
162 162
 
163 163
     // The invoice id will be provided when updating an invoice.
164
-    $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false;
164
+    $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false;
165 165
 
166 166
     // Retrieve the invoice.
167
-    $invoice = new WPInv_Invoice( $data['invoice_id'] );
167
+    $invoice = new WPInv_Invoice($data['invoice_id']);
168 168
 
169 169
     // Do we have an error?
170
-    if ( ! empty( $invoice->last_error ) ) {
171
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0;
170
+    if (!empty($invoice->last_error)) {
171
+        return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0;
172 172
     }
173 173
 
174 174
     // Backwards compatibility (billing address).
175
-    if ( ! empty( $data['user_info'] ) ) {
175
+    if (!empty($data['user_info'])) {
176 176
 
177
-        foreach ( $data['user_info'] as $key => $value ) {
177
+        foreach ($data['user_info'] as $key => $value) {
178 178
 
179
-            if ( $key == 'discounts' ) {
179
+            if ($key == 'discounts') {
180 180
                 $value = (array) $value;
181
-                $data[ 'discount_code' ] = empty( $value ) ? null : $value[0];
181
+                $data['discount_code'] = empty($value) ? null : $value[0];
182 182
             } else {
183
-                $data[ $key ] = $value;
183
+                $data[$key] = $value;
184 184
             }
185 185
 
186 186
         }
@@ -188,30 +188,30 @@  discard block
 block discarded – undo
188 188
     }
189 189
 
190 190
     // Backwards compatibility.
191
-    if ( ! empty( $data['payment_details'] ) ) {
191
+    if (!empty($data['payment_details'])) {
192 192
 
193
-        foreach ( $data['payment_details'] as $key => $value ) {
194
-            $data[ $key ] = $value;
193
+        foreach ($data['payment_details'] as $key => $value) {
194
+            $data[$key] = $value;
195 195
         }
196 196
 
197 197
     }
198 198
 
199 199
     // Set up the owner of the invoice.
200
-    $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id();
200
+    $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id();
201 201
 
202 202
     // Make sure the user exists.
203
-    if ( ! get_userdata( $user_id ) ) {
204
-        return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0;
203
+    if (!get_userdata($user_id)) {
204
+        return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0;
205 205
     }
206 206
 
207
-    $address = wpinv_get_user_address( $user_id );
207
+    $address = wpinv_get_user_address($user_id);
208 208
 
209
-    foreach ( $address as $key => $value ) {
209
+    foreach ($address as $key => $value) {
210 210
 
211
-        if ( $value == '' ) {
212
-            $address[ $key ] = null;
211
+        if ($value == '') {
212
+            $address[$key] = null;
213 213
         } else {
214
-            $address[ $key ] = wpinv_clean( $value );
214
+            $address[$key] = wpinv_clean($value);
215 215
         }
216 216
 
217 217
     }
@@ -222,103 +222,103 @@  discard block
 block discarded – undo
222 222
         array(
223 223
 
224 224
             // Basic info.
225
-            'template'             => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null,
226
-            'email_cc'             => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null,
227
-            'date_created'         => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null,
228
-            'due_date'             => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null,
229
-            'date_completed'       => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null,
230
-            'number'               => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null,
231
-            'key'                  => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null,
232
-            'status'               => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null,
233
-            'post_type'            => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null,
234
-            'user_ip'              => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(),
235
-            'parent_id'            => isset( $data['parent'] ) ? intval( $data['parent'] ) : null,
236
-            'mode'                 => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null,
237
-            'description'          => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null,
225
+            'template'             => isset($data['template']) ? wpinv_clean($data['template']) : null,
226
+            'email_cc'             => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null,
227
+            'date_created'         => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null,
228
+            'due_date'             => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null,
229
+            'date_completed'       => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null,
230
+            'number'               => isset($data['number']) ? wpinv_clean($data['number']) : null,
231
+            'key'                  => isset($data['key']) ? wpinv_clean($data['key']) : null,
232
+            'status'               => isset($data['status']) ? wpinv_clean($data['status']) : null,
233
+            'post_type'            => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null,
234
+            'user_ip'              => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(),
235
+            'parent_id'            => isset($data['parent']) ? intval($data['parent']) : null,
236
+            'mode'                 => isset($data['mode']) ? wpinv_clean($data['mode']) : null,
237
+            'description'          => isset($data['description']) ? wp_kses_post($data['description']) : null,
238 238
 
239 239
             // Payment info.
240
-            'disable_taxes'        => ! empty( $data['disable_taxes'] ),
241
-            'currency'             => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(),
242
-            'gateway'              => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null,
243
-            'transaction_id'       => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null,
244
-            'discount_code'        => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null,
245
-            'payment_form'         => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null,
246
-            'submission_id'        => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null,
247
-            'subscription_id'      => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null,
248
-            'is_viewed'            => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null,
249
-            'fees'                 => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null,
250
-            'discounts'            => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null,
251
-            'taxes'                => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null,
240
+            'disable_taxes'        => !empty($data['disable_taxes']),
241
+            'currency'             => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(),
242
+            'gateway'              => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null,
243
+            'transaction_id'       => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null,
244
+            'discount_code'        => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null,
245
+            'payment_form'         => isset($data['payment_form']) ? intval($data['payment_form']) : null,
246
+            'submission_id'        => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null,
247
+            'subscription_id'      => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null,
248
+            'is_viewed'            => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null,
249
+            'fees'                 => isset($data['fees']) ? wpinv_clean($data['fees']) : null,
250
+            'discounts'            => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null,
251
+            'taxes'                => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null,
252 252
             
253 253
 
254 254
             // Billing details.
255 255
             'user_id'              => $data['user_id'],
256
-            'first_name'           => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'],
257
-            'last_name'            => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'],
258
-            'address'              => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'] ,
259
-            'vat_number'           => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'],
260
-            'company'              => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'],
261
-            'zip'                  => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'],
262
-            'state'                => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'],
263
-            'city'                 => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'],
264
-            'country'              => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'],
265
-            'phone'                => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'],
266
-            'address_confirmed'    => ! empty( $data['address_confirmed'] ),
256
+            'first_name'           => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'],
257
+            'last_name'            => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'],
258
+            'address'              => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'],
259
+            'vat_number'           => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'],
260
+            'company'              => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'],
261
+            'zip'                  => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'],
262
+            'state'                => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'],
263
+            'city'                 => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'],
264
+            'country'              => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'],
265
+            'phone'                => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'],
266
+            'address_confirmed'    => !empty($data['address_confirmed']),
267 267
 
268 268
         )
269 269
 
270 270
     );
271 271
 
272 272
     // Backwards compatibililty.
273
-    if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) {
273
+    if (!empty($data['cart_details']) && is_array($data['cart_details'])) {
274 274
         $data['items'] = array();
275 275
 
276
-        foreach( $data['cart_details'] as $_item ) {
276
+        foreach ($data['cart_details'] as $_item) {
277 277
 
278 278
             // Ensure that we have an item id.
279
-            if ( empty(  $_item['id']  ) ) {
279
+            if (empty($_item['id'])) {
280 280
                 continue;
281 281
             }
282 282
 
283 283
             // Retrieve the item.
284
-            $item = new GetPaid_Form_Item(  $_item['id']  );
284
+            $item = new GetPaid_Form_Item($_item['id']);
285 285
 
286 286
             // Ensure that it is purchasable.
287
-            if ( ! $item->can_purchase() ) {
287
+            if (!$item->can_purchase()) {
288 288
                 continue;
289 289
             }
290 290
 
291 291
             // Set quantity.
292
-            if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) {
293
-                $item->set_quantity( $_item['quantity'] );
292
+            if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) {
293
+                $item->set_quantity($_item['quantity']);
294 294
             }
295 295
 
296 296
             // Set price.
297
-            if ( isset( $_item['item_price'] ) ) {
298
-                $item->set_price( $_item['item_price'] );
297
+            if (isset($_item['item_price'])) {
298
+                $item->set_price($_item['item_price']);
299 299
             }
300 300
 
301
-            if ( isset( $_item['custom_price'] ) ) {
302
-                $item->set_price( $_item['custom_price'] );
301
+            if (isset($_item['custom_price'])) {
302
+                $item->set_price($_item['custom_price']);
303 303
             }
304 304
 
305 305
             // Set name.
306
-            if ( ! empty( $_item['name'] ) ) {
307
-                $item->set_name( $_item['name'] );
306
+            if (!empty($_item['name'])) {
307
+                $item->set_name($_item['name']);
308 308
             }
309 309
 
310 310
             // Set description.
311
-            if ( isset( $_item['description'] ) ) {
312
-                $item->set_custom_description( $_item['description'] );
311
+            if (isset($_item['description'])) {
312
+                $item->set_custom_description($_item['description']);
313 313
             }
314 314
 
315 315
             // Set meta.
316
-            if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) {
316
+            if (isset($_item['meta']) && is_array($_item['meta'])) {
317 317
 
318
-                $item->set_item_meta( $_item['meta'] );
318
+                $item->set_item_meta($_item['meta']);
319 319
 
320
-                if ( isset( $_item['meta']['description'] ) ) {
321
-                    $item->set_custom_description( $_item['meta']['description'] );
320
+                if (isset($_item['meta']['description'])) {
321
+                    $item->set_custom_description($_item['meta']['description']);
322 322
                 }
323 323
 
324 324
             }
@@ -329,14 +329,14 @@  discard block
 block discarded – undo
329 329
     }
330 330
 
331 331
     // Add invoice items.
332
-    if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) {
332
+    if (!empty($data['items']) && is_array($data['items'])) {
333 333
 
334
-        $invoice->set_items( array() );
334
+        $invoice->set_items(array());
335 335
 
336
-        foreach ( $data['items'] as $item ) {
336
+        foreach ($data['items'] as $item) {
337 337
 
338
-            if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) {
339
-                $invoice->add_item( $item );
338
+            if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) {
339
+                $invoice->add_item($item);
340 340
             }
341 341
 
342 342
         }
@@ -347,30 +347,30 @@  discard block
 block discarded – undo
347 347
     $invoice->recalculate_total();
348 348
     $invoice->save();
349 349
 
350
-    if ( ! $invoice->get_id() ) {
351
-        return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0;
350
+    if (!$invoice->get_id()) {
351
+        return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0;
352 352
     }
353 353
 
354 354
     // Add private note.
355
-    if ( ! empty( $data['private_note'] ) ) {
356
-        $invoice->add_note( $data['private_note'] );
355
+    if (!empty($data['private_note'])) {
356
+        $invoice->add_note($data['private_note']);
357 357
     }
358 358
 
359 359
     // User notes.
360
-    if ( !empty( $data['user_note'] ) ) {
361
-        $invoice->add_note( $data['user_note'], true );
360
+    if (!empty($data['user_note'])) {
361
+        $invoice->add_note($data['user_note'], true);
362 362
     }
363 363
 
364 364
     // Created via.
365
-    if ( isset( $data['created_via'] ) ) {
366
-        update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] );
365
+    if (isset($data['created_via'])) {
366
+        update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']);
367 367
     }
368 368
 
369 369
     // Backwards compatiblity.
370
-    if ( $invoice->is_quote() ) {
370
+    if ($invoice->is_quote()) {
371 371
 
372
-        if ( isset( $data['valid_until'] ) ) {
373
-            update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] );
372
+        if (isset($data['valid_until'])) {
373
+            update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']);
374 374
         }
375 375
         return $invoice;
376 376
 
@@ -385,18 +385,18 @@  discard block
 block discarded – undo
385 385
  * @param $bool $deprecated
386 386
  * @return WPInv_Invoice|null
387 387
  */
388
-function wpinv_get_invoice( $invoice = 0, $deprecated = false ) {
388
+function wpinv_get_invoice($invoice = 0, $deprecated = false) {
389 389
 
390 390
     // If we are retrieving the invoice from the cart...
391
-    if ( $deprecated && empty( $invoice ) ) {
391
+    if ($deprecated && empty($invoice)) {
392 392
         $invoice = (int) getpaid_get_current_invoice_id();
393 393
     }
394 394
 
395 395
     // Retrieve the invoice.
396
-    $invoice = new WPInv_Invoice( $invoice );
396
+    $invoice = new WPInv_Invoice($invoice);
397 397
 
398 398
     // Check if it exists.
399
-    if ( $invoice->get_id() != 0 ) {
399
+    if ($invoice->get_id() != 0) {
400 400
         return $invoice;
401 401
     }
402 402
 
@@ -409,15 +409,15 @@  discard block
 block discarded – undo
409 409
  * @param array $args Args to search for.
410 410
  * @return WPInv_Invoice[]|int[]|object
411 411
  */
412
-function wpinv_get_invoices( $args ) {
412
+function wpinv_get_invoices($args) {
413 413
 
414 414
     // Prepare args.
415 415
     $args = wp_parse_args(
416 416
         $args,
417 417
         array(
418
-            'status'   => array_keys( wpinv_get_invoice_statuses() ),
418
+            'status'   => array_keys(wpinv_get_invoice_statuses()),
419 419
             'type'     => 'wpi_invoice',
420
-            'limit'    => get_option( 'posts_per_page' ),
420
+            'limit'    => get_option('posts_per_page'),
421 421
             'return'   => 'objects',
422 422
         )
423 423
     );
@@ -435,24 +435,24 @@  discard block
 block discarded – undo
435 435
         'post__in'       => 'include',
436 436
     );
437 437
 
438
-    foreach ( $map_legacy as $to => $from ) {
439
-        if ( isset( $args[ $from ] ) ) {
440
-            $args[ $to ] = $args[ $from ];
441
-            unset( $args[ $from ] );
438
+    foreach ($map_legacy as $to => $from) {
439
+        if (isset($args[$from])) {
440
+            $args[$to] = $args[$from];
441
+            unset($args[$from]);
442 442
         }
443 443
     }
444 444
 
445 445
     // Backwards compatibility.
446
-    if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) {
446
+    if (!empty($args['email']) && empty($args['user'])) {
447 447
         $args['user'] = $args['email'];
448
-        unset( $args['email'] );
448
+        unset($args['email']);
449 449
     }
450 450
 
451 451
     // Handle cases where the user is set as an email.
452
-    if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) {
453
-        $user = get_user_by( 'email', $args['user'] );
452
+    if (!empty($args['author']) && is_email($args['author'])) {
453
+        $user = get_user_by('email', $args['user']);
454 454
 
455
-        if ( $user ) {
455
+        if ($user) {
456 456
             $args['author'] = $user->user_email;
457 457
         }
458 458
 
@@ -463,31 +463,31 @@  discard block
 block discarded – undo
463 463
 
464 464
     // Show all posts.
465 465
     $paginate = true;
466
-    if ( isset( $args['paginate'] ) ) {
466
+    if (isset($args['paginate'])) {
467 467
 
468 468
         $paginate = $args['paginate'];
469
-        $args['no_found_rows'] = empty( $args['paginate'] );
470
-        unset( $args['paginate'] );
469
+        $args['no_found_rows'] = empty($args['paginate']);
470
+        unset($args['paginate']);
471 471
 
472 472
     }
473 473
 
474 474
     // Whether to return objects or fields.
475 475
     $return = $args['return'];
476
-    unset( $args['return'] );
476
+    unset($args['return']);
477 477
 
478 478
     // Get invoices.
479
-    $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) );
479
+    $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args));
480 480
 
481 481
     // Prepare the results.
482
-    if ( 'objects' === $return ) {
483
-        $results = array_map( 'wpinv_get_invoice', $invoices->posts );
484
-    } elseif ( 'self' === $return ) {
482
+    if ('objects' === $return) {
483
+        $results = array_map('wpinv_get_invoice', $invoices->posts);
484
+    } elseif ('self' === $return) {
485 485
         return $invoices;
486 486
     } else {
487 487
         $results = $invoices->posts;
488 488
     }
489 489
 
490
-    if ( $paginate ) {
490
+    if ($paginate) {
491 491
         return (object) array(
492 492
             'invoices'      => $results,
493 493
             'total'         => $invoices->found_posts,
@@ -505,8 +505,8 @@  discard block
 block discarded – undo
505 505
  * @param string $transaction_id The transaction id to check.
506 506
  * @return int Invoice id on success or 0 on failure
507 507
  */
508
-function wpinv_get_id_by_transaction_id( $transaction_id ) {
509
-    return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' );
508
+function wpinv_get_id_by_transaction_id($transaction_id) {
509
+    return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id');
510 510
 }
511 511
 
512 512
 /**
@@ -515,8 +515,8 @@  discard block
 block discarded – undo
515 515
  * @param string $invoice_number The invoice number to check.
516 516
  * @return int Invoice id on success or 0 on failure
517 517
  */
518
-function wpinv_get_id_by_invoice_number( $invoice_number ) {
519
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' );
518
+function wpinv_get_id_by_invoice_number($invoice_number) {
519
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number');
520 520
 }
521 521
 
522 522
 /**
@@ -525,8 +525,8 @@  discard block
 block discarded – undo
525 525
  * @param string $invoice_key The invoice key to check.
526 526
  * @return int Invoice id on success or 0 on failure
527 527
  */
528
-function wpinv_get_invoice_id_by_key( $invoice_key ) {
529
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' );
528
+function wpinv_get_invoice_id_by_key($invoice_key) {
529
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key');
530 530
 }
531 531
 
532 532
 /**
@@ -536,19 +536,19 @@  discard block
 block discarded – undo
536 536
  * @param string $type Optionally filter by type i.e customer|system
537 537
  * @return array|null
538 538
  */
539
-function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) {
539
+function wpinv_get_invoice_notes($invoice = 0, $type = '') {
540 540
 
541 541
     // Prepare the invoice.
542
-    $invoice = wpinv_get_invoice( $invoice );
543
-    if ( empty( $invoice ) ) {
542
+    $invoice = wpinv_get_invoice($invoice);
543
+    if (empty($invoice)) {
544 544
         return NULL;
545 545
     }
546 546
 
547 547
     // Fetch notes.
548
-    $notes = getpaid_notes()->get_invoice_notes( $invoice->get_id(), $type );
548
+    $notes = getpaid_notes()->get_invoice_notes($invoice->get_id(), $type);
549 549
 
550 550
     // Filter the notes.
551
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type );
551
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type);
552 552
 }
553 553
 
554 554
 /**
@@ -556,10 +556,10 @@  discard block
 block discarded – undo
556 556
  * 
557 557
  * @param string $post_type
558 558
  */
559
-function wpinv_get_user_invoices_columns( $post_type = 'wpi_invoice' ) {
559
+function wpinv_get_user_invoices_columns($post_type = 'wpi_invoice') {
560 560
 
561
-    $label   = getpaid_get_post_type_label( $post_type, false );
562
-    $label   = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label );
561
+    $label   = getpaid_get_post_type_label($post_type, false);
562
+    $label   = empty($label) ? __('Invoice', 'invoicing') : sanitize_text_field($label);
563 563
     $columns = array(
564 564
 
565 565
             'invoice-number'  => array(
@@ -568,22 +568,22 @@  discard block
 block discarded – undo
568 568
             ),
569 569
 
570 570
             'created-date'    => array(
571
-                'title' => __( 'Created Date', 'invoicing' ),
571
+                'title' => __('Created Date', 'invoicing'),
572 572
                 'class' => 'text-left'
573 573
             ),
574 574
 
575 575
             'payment-date'    => array(
576
-                'title' => __( 'Payment Date', 'invoicing' ),
576
+                'title' => __('Payment Date', 'invoicing'),
577 577
                 'class' => 'text-left'
578 578
             ),
579 579
 
580 580
             'invoice-status'  => array(
581
-                'title' => __( 'Status', 'invoicing' ),
581
+                'title' => __('Status', 'invoicing'),
582 582
                 'class' => 'text-center'
583 583
             ),
584 584
 
585 585
             'invoice-total'   => array(
586
-                'title' => __( 'Total', 'invoicing' ),
586
+                'title' => __('Total', 'invoicing'),
587 587
                 'class' => 'text-right'
588 588
             ),
589 589
 
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 
595 595
         );
596 596
 
597
-    return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type );
597
+    return apply_filters('wpinv_user_invoices_columns', $columns, $post_type);
598 598
 }
599 599
 
600 600
 /**
@@ -604,59 +604,59 @@  discard block
 block discarded – undo
604 604
 
605 605
     // Find the invoice.
606 606
     $invoice_id = getpaid_get_current_invoice_id();
607
-    $invoice = new WPInv_Invoice( $invoice_id );
607
+    $invoice = new WPInv_Invoice($invoice_id);
608 608
 
609 609
     // Abort if non was found.
610
-    if ( empty( $invoice_id ) || $invoice->is_draft() ) {
610
+    if (empty($invoice_id) || $invoice->is_draft()) {
611 611
 
612 612
         return aui()->alert(
613 613
             array(
614 614
                 'type'    => 'warning',
615
-                'content' => __( 'We could not find your invoice', 'invoicing' ),
615
+                'content' => __('We could not find your invoice', 'invoicing'),
616 616
             )
617 617
         );
618 618
 
619 619
     }
620 620
 
621 621
     // Can the user view this invoice?
622
-    if ( ! wpinv_can_view_receipt( $invoice_id ) ) {
622
+    if (!wpinv_can_view_receipt($invoice_id)) {
623 623
 
624 624
         return aui()->alert(
625 625
             array(
626 626
                 'type'    => 'warning',
627
-                'content' => __( 'You are not allowed to view this receipt', 'invoicing' ),
627
+                'content' => __('You are not allowed to view this receipt', 'invoicing'),
628 628
             )
629 629
         );
630 630
 
631 631
     }
632 632
 
633 633
     // Load the template.
634
-    return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) );
634
+    return wpinv_get_template_html('invoice-receipt.php', compact('invoice'));
635 635
 
636 636
 }
637 637
 
638 638
 /**
639 639
  * Displays the invoice history.
640 640
  */
641
-function getpaid_invoice_history( $user_id = 0, $post_type = 'wpi_invoice' ) {
641
+function getpaid_invoice_history($user_id = 0, $post_type = 'wpi_invoice') {
642 642
 
643 643
     // Ensure that we have a user id.
644
-    if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
644
+    if (empty($user_id) || !is_numeric($user_id)) {
645 645
         $user_id = get_current_user_id();
646 646
     }
647 647
 
648
-    $label = getpaid_get_post_type_label( $post_type );
649
-    $label = empty( $label ) ? __( 'Invoices', 'invoicing' ) : sanitize_text_field( $label );
648
+    $label = getpaid_get_post_type_label($post_type);
649
+    $label = empty($label) ? __('Invoices', 'invoicing') : sanitize_text_field($label);
650 650
 
651 651
     // View user id.
652
-    if ( empty( $user_id ) ) {
652
+    if (empty($user_id)) {
653 653
 
654 654
         return aui()->alert(
655 655
             array(
656 656
                 'type'    => 'warning',
657 657
                 'content' => sprintf(
658
-                    __( 'You must be logged in to view your %s.', 'invoicing' ),
659
-                    strtolower( $label )
658
+                    __('You must be logged in to view your %s.', 'invoicing'),
659
+                    strtolower($label)
660 660
                 )
661 661
             )
662 662
         );
@@ -667,23 +667,23 @@  discard block
 block discarded – undo
667 667
     $invoices = wpinv_get_invoices(
668 668
 
669 669
         array(
670
-            'page'      => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
670
+            'page'      => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
671 671
             'user'      => $user_id,
672 672
             'paginate'  => true,
673 673
             'type'      => $post_type,
674
-            'status'    => array_keys( wpinv_get_invoice_statuses( false, false, $post_type ) ),
674
+            'status'    => array_keys(wpinv_get_invoice_statuses(false, false, $post_type)),
675 675
         )
676 676
 
677 677
     );
678 678
 
679
-    if ( empty( $invoices->total ) ) {
679
+    if (empty($invoices->total)) {
680 680
 
681 681
         return aui()->alert(
682 682
             array(
683 683
                 'type'    => 'info',
684 684
                 'content' => sprintf(
685
-                    __( 'No %s found.', 'invoicing' ),
686
-                    strtolower( $label )
685
+                    __('No %s found.', 'invoicing'),
686
+                    strtolower($label)
687 687
                 )
688 688
             )
689 689
         );
@@ -691,38 +691,38 @@  discard block
 block discarded – undo
691 691
     }
692 692
 
693 693
     // Load the template.
694
-    return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices', 'post_type' ) );
694
+    return wpinv_get_template_html('invoice-history.php', compact('invoices', 'post_type'));
695 695
 
696 696
 }
697 697
 
698 698
 /**
699 699
  * Formats an invoice number given an invoice type.
700 700
  */
701
-function wpinv_format_invoice_number( $number, $type = '' ) {
701
+function wpinv_format_invoice_number($number, $type = '') {
702 702
 
703 703
     // Allow other plugins to overide this.
704
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
705
-    if ( null !== $check ) {
704
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
705
+    if (null !== $check) {
706 706
         return $check;
707 707
     }
708 708
 
709 709
     // Ensure that we have a numeric number.
710
-    if ( ! is_numeric( $number ) ) {
710
+    if (!is_numeric($number)) {
711 711
         return $number;
712 712
     }
713 713
 
714 714
     // Format the number.
715
-    $padd             = absint( (int) wpinv_get_option( 'invoice_number_padd' ) );
716
-    $prefix           = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_prefix', 'INV-' ) );
717
-    $prefix           = sanitize_text_field( apply_filters( 'getpaid_invoice_type_prefix', $prefix, $type ) );
718
-    $postfix          = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_postfix' ) );
719
-    $postfix          = sanitize_text_field( apply_filters( 'getpaid_invoice_type_postfix', $postfix, $type ) );
720
-    $formatted_number = zeroise( absint( $number ), $padd );
715
+    $padd             = absint((int) wpinv_get_option('invoice_number_padd'));
716
+    $prefix           = sanitize_text_field((string) wpinv_get_option('invoice_number_prefix', 'INV-'));
717
+    $prefix           = sanitize_text_field(apply_filters('getpaid_invoice_type_prefix', $prefix, $type));
718
+    $postfix          = sanitize_text_field((string) wpinv_get_option('invoice_number_postfix'));
719
+    $postfix          = sanitize_text_field(apply_filters('getpaid_invoice_type_postfix', $postfix, $type));
720
+    $formatted_number = zeroise(absint($number), $padd);
721 721
 
722 722
     // Add the prefix and post fix.
723 723
     $formatted_number = $prefix . $formatted_number . $postfix;
724 724
 
725
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
725
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
726 726
 }
727 727
 
728 728
 /**
@@ -731,58 +731,58 @@  discard block
 block discarded – undo
731 731
  * @param string $type.
732 732
  * @return int|null|bool
733 733
  */
734
-function wpinv_get_next_invoice_number( $type = '' ) {
734
+function wpinv_get_next_invoice_number($type = '') {
735 735
 
736 736
     // Allow plugins to overide this.
737
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
738
-    if ( null !== $check ) {
737
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
738
+    if (null !== $check) {
739 739
         return $check;
740 740
     }
741 741
 
742 742
     // Ensure sequential invoice numbers is active.
743
-    if ( ! wpinv_sequential_number_active() ) {
743
+    if (!wpinv_sequential_number_active()) {
744 744
         return false;
745 745
     }
746 746
 
747 747
     // Retrieve the current number and the start number.
748
-    $number = (int) get_option( 'wpinv_last_invoice_number', 0 );
749
-    $start  = absint( (int) wpinv_get_option( 'invoice_sequence_start', 1 ) );
748
+    $number = (int) get_option('wpinv_last_invoice_number', 0);
749
+    $start  = absint((int) wpinv_get_option('invoice_sequence_start', 1));
750 750
 
751 751
     // Ensure that we are starting at a positive integer.
752
-    $start  = max( $start, 1 );
752
+    $start  = max($start, 1);
753 753
 
754 754
     // If this is the first invoice, use the start number.
755
-    $number = max( $start, $number );
755
+    $number = max($start, $number);
756 756
 
757 757
     // Format the invoice number.
758
-    $formatted_number = wpinv_format_invoice_number( $number, $type );
758
+    $formatted_number = wpinv_format_invoice_number($number, $type);
759 759
 
760 760
     // Ensure that this number is unique.
761
-    $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $formatted_number, 'number' );
761
+    $invoice_id = WPInv_Invoice::get_invoice_id_by_field($formatted_number, 'number');
762 762
 
763 763
     // We found a match. Nice.
764
-    if ( empty( $invoice_id ) ) {
765
-        update_option( 'wpinv_last_invoice_number', $number );
766
-        return apply_filters( 'wpinv_get_next_invoice_number', $number );
764
+    if (empty($invoice_id)) {
765
+        update_option('wpinv_last_invoice_number', $number);
766
+        return apply_filters('wpinv_get_next_invoice_number', $number);
767 767
     }
768 768
 
769
-    update_option( 'wpinv_last_invoice_number', $number + 1 );
770
-    return wpinv_get_next_invoice_number( $type );
769
+    update_option('wpinv_last_invoice_number', $number + 1);
770
+    return wpinv_get_next_invoice_number($type);
771 771
 
772 772
 }
773 773
 
774 774
 /**
775 775
  * The prefix used for invoice paths.
776 776
  */
777
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
778
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
777
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
778
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
779 779
 }
780 780
 
781
-function wpinv_generate_post_name( $post_ID ) {
782
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
783
-    $post_name = sanitize_title( $prefix . $post_ID );
781
+function wpinv_generate_post_name($post_ID) {
782
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
783
+    $post_name = sanitize_title($prefix . $post_ID);
784 784
 
785
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
785
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
786 786
 }
787 787
 
788 788
 /**
@@ -790,8 +790,8 @@  discard block
 block discarded – undo
790 790
  * 
791 791
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
792 792
  */
793
-function wpinv_is_invoice_viewed( $invoice ) {
794
-    $invoice = new WPInv_Invoice( $invoice );
793
+function wpinv_is_invoice_viewed($invoice) {
794
+    $invoice = new WPInv_Invoice($invoice);
795 795
     return (bool) $invoice->get_is_viewed();
796 796
 }
797 797
 
@@ -800,17 +800,17 @@  discard block
 block discarded – undo
800 800
  * 
801 801
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
802 802
  */
803
-function getpaid_maybe_mark_invoice_as_viewed( $invoice ) {
804
-    $invoice = new WPInv_Invoice( $invoice );
803
+function getpaid_maybe_mark_invoice_as_viewed($invoice) {
804
+    $invoice = new WPInv_Invoice($invoice);
805 805
 
806
-    if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) {
807
-        $invoice->set_is_viewed( true );
806
+    if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) {
807
+        $invoice->set_is_viewed(true);
808 808
         $invoice->save();
809 809
     }
810 810
 
811 811
 }
812
-add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' );
813
-add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' );
812
+add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed');
813
+add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed');
814 814
 
815 815
 /**
816 816
  * Processes an invoice refund.
@@ -819,27 +819,27 @@  discard block
 block discarded – undo
819 819
  * @param array $status_transition
820 820
  * @todo: descrease customer/store earnings
821 821
  */
822
-function getpaid_maybe_process_refund( $invoice, $status_transition ) {
822
+function getpaid_maybe_process_refund($invoice, $status_transition) {
823 823
 
824
-    if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
824
+    if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) {
825 825
         return;
826 826
     }
827 827
 
828 828
     $discount_code = $invoice->get_discount_code();
829
-    if ( ! empty( $discount_code ) ) {
830
-        $discount = wpinv_get_discount_obj( $discount_code );
829
+    if (!empty($discount_code)) {
830
+        $discount = wpinv_get_discount_obj($discount_code);
831 831
 
832
-        if ( $discount->exists() ) {
832
+        if ($discount->exists()) {
833 833
             $discount->increase_usage( -1 );
834 834
         }
835 835
 
836 836
     }
837 837
 
838
-    do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice->get_id() );
839
-    do_action( 'wpinv_refund_invoice', $invoice, $invoice->get_id() );
840
-    do_action( 'wpinv_post_refund_invoice', $invoice, $invoice->get_id() );
838
+    do_action('wpinv_pre_refund_invoice', $invoice, $invoice->get_id());
839
+    do_action('wpinv_refund_invoice', $invoice, $invoice->get_id());
840
+    do_action('wpinv_post_refund_invoice', $invoice, $invoice->get_id());
841 841
 }
842
-add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2 );
842
+add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2);
843 843
 
844 844
 
845 845
 /**
@@ -847,48 +847,48 @@  discard block
 block discarded – undo
847 847
  *
848 848
  * @param int $invoice_id
849 849
  */
850
-function getpaid_process_invoice_payment( $invoice_id ) {
850
+function getpaid_process_invoice_payment($invoice_id) {
851 851
 
852 852
     // Fetch the invoice.
853
-    $invoice = new WPInv_Invoice( $invoice_id );
853
+    $invoice = new WPInv_Invoice($invoice_id);
854 854
 
855 855
     // We only want to do this once.
856
-    if ( 1 ==  get_post_meta( $invoice->get_id(), 'wpinv_processed_payment', true ) ) {
856
+    if (1 == get_post_meta($invoice->get_id(), 'wpinv_processed_payment', true)) {
857 857
         return;
858 858
     }
859 859
 
860
-    update_post_meta( $invoice->get_id(), 'wpinv_processed_payment', 1 );
860
+    update_post_meta($invoice->get_id(), 'wpinv_processed_payment', 1);
861 861
 
862 862
     // Fires when processing a payment.
863
-    do_action( 'getpaid_process_payment', $invoice );
863
+    do_action('getpaid_process_payment', $invoice);
864 864
 
865 865
     // Fire an action for each invoice item.
866
-    foreach( $invoice->get_items() as $item ) {
867
-        do_action( 'getpaid_process_item_payment', $item, $invoice );
866
+    foreach ($invoice->get_items() as $item) {
867
+        do_action('getpaid_process_item_payment', $item, $invoice);
868 868
     }
869 869
 
870 870
     // Increase discount usage.
871 871
     $discount_code = $invoice->get_discount_code();
872
-    if ( ! empty( $discount_code ) && ! $invoice->is_renewal() ) {
873
-        $discount = wpinv_get_discount_obj( $discount_code );
872
+    if (!empty($discount_code) && !$invoice->is_renewal()) {
873
+        $discount = wpinv_get_discount_obj($discount_code);
874 874
 
875
-        if ( $discount->exists() ) {
875
+        if ($discount->exists()) {
876 876
             $discount->increase_usage();
877 877
         }
878 878
 
879 879
     }
880 880
 
881 881
     // Record reverse vat.
882
-    if ( 'invoice' == $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
882
+    if ('invoice' == $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) {
883 883
 
884
-        if ( wpinv_same_country_exempt_vat() && wpinv_is_base_country( $invoice->get_country() ) ) {
885
-            $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true );
884
+        if (wpinv_same_country_exempt_vat() && wpinv_is_base_country($invoice->get_country())) {
885
+            $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true);
886 886
         }
887 887
 
888 888
     }
889 889
 
890 890
 }
891
-add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' );
891
+add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment');
892 892
 
893 893
 /**
894 894
  * Returns an array of invoice item columns
@@ -896,13 +896,13 @@  discard block
 block discarded – undo
896 896
  * @param int|WPInv_Invoice $invoice
897 897
  * @return array
898 898
  */
899
-function getpaid_invoice_item_columns( $invoice ) {
899
+function getpaid_invoice_item_columns($invoice) {
900 900
 
901 901
     // Prepare the invoice.
902
-    $invoice = new WPInv_Invoice( $invoice );
902
+    $invoice = new WPInv_Invoice($invoice);
903 903
 
904 904
     // Abort if there is no invoice.
905
-    if ( 0 == $invoice->get_id() ) {
905
+    if (0 == $invoice->get_id()) {
906 906
         return array();
907 907
     }
908 908
 
@@ -910,47 +910,47 @@  discard block
 block discarded – undo
910 910
     $columns = apply_filters(
911 911
         'getpaid_invoice_item_columns',
912 912
         array(
913
-            'name'     => __( 'Item', 'invoicing' ),
914
-            'price'    => __( 'Price', 'invoicing' ),
915
-            'quantity' => __( 'Quantity', 'invoicing' ),
916
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
913
+            'name'     => __('Item', 'invoicing'),
914
+            'price'    => __('Price', 'invoicing'),
915
+            'quantity' => __('Quantity', 'invoicing'),
916
+            'subtotal' => __('Subtotal', 'invoicing'),
917 917
         ),
918 918
         $invoice
919 919
     );
920 920
 
921 921
     // Quantities.
922
-    if ( isset( $columns[ 'quantity' ] ) ) {
922
+    if (isset($columns['quantity'])) {
923 923
 
924
-        if ( 'hours' == $invoice->get_template() ) {
925
-            $columns[ 'quantity' ] = __( 'Hours', 'invoicing' );
924
+        if ('hours' == $invoice->get_template()) {
925
+            $columns['quantity'] = __('Hours', 'invoicing');
926 926
         }
927 927
 
928
-        if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) {
929
-            unset( $columns[ 'quantity' ] );
928
+        if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) {
929
+            unset($columns['quantity']);
930 930
         }
931 931
 
932 932
     }
933 933
 
934 934
 
935 935
     // Price.
936
-    if ( isset( $columns[ 'price' ] ) ) {
936
+    if (isset($columns['price'])) {
937 937
 
938
-        if ( 'amount' == $invoice->get_template() ) {
939
-            $columns[ 'price' ] = __( 'Amount', 'invoicing' );
938
+        if ('amount' == $invoice->get_template()) {
939
+            $columns['price'] = __('Amount', 'invoicing');
940 940
         }
941 941
 
942
-        if ( 'hours' == $invoice->get_template() ) {
943
-            $columns[ 'price' ] = __( 'Rate', 'invoicing' );
942
+        if ('hours' == $invoice->get_template()) {
943
+            $columns['price'] = __('Rate', 'invoicing');
944 944
         }
945 945
 
946 946
     }
947 947
 
948 948
 
949 949
     // Sub total.
950
-    if ( isset( $columns[ 'subtotal' ] ) ) {
950
+    if (isset($columns['subtotal'])) {
951 951
 
952
-        if ( 'amount' == $invoice->get_template() ) {
953
-            unset( $columns[ 'subtotal' ] );
952
+        if ('amount' == $invoice->get_template()) {
953
+            unset($columns['subtotal']);
954 954
         }
955 955
 
956 956
     }
@@ -964,30 +964,30 @@  discard block
 block discarded – undo
964 964
  * @param int|WPInv_Invoice $invoice
965 965
  * @return array
966 966
  */
967
-function getpaid_invoice_totals_rows( $invoice ) {
967
+function getpaid_invoice_totals_rows($invoice) {
968 968
 
969 969
     // Prepare the invoice.
970
-    $invoice = new WPInv_Invoice( $invoice );
970
+    $invoice = new WPInv_Invoice($invoice);
971 971
 
972 972
     // Abort if there is no invoice.
973
-    if ( 0 == $invoice->get_id() ) {
973
+    if (0 == $invoice->get_id()) {
974 974
         return array();
975 975
     }
976 976
 
977 977
     $totals = apply_filters(
978 978
         'getpaid_invoice_totals_rows',
979 979
         array(
980
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
981
-            'tax'      => __( 'Tax', 'invoicing' ),
982
-            'fee'      => __( 'Fee', 'invoicing' ),
983
-            'discount' => __( 'Discount', 'invoicing' ),
984
-            'total'    => __( 'Total', 'invoicing' ),
980
+            'subtotal' => __('Subtotal', 'invoicing'),
981
+            'tax'      => __('Tax', 'invoicing'),
982
+            'fee'      => __('Fee', 'invoicing'),
983
+            'discount' => __('Discount', 'invoicing'),
984
+            'total'    => __('Total', 'invoicing'),
985 985
         ),
986 986
         $invoice
987 987
     );
988 988
 
989
-    if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) {
990
-        unset( $totals['tax'] );
989
+    if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) {
990
+        unset($totals['tax']);
991 991
     }
992 992
 
993 993
     return $totals;
@@ -998,47 +998,47 @@  discard block
 block discarded – undo
998 998
  * 
999 999
  * @param WPInv_Invoice $invoice
1000 1000
  */
1001
-function getpaid_new_invoice( $invoice ) {
1001
+function getpaid_new_invoice($invoice) {
1002 1002
 
1003
-    if ( ! $invoice->get_status() ) {
1003
+    if (!$invoice->get_status()) {
1004 1004
         return;
1005 1005
     }
1006 1006
 
1007 1007
     // Add an invoice created note.
1008 1008
     $invoice->add_note(
1009 1009
         sprintf(
1010
-            __( '%s created with the status "%s".', 'invoicing' ),
1011
-            ucfirst( $invoice->get_invoice_quote_type() ),
1012
-            wpinv_status_nicename( $invoice->get_status(), $invoice  )
1010
+            __('%s created with the status "%s".', 'invoicing'),
1011
+            ucfirst($invoice->get_invoice_quote_type()),
1012
+            wpinv_status_nicename($invoice->get_status(), $invoice)
1013 1013
         )
1014 1014
     );
1015 1015
 
1016 1016
 }
1017
-add_action( 'getpaid_new_invoice', 'getpaid_new_invoice' );
1017
+add_action('getpaid_new_invoice', 'getpaid_new_invoice');
1018 1018
 
1019 1019
 /**
1020 1020
  * This function updates invoice caches.
1021 1021
  * 
1022 1022
  * @param WPInv_Invoice $invoice
1023 1023
  */
1024
-function getpaid_update_invoice_caches( $invoice ) {
1024
+function getpaid_update_invoice_caches($invoice) {
1025 1025
 
1026 1026
     // Cache invoice number.
1027
-    wp_cache_set( $invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids" );
1027
+    wp_cache_set($invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids");
1028 1028
 
1029 1029
     // Cache invoice key.
1030
-    wp_cache_set( $invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids" );
1030
+    wp_cache_set($invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids");
1031 1031
 
1032 1032
     // (Maybe) cache transaction id.
1033 1033
     $transaction_id = $invoice->get_transaction_id();
1034 1034
 
1035
-    if ( ! empty( $transaction_id ) ) {
1036
-        wp_cache_set( $transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids" );
1035
+    if (!empty($transaction_id)) {
1036
+        wp_cache_set($transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids");
1037 1037
     }
1038 1038
 
1039 1039
 }
1040
-add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5 );
1041
-add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5 );
1040
+add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5);
1041
+add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5);
1042 1042
 
1043 1043
 /**
1044 1044
  * Duplicates an invoice.
@@ -1048,7 +1048,7 @@  discard block
 block discarded – undo
1048 1048
  * @param  WPInv_Invoice $old_invoice The invoice to duplicate
1049 1049
  * @return WPInv_Invoice The new invoice.
1050 1050
  */
1051
-function getpaid_duplicate_invoice( $old_invoice ) {
1051
+function getpaid_duplicate_invoice($old_invoice) {
1052 1052
 
1053 1053
     // Create the new invoice.
1054 1054
     $invoice = new WPInv_Invoice();
@@ -1109,123 +1109,123 @@  discard block
 block discarded – undo
1109 1109
  * @param WPInv_Invoice $invoice
1110 1110
  * @return array
1111 1111
  */
1112
-function getpaid_get_invoice_meta( $invoice ) {
1112
+function getpaid_get_invoice_meta($invoice) {
1113 1113
 
1114 1114
     // Load the invoice meta.
1115 1115
     $meta = array(
1116 1116
 
1117 1117
         'number' => array(
1118 1118
             'label' => sprintf(
1119
-                __( '%s Number', 'invoicing' ),
1120
-                ucfirst( $invoice->get_invoice_quote_type() )
1119
+                __('%s Number', 'invoicing'),
1120
+                ucfirst($invoice->get_invoice_quote_type())
1121 1121
             ),
1122
-            'value' => sanitize_text_field( $invoice->get_number() ),
1122
+            'value' => sanitize_text_field($invoice->get_number()),
1123 1123
         ),
1124 1124
 
1125 1125
         'status' => array(
1126 1126
             'label' => sprintf(
1127
-                __( '%s Status', 'invoicing' ),
1128
-                ucfirst( $invoice->get_invoice_quote_type() )
1127
+                __('%s Status', 'invoicing'),
1128
+                ucfirst($invoice->get_invoice_quote_type())
1129 1129
             ),
1130 1130
             'value' => $invoice->get_status_label_html(),
1131 1131
         ),
1132 1132
 
1133 1133
         'date' => array(
1134 1134
             'label' => sprintf(
1135
-                __( '%s Date', 'invoicing' ),
1136
-                ucfirst( $invoice->get_invoice_quote_type() )
1135
+                __('%s Date', 'invoicing'),
1136
+                ucfirst($invoice->get_invoice_quote_type())
1137 1137
             ),
1138
-            'value' => getpaid_format_date( $invoice->get_created_date() ),
1138
+            'value' => getpaid_format_date($invoice->get_created_date()),
1139 1139
         ),
1140 1140
 
1141 1141
         'date_paid' => array(
1142
-            'label' => __( 'Paid On', 'invoicing' ),
1143
-            'value' => getpaid_format_date( $invoice->get_completed_date() ),
1142
+            'label' => __('Paid On', 'invoicing'),
1143
+            'value' => getpaid_format_date($invoice->get_completed_date()),
1144 1144
         ),
1145 1145
 
1146 1146
         'gateway'   => array(
1147
-            'label' => __( 'Payment Method', 'invoicing' ),
1148
-            'value' => sanitize_text_field( $invoice->get_gateway_title() ),
1147
+            'label' => __('Payment Method', 'invoicing'),
1148
+            'value' => sanitize_text_field($invoice->get_gateway_title()),
1149 1149
         ),
1150 1150
 
1151 1151
         'transaction_id' => array(
1152
-            'label' => __( 'Transaction ID', 'invoicing' ),
1153
-            'value' => sanitize_text_field( $invoice->get_transaction_id() ),
1152
+            'label' => __('Transaction ID', 'invoicing'),
1153
+            'value' => sanitize_text_field($invoice->get_transaction_id()),
1154 1154
         ),
1155 1155
 
1156 1156
         'due_date'  => array(
1157
-            'label' => __( 'Due Date', 'invoicing' ),
1158
-            'value' => getpaid_format_date( $invoice->get_due_date() ),
1157
+            'label' => __('Due Date', 'invoicing'),
1158
+            'value' => getpaid_format_date($invoice->get_due_date()),
1159 1159
         ),
1160 1160
 
1161 1161
         'vat_number' => array(
1162
-            'label' => __( 'VAT Number', 'invoicing' ),
1163
-            'value' => sanitize_text_field( $invoice->get_vat_number() ),
1162
+            'label' => __('VAT Number', 'invoicing'),
1163
+            'value' => sanitize_text_field($invoice->get_vat_number()),
1164 1164
         ),
1165 1165
 
1166 1166
     );
1167 1167
 
1168 1168
     // If it is not paid, remove the date of payment.
1169
-    if ( ! $invoice->is_paid() ) {
1170
-        unset( $meta[ 'date_paid' ] );
1171
-        unset( $meta[ 'transaction_id' ] );
1169
+    if (!$invoice->is_paid()) {
1170
+        unset($meta['date_paid']);
1171
+        unset($meta['transaction_id']);
1172 1172
     }
1173 1173
 
1174
-    if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) {
1175
-        unset( $meta[ 'gateway' ] );
1174
+    if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) {
1175
+        unset($meta['gateway']);
1176 1176
     }
1177 1177
 
1178 1178
     // Only display the due date if due dates are enabled.
1179
-    if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) {
1180
-        unset( $meta[ 'due_date' ] );
1179
+    if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) {
1180
+        unset($meta['due_date']);
1181 1181
     }
1182 1182
 
1183 1183
     // Only display the vat number if taxes are enabled.
1184
-    if ( ! wpinv_use_taxes() ) {
1185
-        unset( $meta[ 'vat_number' ] );
1184
+    if (!wpinv_use_taxes()) {
1185
+        unset($meta['vat_number']);
1186 1186
     }
1187 1187
 
1188
-    if ( $invoice->is_recurring() ) {
1188
+    if ($invoice->is_recurring()) {
1189 1189
 
1190 1190
         // Link to the parent invoice.
1191
-        if ( $invoice->is_renewal() ) {
1191
+        if ($invoice->is_renewal()) {
1192 1192
 
1193
-            $meta[ 'parent' ] = array(
1193
+            $meta['parent'] = array(
1194 1194
 
1195 1195
                 'label' => sprintf(
1196
-                    __( 'Parent %s', 'invoicing' ),
1197
-                    ucfirst( $invoice->get_invoice_quote_type() )
1196
+                    __('Parent %s', 'invoicing'),
1197
+                    ucfirst($invoice->get_invoice_quote_type())
1198 1198
                 ),
1199 1199
 
1200
-                'value' => wpinv_invoice_link( $invoice->get_parent_id() ),
1200
+                'value' => wpinv_invoice_link($invoice->get_parent_id()),
1201 1201
 
1202 1202
             );
1203 1203
 
1204 1204
         }
1205 1205
 
1206
-        $subscription = wpinv_get_subscription( $invoice );
1206
+        $subscription = wpinv_get_subscription($invoice);
1207 1207
 
1208
-        if ( ! empty ( $subscription ) ) {
1208
+        if (!empty ($subscription)) {
1209 1209
 
1210 1210
             // Display the renewal date.
1211
-            if ( $subscription->is_active() && 'cancelled' != $subscription->get_status() ) {
1211
+            if ($subscription->is_active() && 'cancelled' != $subscription->get_status()) {
1212 1212
 
1213
-                $meta[ 'renewal_date' ] = array(
1213
+                $meta['renewal_date'] = array(
1214 1214
 
1215
-                    'label' => __( 'Renews On', 'invoicing' ),
1216
-                    'value' => getpaid_format_date( $subscription->get_expiration() ),
1215
+                    'label' => __('Renews On', 'invoicing'),
1216
+                    'value' => getpaid_format_date($subscription->get_expiration()),
1217 1217
         
1218 1218
                 );
1219 1219
 
1220 1220
             }
1221 1221
 
1222
-            if ( $invoice->is_parent() ) {
1222
+            if ($invoice->is_parent()) {
1223 1223
 
1224 1224
                 // Display the recurring amount.
1225
-                $meta[ 'recurring_total' ] = array(
1225
+                $meta['recurring_total'] = array(
1226 1226
 
1227
-                    'label' => __( 'Recurring Amount', 'invoicing' ),
1228
-                    'value' => wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ),
1227
+                    'label' => __('Recurring Amount', 'invoicing'),
1228
+                    'value' => wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency()),
1229 1229
         
1230 1230
                 );
1231 1231
 
@@ -1235,15 +1235,15 @@  discard block
 block discarded – undo
1235 1235
     }
1236 1236
 
1237 1237
     // Add the invoice total to the meta.
1238
-    $meta[ 'invoice_total' ] = array(
1238
+    $meta['invoice_total'] = array(
1239 1239
 
1240
-        'label' => __( 'Total Amount', 'invoicing' ),
1241
-        'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ),
1240
+        'label' => __('Total Amount', 'invoicing'),
1241
+        'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()),
1242 1242
 
1243 1243
     );
1244 1244
 
1245 1245
     // Provide a way for third party plugins to filter the meta.
1246
-    $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice );
1246
+    $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice);
1247 1247
 
1248 1248
     return $meta;
1249 1249
 
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 1 patch
Spacing   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * Please use GetPaid_Notification_Email_Sender
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /*
12 12
 |--------------------------------------------------------------------------
@@ -17,19 +17,19 @@  discard block
 block discarded – undo
17 17
 /**
18 18
  * Generates the email header.
19 19
  */
20
-function wpinv_email_header( $email_heading ) {
21
-    wpinv_get_template( 'emails/wpinv-email-header.php', compact( 'email_heading' ) );
20
+function wpinv_email_header($email_heading) {
21
+    wpinv_get_template('emails/wpinv-email-header.php', compact('email_heading'));
22 22
 }
23
-add_action( 'wpinv_email_header', 'wpinv_email_header' );
23
+add_action('wpinv_email_header', 'wpinv_email_header');
24 24
 
25 25
 
26 26
 /**
27 27
  * Generates the email footer.
28 28
  */
29 29
 function wpinv_email_footer() {
30
-    wpinv_get_template( 'emails/wpinv-email-footer.php' );
30
+    wpinv_get_template('emails/wpinv-email-footer.php');
31 31
 }
32
-add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
32
+add_action('wpinv_email_footer', 'wpinv_email_footer');
33 33
 
34 34
 
35 35
 /**
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
  * @param string $email_type
40 40
  * @param bool $sent_to_admin
41 41
  */
42
-function wpinv_email_invoice_details( $invoice,  $email_type, $sent_to_admin ) {
42
+function wpinv_email_invoice_details($invoice, $email_type, $sent_to_admin) {
43 43
 
44
-    $args = compact( 'invoice', 'email_type', 'sent_to_admin' );
45
-    wpinv_get_template( 'emails/invoice-details.php', $args );
44
+    $args = compact('invoice', 'email_type', 'sent_to_admin');
45
+    wpinv_get_template('emails/invoice-details.php', $args);
46 46
 
47 47
 }
48
-add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
48
+add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3);
49 49
 
50 50
 /**
51 51
  * Display line items in emails.
@@ -54,17 +54,17 @@  discard block
 block discarded – undo
54 54
  * @param string $email_type
55 55
  * @param bool $sent_to_admin
56 56
  */
57
-function wpinv_email_invoice_items( $invoice, $email_type, $sent_to_admin ) {
57
+function wpinv_email_invoice_items($invoice, $email_type, $sent_to_admin) {
58 58
 
59 59
     // Prepare line items.
60
-    $columns = getpaid_invoice_item_columns( $invoice );
61
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
60
+    $columns = getpaid_invoice_item_columns($invoice);
61
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
62 62
 
63 63
     // Load the template.
64
-    wpinv_get_template( 'emails/invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) );
64
+    wpinv_get_template('emails/invoice-items.php', compact('invoice', 'columns', 'email_type', 'sent_to_admin'));
65 65
 
66 66
 }
67
-add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
67
+add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3);
68 68
 
69 69
 
70 70
 /**
@@ -74,13 +74,13 @@  discard block
 block discarded – undo
74 74
  * @param string $email_type
75 75
  * @param bool $sent_to_admin
76 76
  */
77
-function wpinv_email_billing_details( $invoice, $email_type, $sent_to_admin ) {
77
+function wpinv_email_billing_details($invoice, $email_type, $sent_to_admin) {
78 78
 
79
-    $args = compact( 'invoice', 'email_type', 'sent_to_admin' );
80
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', $args );
79
+    $args = compact('invoice', 'email_type', 'sent_to_admin');
80
+    wpinv_get_template('emails/wpinv-email-billing-details.php', $args);
81 81
 
82 82
 }
83
-add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
83
+add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3);
84 84
 
85 85
 /**
86 86
  * Returns email css.
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
  */
89 89
 function getpaid_get_email_css() {
90 90
 
91
-    $css = wpinv_get_template_html( 'emails/wpinv-email-styles.php' );
92
-    return apply_filters( 'wpinv_email_styles', $css );
91
+    $css = wpinv_get_template_html('emails/wpinv-email-styles.php');
92
+    return apply_filters('wpinv_email_styles', $css);
93 93
 
94 94
 }
95 95
 
@@ -100,26 +100,26 @@  discard block
 block discarded – undo
100 100
  * @return string
101 101
  * 
102 102
  */
103
-function wpinv_email_style_body( $content ) {
103
+function wpinv_email_style_body($content) {
104 104
 
105
-    if ( ! class_exists( 'DOMDocument' ) ) {
105
+    if (!class_exists('DOMDocument')) {
106 106
         return $content;
107 107
     }
108 108
 
109 109
     $css = getpaid_get_email_css();
110 110
 
111 111
     // include css inliner
112
-	if ( ! class_exists( 'Emogrifier' ) ) {
113
-		include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
112
+	if (!class_exists('Emogrifier')) {
113
+		include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
114 114
     }
115 115
 
116 116
     // Inline the css.
117 117
     try {
118
-        $emogrifier = new Emogrifier( $content, $css );
118
+        $emogrifier = new Emogrifier($content, $css);
119 119
         $_content   = $emogrifier->emogrify();
120 120
         $content    = $_content;
121
-    } catch ( Exception $e ) {
122
-        wpinv_error_log( $e->getMessage(), 'emogrifier' );
121
+    } catch (Exception $e) {
122
+        wpinv_error_log($e->getMessage(), 'emogrifier');
123 123
     }
124 124
 
125 125
     return $content;
@@ -128,37 +128,37 @@  discard block
 block discarded – undo
128 128
 
129 129
 // Backwards compatibility.
130 130
 function wpinv_init_transactional_emails() {
131
-    foreach ( apply_filters( 'wpinv_email_actions', array() ) as $action ) {
132
-        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
131
+    foreach (apply_filters('wpinv_email_actions', array()) as $action) {
132
+        add_action($action, 'wpinv_send_transactional_email', 10, 10);
133 133
     }
134 134
 }
135
-add_action( 'init', 'wpinv_init_transactional_emails' );
135
+add_action('init', 'wpinv_init_transactional_emails');
136 136
 
137 137
 function wpinv_send_transactional_email() {
138 138
     $args       = func_get_args();
139 139
     $function   = current_filter() . '_notification';
140
-    do_action_ref_array( $function, $args );
140
+    do_action_ref_array($function, $args);
141 141
 }
142 142
 
143 143
 function wpinv_mail_get_from_address() {
144
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
145
-    return sanitize_email( $from_address );
144
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from'));
145
+    return sanitize_email($from_address);
146 146
 }
147 147
 
148 148
 function wpinv_mail_get_from_name() {
149
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
150
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
149
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name'));
150
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
151 151
 }
152 152
 
153
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
154
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
155
-    return ( $active ? true : false );
153
+function wpinv_mail_admin_bcc_active($mail_type = '') {
154
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
155
+    return ($active ? true : false);
156 156
 }
157 157
     
158
-function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
159
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
158
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
159
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
160 160
 
161
-    switch ( $email_type ) {
161
+    switch ($email_type) {
162 162
         case 'html' :
163 163
             $content_type = 'text/html';
164 164
             break;
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
  * @param array        $attachments Any files to attach to the email.
184 184
  * @param string|array $cc An email or array of extra emails to send a copy of the email to.
185 185
  */
186
-function wpinv_mail_send( $to, $subject, $message, $deprecated, $attachments = array(), $cc = array() ) {
186
+function wpinv_mail_send($to, $subject, $message, $deprecated, $attachments = array(), $cc = array()) {
187 187
 
188 188
     $mailer  = new GetPaid_Notification_Email_Sender();
189
-    $message = wpinv_email_style_body( $message );
190
-    $to      = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) );
189
+    $message = wpinv_email_style_body($message);
190
+    $to      = array_merge(wpinv_parse_list($to), wpinv_parse_list($cc));
191 191
 
192 192
 	return $mailer->send(
193 193
         $to,
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
  * @return array
205 205
  */
206 206
 function wpinv_get_emails() {
207
-    return apply_filters( 'wpinv_get_emails', wpinv_get_data( 'email-settings' ) );
207
+    return apply_filters('wpinv_get_emails', wpinv_get_data('email-settings'));
208 208
 }
209 209
 
210 210
 /**
@@ -213,172 +213,172 @@  discard block
 block discarded – undo
213 213
  * @param array $settings
214 214
  * @return array
215 215
  */
216
-function wpinv_settings_emails( $settings = array() ) {
217
-    $settings = array_merge( $settings, wpinv_get_emails() );
218
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
216
+function wpinv_settings_emails($settings = array()) {
217
+    $settings = array_merge($settings, wpinv_get_emails());
218
+    return apply_filters('wpinv_settings_get_emails', $settings);
219 219
 }
220
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
220
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
221 221
 
222 222
 /**
223 223
  * Filter email section names.
224 224
  * 
225 225
  */
226
-function wpinv_settings_sections_emails( $settings ) {
227
-    foreach  ( wpinv_get_emails() as $key => $email) {
228
-        $settings[$key] = ! empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : strip_tags( $key );
226
+function wpinv_settings_sections_emails($settings) {
227
+    foreach (wpinv_get_emails() as $key => $email) {
228
+        $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : strip_tags($key);
229 229
     }
230 230
 
231 231
     return $settings;    
232 232
 }
233
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
233
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
234 234
 
235
-function wpinv_email_is_enabled( $email_type ) {
235
+function wpinv_email_is_enabled($email_type) {
236 236
     $emails = wpinv_get_emails();
237
-    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( 'email_'. $email_type . '_active', 0 ) ? true : false;
237
+    $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false;
238 238
 
239
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
239
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
240 240
 }
241 241
 
242
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
243
-    switch ( $email_type ) {
242
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
243
+    switch ($email_type) {
244 244
         case 'new_invoice':
245 245
         case 'cancelled_invoice':
246 246
         case 'failed_invoice':
247 247
             $recipient  = wpinv_get_admin_email();
248 248
         break;
249 249
         default:
250
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
251
-            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
250
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
251
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
252 252
         break;
253 253
     }
254 254
 
255
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
255
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
256 256
 }
257 257
 
258 258
 /**
259 259
  * Returns invoice CC recipients
260 260
  */
261
-function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) {
262
-    switch ( $email_type ) {
261
+function wpinv_email_get_cc_recipients($email_type = '', $invoice_id = 0, $invoice = array()) {
262
+    switch ($email_type) {
263 263
         case 'new_invoice':
264 264
         case 'cancelled_invoice':
265 265
         case 'failed_invoice':
266 266
             return array();
267 267
         break;
268 268
         default:
269
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
270
-            $recipient  = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true );
271
-            if ( empty( $recipient ) ) {
269
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
270
+            $recipient  = empty($invoice) ? '' : get_post_meta($invoice->ID, 'wpinv_email_cc', true);
271
+            if (empty($recipient)) {
272 272
                 return array();
273 273
             }
274
-            return  array_filter( array_map( 'trim', explode( ',', $recipient ) ) );
274
+            return  array_filter(array_map('trim', explode(',', $recipient)));
275 275
         break;
276 276
     }
277 277
 
278 278
 }
279 279
 
280
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
281
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
282
-    $subject    = __( $subject, 'invoicing' );
280
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
281
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
282
+    $subject    = __($subject, 'invoicing');
283 283
 
284
-    $subject    = wpinv_email_format_text( $subject, $invoice );
284
+    $subject    = wpinv_email_format_text($subject, $invoice);
285 285
 
286
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
286
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
287 287
 }
288 288
 
289
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
290
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
291
-    $email_heading = __( $email_heading, 'invoicing' );
289
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
290
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
291
+    $email_heading = __($email_heading, 'invoicing');
292 292
 
293
-    $email_heading = wpinv_email_format_text( $email_heading, $invoice );
293
+    $email_heading = wpinv_email_format_text($email_heading, $invoice);
294 294
 
295
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
295
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
296 296
 }
297 297
 
298
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
299
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
300
-    $content    = __( $content, 'invoicing' );
298
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
299
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
300
+    $content    = __($content, 'invoicing');
301 301
 
302
-    $content    = wpinv_email_format_text( $content, $invoice );
302
+    $content    = wpinv_email_format_text($content, $invoice);
303 303
 
304
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
304
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
305 305
 }
306 306
 
307
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
307
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
308 308
     $from_name = wpinv_mail_get_from_address();
309 309
     $from_email = wpinv_mail_get_from_address();
310 310
     
311
-    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
311
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
312 312
     
313
-    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
314
-    $headers    .= "Reply-To: ". $from_email . "\r\n";
313
+    $headers    = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
314
+    $headers    .= "Reply-To: " . $from_email . "\r\n";
315 315
     $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
316 316
     
317
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
317
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
318 318
 }
319 319
 
320
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
320
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
321 321
     $attachments = array();
322 322
     
323
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
323
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
324 324
 }
325 325
 
326 326
 /**
327 327
  * Searches for and replaces certain placeholders in an email.
328 328
  */
329
-function wpinv_email_format_text( $content, $invoice ) {
329
+function wpinv_email_format_text($content, $invoice) {
330 330
 
331 331
     $replace_array = array(
332 332
         '{site_title}'      => wpinv_get_blogname(),
333
-        '{date}'            => getpaid_format_date( current_time( 'mysql' ) ),
333
+        '{date}'            => getpaid_format_date(current_time('mysql')),
334 334
     );
335 335
 
336
-    $invoice = new WPInv_Invoice( $invoice );
336
+    $invoice = new WPInv_Invoice($invoice);
337 337
 
338
-    if ( $invoice->get_id() ) {
338
+    if ($invoice->get_id()) {
339 339
 
340 340
         $replace_array = array_merge(
341 341
             $replace_array, 
342 342
             array(
343
-                '{name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
344
-                '{full_name}'       => sanitize_text_field( $invoice->get_user_full_name() ),
345
-                '{first_name}'      => sanitize_text_field( $invoice->get_first_name() ),
346
-                '{last_name}'       => sanitize_text_field( $invoice->get_last_name() ),
347
-                '{email}'           => sanitize_email( $invoice->get_email() ),
348
-                '{invoice_number}'  => sanitize_text_field( $invoice->get_number() ),
349
-                '{invoice_total}'   => sanitize_text_field( wpinv_price( $invoice->get_total( true ), $invoice->get_currency() ) ),
350
-                '{invoice_link}'    => esc_url( $invoice->get_view_url() ),
351
-                '{invoice_pay_link}'=> esc_url( $invoice->get_checkout_payment_url() ),
352
-                '{invoice_date}'    => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
353
-                '{invoice_due_date}'=> date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ),
354
-                '{invoice_quote}'   => sanitize_text_field( $invoice->get_invoice_quote_type() ),
355
-                '{invoice_label}'   => sanitize_text_field( ucfirst( $invoice->get_invoice_quote_type() ) ),
356
-                '{is_was}'          => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
343
+                '{name}'            => sanitize_text_field($invoice->get_user_full_name()),
344
+                '{full_name}'       => sanitize_text_field($invoice->get_user_full_name()),
345
+                '{first_name}'      => sanitize_text_field($invoice->get_first_name()),
346
+                '{last_name}'       => sanitize_text_field($invoice->get_last_name()),
347
+                '{email}'           => sanitize_email($invoice->get_email()),
348
+                '{invoice_number}'  => sanitize_text_field($invoice->get_number()),
349
+                '{invoice_total}'   => sanitize_text_field(wpinv_price($invoice->get_total(true), $invoice->get_currency())),
350
+                '{invoice_link}'    => esc_url($invoice->get_view_url()),
351
+                '{invoice_pay_link}'=> esc_url($invoice->get_checkout_payment_url()),
352
+                '{invoice_date}'    => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))),
353
+                '{invoice_due_date}'=> date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))),
354
+                '{invoice_quote}'   => sanitize_text_field($invoice->get_invoice_quote_type()),
355
+                '{invoice_label}'   => sanitize_text_field(ucfirst($invoice->get_invoice_quote_type())),
356
+                '{is_was}'          => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
357 357
             )
358 358
         );
359 359
 
360 360
     }
361 361
 
362 362
     // Let third party plugins filter the arra.
363
-    $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice );
363
+    $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice);
364 364
 
365
-    foreach ( $replace_array as $key => $value ) {
366
-        $content = str_replace( $key, $value, $content );
365
+    foreach ($replace_array as $key => $value) {
366
+        $content = str_replace($key, $value, $content);
367 367
     }
368 368
 
369
-    return apply_filters( 'wpinv_email_content_replace', $content );
369
+    return apply_filters('wpinv_email_content_replace', $content);
370 370
 }
371 371
 
372 372
 
373
-function wpinv_email_wrap_message( $message ) {
373
+function wpinv_email_wrap_message($message) {
374 374
     // Buffer
375 375
     ob_start();
376 376
 
377
-    do_action( 'wpinv_email_header' );
377
+    do_action('wpinv_email_header');
378 378
 
379
-    echo wpautop( wptexturize( $message ) );
379
+    echo wpautop(wptexturize($message));
380 380
 
381
-    do_action( 'wpinv_email_footer' );
381
+    do_action('wpinv_email_footer');
382 382
 
383 383
     // Get contents
384 384
     $message = ob_get_clean();
@@ -386,21 +386,21 @@  discard block
 block discarded – undo
386 386
     return $message;
387 387
 }
388 388
 
389
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type ) {
390
-    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->get_id(), true ) ) {
391
-        $date_format = get_option( 'date_format' );
392
-        $time_format = get_option( 'time_format' );
389
+function wpinv_add_notes_to_invoice_email($invoice, $email_type) {
390
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->get_id(), true)) {
391
+        $date_format = get_option('date_format');
392
+        $time_format = get_option('time_format');
393 393
         ?>
394 394
         <div id="wpinv-email-notes">
395
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
395
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
396 396
             <ol class="wpinv-notes-lists">
397 397
         <?php
398
-        foreach ( $invoice_notes as $note ) {
399
-            $note_time = strtotime( $note->comment_date );
398
+        foreach ($invoice_notes as $note) {
399
+            $note_time = strtotime($note->comment_date);
400 400
             ?>
401 401
             <li class="comment wpinv-note">
402
-            <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p>
403
-            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
402
+            <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p>
403
+            <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div>
404 404
             </li>
405 405
             <?php
406 406
         }
@@ -409,4 +409,4 @@  discard block
 block discarded – undo
409 409
         <?php
410 410
     }
411 411
 }
412
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
412
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-details.php 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -21,13 +21,13 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param WP_Post $post
23 23
 	 */
24
-    public static function output( $post ) {
24
+    public static function output($post) {
25 25
 
26 26
         // Prepare the invoice.
27
-        $invoice = new WPInv_Invoice( $post );
27
+        $invoice = new WPInv_Invoice($post);
28 28
 
29 29
         // Nonce field.
30
-        wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;
30
+        wp_nonce_field('wpinv_details', 'wpinv_details_nonce');
31 31
 
32 32
 
33 33
         ?>
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
 
47 47
                 <div class="bsui" style="margin-top: 1.5rem">
48 48
 
49
-                    <?php do_action( 'getpaid_invoice_edit_before_viewed_by_customer', $invoice ); ?>
50
-                    <?php if ( ! $invoice->is_draft() ) : ?>
49
+                    <?php do_action('getpaid_invoice_edit_before_viewed_by_customer', $invoice); ?>
50
+                    <?php if (!$invoice->is_draft()) : ?>
51 51
                         <div class="form-group">
52
-                            <strong><?php _e( 'Viewed by Customer:', 'invoicing' );?></strong>
53
-                            <?php ( $invoice->get_is_viewed() ) ? _e( 'Yes', 'invoicing' ) : _e( 'No', 'invoicing' ); ?>
52
+                            <strong><?php _e('Viewed by Customer:', 'invoicing'); ?></strong>
53
+                            <?php ($invoice->get_is_viewed()) ? _e('Yes', 'invoicing') : _e('No', 'invoicing'); ?>
54 54
                         </div>
55 55
                     <?php endif; ?>
56 56
 
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
 
59 59
                         // Date created.
60 60
                         $label = sprintf(
61
-                            __( '%s Date:', 'invoicing' ),
62
-                            ucfirst( $invoice->get_invoice_quote_type() )
61
+                            __('%s Date:', 'invoicing'),
62
+                            ucfirst($invoice->get_invoice_quote_type())
63 63
                         );
64 64
 
65
-                        $info  = sprintf(
66
-                            __( 'The date this %s was created.', 'invoicing' ),
67
-                            strtolower( $invoice->get_invoice_quote_type() )
65
+                        $info = sprintf(
66
+                            __('The date this %s was created.', 'invoicing'),
67
+                            strtolower($invoice->get_invoice_quote_type())
68 68
                         );
69 69
 
70 70
                         echo aui()->input(
@@ -72,11 +72,11 @@  discard block
 block discarded – undo
72 72
                                 'type'        => 'datepicker',
73 73
                                 'id'          => 'wpinv_date_created',
74 74
                                 'name'        => 'date_created',
75
-                                'label'       => $label . getpaid_get_help_tip( $info ),
75
+                                'label'       => $label . getpaid_get_help_tip($info),
76 76
                                 'label_type'  => 'vertical',
77 77
                                 'placeholder' => 'YYYY-MM-DD 00:00',
78 78
                                 'class'       => 'form-control-sm',
79
-                                'value'       => $invoice->get_date_created( 'edit' ),
79
+                                'value'       => $invoice->get_date_created('edit'),
80 80
                                 'extra_attributes' => array(
81 81
                                     'data-enable-time' => 'true',
82 82
                                     'data-time_24hr'   => 'true',
@@ -87,30 +87,30 @@  discard block
 block discarded – undo
87 87
                         );
88 88
 
89 89
                         // Due date.
90
-                        if ( $invoice->is_type( 'invoice' ) && wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->is_draft() ) ) {
90
+                        if ($invoice->is_type('invoice') && wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->is_draft())) {
91 91
 
92 92
                             echo aui()->input(
93 93
                                 array(
94 94
                                     'type'        => 'text',
95 95
                                     'id'          => 'wpinv_due_date',
96 96
                                     'name'        => 'wpinv_due_date',
97
-                                    'label'       => __( 'Due Date:', 'invoicing' ) . getpaid_get_help_tip( __( 'Leave blank to disable automated reminder emails for this invoice.', 'invoicing' ) ),
97
+                                    'label'       => __('Due Date:', 'invoicing') . getpaid_get_help_tip(__('Leave blank to disable automated reminder emails for this invoice.', 'invoicing')),
98 98
                                     'label_type'  => 'vertical',
99
-                                    'placeholder' => __( 'No due date', 'invoicing' ),
99
+                                    'placeholder' => __('No due date', 'invoicing'),
100 100
                                     'class'       => 'form-control-sm',
101
-                                    'value'       => $invoice->get_due_date( 'edit' ),
101
+                                    'value'       => $invoice->get_due_date('edit'),
102 102
                                 )
103 103
                             );
104 104
 
105 105
                         }
106 106
 
107
-                        do_action( 'wpinv_meta_box_details_after_due_date', $invoice->get_id() );
108
-                        do_action( 'getpaid_metabox_after_due_date', $invoice );
107
+                        do_action('wpinv_meta_box_details_after_due_date', $invoice->get_id());
108
+                        do_action('getpaid_metabox_after_due_date', $invoice);
109 109
 
110 110
                         // Status.
111 111
                         $label = sprintf(
112
-                            __( '%s Status:', 'invoicing' ),
113
-                            ucfirst( $invoice->get_invoice_quote_type() )
112
+                            __('%s Status:', 'invoicing'),
113
+                            ucfirst($invoice->get_invoice_quote_type())
114 114
                         );
115 115
 
116 116
                         echo aui()->select(
@@ -119,23 +119,23 @@  discard block
 block discarded – undo
119 119
                                 'name'             => 'wpinv_status',
120 120
                                 'label'            => $label,
121 121
                                 'label_type'       => 'vertical',
122
-                                'placeholder'      => __( 'Select Status', 'invoicing' ),
123
-                                'value'            => $invoice->get_status( 'edit' ),
122
+                                'placeholder'      => __('Select Status', 'invoicing'),
123
+                                'value'            => $invoice->get_status('edit'),
124 124
                                 'select2'          => true,
125 125
                                 'data-allow-clear' => 'false',
126
-                                'options'          => wpinv_get_invoice_statuses( true, false, $invoice )
126
+                                'options'          => wpinv_get_invoice_statuses(true, false, $invoice)
127 127
                             )
128 128
                         );
129 129
 
130 130
                         // Invoice number.
131 131
                         $label = sprintf(
132
-                            __( '%s Number:', 'invoicing' ),
133
-                            ucfirst( $invoice->get_invoice_quote_type() )
132
+                            __('%s Number:', 'invoicing'),
133
+                            ucfirst($invoice->get_invoice_quote_type())
134 134
                         );
135 135
 
136
-                        $info  = sprintf(
137
-                            __( 'Each %s number must be unique.', 'invoicing' ),
138
-                            strtolower( $invoice->get_invoice_quote_type() )
136
+                        $info = sprintf(
137
+                            __('Each %s number must be unique.', 'invoicing'),
138
+                            strtolower($invoice->get_invoice_quote_type())
139 139
                         );
140 140
 
141 141
                         echo aui()->input(
@@ -143,11 +143,11 @@  discard block
 block discarded – undo
143 143
                                 'type'        => 'text',
144 144
                                 'id'          => 'wpinv_number',
145 145
                                 'name'        => 'wpinv_number',
146
-                                'label'       => $label . getpaid_get_help_tip( $info ),
146
+                                'label'       => $label . getpaid_get_help_tip($info),
147 147
                                 'label_type'  => 'vertical',
148
-                                'placeholder' => __( 'Autogenerate', 'invoicing' ),
148
+                                'placeholder' => __('Autogenerate', 'invoicing'),
149 149
                                 'class'       => 'form-control-sm',
150
-                                'value'       => $invoice->get_number( 'edit' ),
150
+                                'value'       => $invoice->get_number('edit'),
151 151
                             )
152 152
                         );
153 153
 
@@ -157,25 +157,25 @@  discard block
 block discarded – undo
157 157
                                 'type'        => 'text',
158 158
                                 'id'          => 'wpinv_cc',
159 159
                                 'name'        => 'wpinv_cc',
160
-                                'label'       => __( 'Email CC:', 'invoicing' ) . getpaid_get_help_tip( __( 'Enter a comma separated list of other emails that should be notified about the invoice.', 'invoicing' ) ),
160
+                                'label'       => __('Email CC:', 'invoicing') . getpaid_get_help_tip(__('Enter a comma separated list of other emails that should be notified about the invoice.', 'invoicing')),
161 161
                                 'label_type'  => 'vertical',
162
-                                'placeholder' => __( '[email protected], [email protected]', 'invoicing' ),
162
+                                'placeholder' => __('[email protected], [email protected]', 'invoicing'),
163 163
                                 'class'       => 'form-control-sm',
164
-                                'value'       => $invoice->get_email_cc( 'edit' ),
164
+                                'value'       => $invoice->get_email_cc('edit'),
165 165
                             )
166 166
                         );
167 167
 
168
-                        do_action( 'wpinv_meta_box_details_inner', $invoice->get_id() );
168
+                        do_action('wpinv_meta_box_details_inner', $invoice->get_id());
169 169
 
170 170
                         // Disable taxes.
171
-                        if ( wpinv_use_taxes() && ! ( $invoice->is_paid() || $invoice->is_refunded() ) ) {
171
+                        if (wpinv_use_taxes() && !($invoice->is_paid() || $invoice->is_refunded())) {
172 172
 
173 173
                             echo aui()->input(
174 174
                                 array(
175 175
                                     'id'          => 'wpinv_taxable',
176 176
                                     'name'        => 'disable_taxes',
177 177
                                     'type'        => 'checkbox',
178
-                                    'label'       => __( 'Disable taxes', 'invoicing' ),
178
+                                    'label'       => __('Disable taxes', 'invoicing'),
179 179
                                     'value'       => '1',
180 180
                                     'checked'     => (bool) $invoice->get_disable_taxes(),
181 181
                                 )
@@ -184,17 +184,17 @@  discard block
 block discarded – undo
184 184
                         }
185 185
 
186 186
                         // Apply a discount.
187
-                        if ( $invoice->get_discount_code( 'edit' ) ) {
187
+                        if ($invoice->get_discount_code('edit')) {
188 188
 
189 189
                             echo aui()->input(
190 190
                                 array(
191 191
                                     'type'        => 'text',
192 192
                                     'id'          => 'wpinv_discount_code',
193 193
                                     'name'        => 'wpinv_discount_code',
194
-                                    'label'       => __( 'Discount Code:', 'invoicing' ),
194
+                                    'label'       => __('Discount Code:', 'invoicing'),
195 195
                                     'label_type'  => 'vertical',
196 196
                                     'class'       => 'form-control-sm',
197
-                                    'value'       => $invoice->get_discount_code( 'edit' ),
197
+                                    'value'       => $invoice->get_discount_code('edit'),
198 198
                                     'extra_attributes' => array(
199 199
                                         'onclick'  => 'this.select();',
200 200
                                         'readonly' => 'true',
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 
205 205
                         }
206 206
 
207
-                        do_action( 'getpaid_metabox_after_invoice_details', $invoice );
207
+                        do_action('getpaid_metabox_after_invoice_details', $invoice);
208 208
 
209 209
                     ?>
210 210
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-payment-meta.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param WP_Post $post
23 23
 	 */
24
-    public static function output( $post ) {
24
+    public static function output($post) {
25 25
 
26 26
         // Prepare the invoice.
27
-        $invoice = new WPInv_Invoice( $post );
27
+        $invoice = new WPInv_Invoice($post);
28 28
 
29 29
         ?>
30 30
 
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
                                 'id'          => 'wpinv_key',
48 48
                                 'name'        => 'wpinv_key',
49 49
                                 'label'       => sprintf(
50
-                                    __( '%s Key:', 'invoicing' ),
51
-                                    ucfirst( $invoice->get_invoice_quote_type() )
50
+                                    __('%s Key:', 'invoicing'),
51
+                                    ucfirst($invoice->get_invoice_quote_type())
52 52
                                 ),
53 53
                                 'label_type'  => 'vertical',
54 54
                                 'class'       => 'form-control-sm',
55
-                                'value'       => $invoice->get_key( 'edit' ),
55
+                                'value'       => $invoice->get_key('edit'),
56 56
                                 'extra_attributes' => array(
57 57
                                     'onclick'  => 'this.select();',
58 58
                                     'readonly' => 'true',
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
                                 'id'          => 'wpinv_view_url',
68 68
                                 'name'        => 'wpinv_view_url',
69 69
                                 'label'       => sprintf(
70
-                                    __( '%s URL:', 'invoicing' ),
71
-                                    ucfirst( $invoice->get_invoice_quote_type() )
70
+                                    __('%s URL:', 'invoicing'),
71
+                                    ucfirst($invoice->get_invoice_quote_type())
72 72
                                 ),
73 73
                                 'label_type'  => 'vertical',
74 74
                                 'class'       => 'form-control-sm',
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
                         );
82 82
 
83 83
                         // If the invoice is paid...
84
-                        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
84
+                        if ($invoice->is_paid() || $invoice->is_refunded()) {
85 85
 
86 86
                             // Payment date.
87 87
                             echo aui()->input(
@@ -89,11 +89,11 @@  discard block
 block discarded – undo
89 89
                                     'type'        => 'datepicker',
90 90
                                     'id'          => 'wpinv_date_completed',
91 91
                                     'name'        => 'date_completed',
92
-                                    'label'       => __( 'Payment Date:', 'invoicing' ),
92
+                                    'label'       => __('Payment Date:', 'invoicing'),
93 93
                                     'label_type'  => 'vertical',
94 94
                                     'placeholder' => 'YYYY-MM-DD 00:00',
95 95
                                     'class'       => 'form-control-sm',
96
-                                    'value'       => $invoice->get_date_completed( 'edit' ),
96
+                                    'value'       => $invoice->get_date_completed('edit'),
97 97
                                     'extra_attributes' => array(
98 98
                                         'data-enable-time' => 'true',
99 99
                                         'data-time_24hr'   => 'true',
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
                                     'type'        => 'text',
109 109
                                     'id'          => 'wpinv_gateway',
110 110
                                     'name'        => 'wpinv_gateway',
111
-                                    'label'       => __( 'Gateway:', 'invoicing' ),
111
+                                    'label'       => __('Gateway:', 'invoicing'),
112 112
                                     'label_type'  => 'vertical',
113 113
                                     'class'       => 'form-control-sm',
114
-                                    'value'       => wpinv_get_gateway_admin_label( $invoice->get_gateway( 'edit' ) ),
114
+                                    'value'       => wpinv_get_gateway_admin_label($invoice->get_gateway('edit')),
115 115
                                     'extra_attributes' => array(
116 116
                                         'onclick'  => 'this.select();',
117 117
                                         'readonly' => 'true',
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
                                     'type'        => 'text',
126 126
                                     'id'          => 'wpinv_transaction_id',
127 127
                                     'name'        => 'wpinv_transaction_id',
128
-                                    'label'       => __( 'Transaction ID:', 'invoicing' ),
128
+                                    'label'       => __('Transaction ID:', 'invoicing'),
129 129
                                     'label_type'  => 'vertical',
130 130
                                     'class'       => 'form-control-sm',
131
-                                    'value'       => $invoice->get_transaction_id( 'edit' ),
132
-                                    'help_text'   => apply_filters( 'wpinv_invoice_transaction_link_' . $invoice->get_gateway( 'edit' ), '', $invoice->get_transaction_id(), $invoice ),
131
+                                    'value'       => $invoice->get_transaction_id('edit'),
132
+                                    'help_text'   => apply_filters('wpinv_invoice_transaction_link_' . $invoice->get_gateway('edit'), '', $invoice->get_transaction_id(), $invoice),
133 133
                                     'extra_attributes' => array(
134 134
                                         'onclick'  => 'this.select();',
135 135
                                         'readonly' => 'true',
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
                                     'type'        => 'text',
144 144
                                     'id'          => 'wpinv_currency',
145 145
                                     'name'        => 'wpinv_currency',
146
-                                    'label'       => __( 'Currency:', 'invoicing' ),
146
+                                    'label'       => __('Currency:', 'invoicing'),
147 147
                                     'label_type'  => 'vertical',
148 148
                                     'class'       => 'form-control-sm',
149
-                                    'value'       => $invoice->get_currency( 'edit' ),
149
+                                    'value'       => $invoice->get_currency('edit'),
150 150
                                     'extra_attributes' => array(
151 151
                                         'onclick'  => 'this.select();',
152 152
                                         'readonly' => 'true',
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 
157 157
                         } else {
158 158
 
159
-                            if ( 'wpi_invoice' == $invoice->get_post_type() ) {
159
+                            if ('wpi_invoice' == $invoice->get_post_type()) {
160 160
 
161 161
                                 // Payment URL.
162 162
                                 echo aui()->input(
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
                                         'type'        => 'text',
165 165
                                         'id'          => 'wpinv_payment_url',
166 166
                                         'name'        => 'wpinv_payment_url',
167
-                                        'label'       => __( 'Payment URL:', 'invoicing' ),
167
+                                        'label'       => __('Payment URL:', 'invoicing'),
168 168
                                         'label_type'  => 'vertical',
169 169
                                         'class'       => 'form-control-sm',
170 170
                                         'value'       => $invoice->get_checkout_payment_url(),
@@ -180,13 +180,13 @@  discard block
 block discarded – undo
180 180
                                     array(
181 181
                                         'id'               => 'wpinv_gateway',
182 182
                                         'name'             => 'wpinv_gateway',
183
-                                        'label'            => __( 'Gateway:', 'invoicing' ),
183
+                                        'label'            => __('Gateway:', 'invoicing'),
184 184
                                         'label_type'       => 'vertical',
185
-                                        'placeholder'      => __( 'Select Gateway', 'invoicing' ),
186
-                                        'value'            => $invoice->get_gateway( 'edit' ),
185
+                                        'placeholder'      => __('Select Gateway', 'invoicing'),
186
+                                        'value'            => $invoice->get_gateway('edit'),
187 187
                                         'select2'          => true,
188 188
                                         'data-allow-clear' => 'false',
189
-                                        'options'          => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ),
189
+                                        'options'          => wp_list_pluck(wpinv_get_enabled_payment_gateways(true), 'admin_label'),
190 190
                                     )
191 191
                                 );
192 192
 
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 2 patches
Indentation   +303 added lines, -303 removed lines patch added patch discarded remove patch
@@ -14,73 +14,73 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
28
-	public $admin_url;
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28
+    public $admin_url;
29 29
 	
30
-	/**
31
-	 * Reports components.
32
-	 *
33
-	 * @var GetPaid_Reports
34
-	 */
30
+    /**
31
+     * Reports components.
32
+     *
33
+     * @var GetPaid_Reports
34
+     */
35 35
     public $reports;
36 36
 
37 37
     /**
38
-	 * Class constructor.
39
-	 */
40
-	public function __construct(){
38
+     * Class constructor.
39
+     */
40
+    public function __construct(){
41 41
 
42 42
         $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
44
-		$this->reports     = new GetPaid_Reports();
43
+        $this->admin_url   = plugins_url( '/', __FILE__ );
44
+        $this->reports     = new GetPaid_Reports();
45 45
 
46 46
         if ( is_admin() ) {
47
-			$this->init_admin_hooks();
47
+            $this->init_admin_hooks();
48 48
         }
49 49
 
50 50
     }
51 51
 
52 52
     /**
53
-	 * Init action and filter hooks
54
-	 *
55
-	 */
56
-	private function init_admin_hooks() {
53
+     * Init action and filter hooks
54
+     *
55
+     */
56
+    private function init_admin_hooks() {
57 57
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
58 58
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59 59
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60 60
         add_action( 'admin_init', array( $this, 'activation_redirect') );
61 61
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
62
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
+        add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
65
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
66 66
         add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
67
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
68
-		do_action( 'getpaid_init_admin_hooks', $this );
67
+        add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
68
+        do_action( 'getpaid_init_admin_hooks', $this );
69 69
 
70 70
     }
71 71
 
72 72
     /**
73
-	 * Register admin scripts
74
-	 *
75
-	 */
76
-	public function enqeue_scripts() {
73
+     * Register admin scripts
74
+     *
75
+     */
76
+    public function enqeue_scripts() {
77 77
         global $current_screen, $pagenow;
78 78
 
79
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
80
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
79
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
80
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
81 81
 
82 82
         if ( ! empty( $current_screen->post_type ) ) {
83
-			$page = $current_screen->post_type;
83
+            $page = $current_screen->post_type;
84 84
         }
85 85
 
86 86
         // General styles.
@@ -103,54 +103,54 @@  discard block
 block discarded – undo
103 103
         }
104 104
 
105 105
         // Payment form scripts.
106
-		if ( 'wpi_payment_form' == $page && $editing ) {
106
+        if ( 'wpi_payment_form' == $page && $editing ) {
107 107
             $this->load_payment_form_scripts();
108 108
         }
109 109
 
110
-		if ( $page == 'wpinv-subscriptions' ) {
111
-			wp_enqueue_script( 'postbox' );
112
-		}
110
+        if ( $page == 'wpinv-subscriptions' ) {
111
+            wp_enqueue_script( 'postbox' );
112
+        }
113 113
 
114 114
     }
115 115
 
116 116
     /**
117
-	 * Returns admin js translations.
118
-	 *
119
-	 */
120
-	protected function get_admin_i18() {
117
+     * Returns admin js translations.
118
+     *
119
+     */
120
+    protected function get_admin_i18() {
121 121
         global $post;
122 122
 
123
-		$date_range = array(
124
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
125
-		);
123
+        $date_range = array(
124
+            'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
125
+        );
126 126
 
127
-		if ( $date_range['period'] == 'custom' ) {
127
+        if ( $date_range['period'] == 'custom' ) {
128 128
 			
129
-			if ( isset( $_GET['from'] ) ) {
130
-				$date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
131
-			}
129
+            if ( isset( $_GET['from'] ) ) {
130
+                $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
131
+            }
132 132
 
133
-			if ( isset( $_GET['to'] ) ) {
134
-				$date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
135
-			}
133
+            if ( isset( $_GET['to'] ) ) {
134
+                $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
135
+            }
136 136
 
137
-		}
137
+        }
138 138
 
139 139
         $i18n = array(
140 140
             'ajax_url'                  => admin_url( 'admin-ajax.php' ),
141 141
             'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
142
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
143
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
144
-			'rest_root'                 => esc_url_raw( rest_url() ),
145
-			'date_range'                => $date_range,
142
+            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
143
+            'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
144
+            'rest_root'                 => esc_url_raw( rest_url() ),
145
+            'date_range'                => $date_range,
146 146
             'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
147 147
             'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
148 148
             'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
149 149
             'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
150 150
             'tax'                       => wpinv_tax_amount(),
151 151
             'discount'                  => 0,
152
-			'currency_symbol'           => wpinv_currency_symbol(),
153
-			'currency'                  => wpinv_get_currency(),
152
+            'currency_symbol'           => wpinv_currency_symbol(),
153
+            'currency'                  => wpinv_get_currency(),
154 154
             'currency_pos'              => wpinv_currency_position(),
155 155
             'thousand_sep'              => wpinv_thousands_separator(),
156 156
             'decimal_sep'               => wpinv_decimal_separator(),
@@ -173,112 +173,112 @@  discard block
 block discarded – undo
173 173
             'searching'                 => __( 'Searching', 'invoicing' ),
174 174
         );
175 175
 
176
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
176
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
177 177
 
178
-			$invoice              = new WPInv_Invoice( $post );
179
-			$i18n['save_invoice'] = sprintf(
180
-				__( 'Save %s', 'invoicing' ),
181
-				ucfirst( $invoice->get_invoice_quote_type() )
182
-			);
178
+            $invoice              = new WPInv_Invoice( $post );
179
+            $i18n['save_invoice'] = sprintf(
180
+                __( 'Save %s', 'invoicing' ),
181
+                ucfirst( $invoice->get_invoice_quote_type() )
182
+            );
183 183
 
184
-			$i18n['invoice_description'] = sprintf(
185
-				__( '%s Description', 'invoicing' ),
186
-				ucfirst( $invoice->get_invoice_quote_type() )
187
-			);
184
+            $i18n['invoice_description'] = sprintf(
185
+                __( '%s Description', 'invoicing' ),
186
+                ucfirst( $invoice->get_invoice_quote_type() )
187
+            );
188 188
 
189
-		}
190
-		return $i18n;
191
-	}
189
+        }
190
+        return $i18n;
191
+    }
192 192
 
193
-	/**
194
-	 * Change the admin footer text on GetPaid admin pages.
195
-	 *
196
-	 * @since  2.0.0
197
-	 * @param  string $footer_text
198
-	 * @return string
199
-	 */
200
-	public function admin_footer_text( $footer_text ) {
201
-		global $current_screen;
193
+    /**
194
+     * Change the admin footer text on GetPaid admin pages.
195
+     *
196
+     * @since  2.0.0
197
+     * @param  string $footer_text
198
+     * @return string
199
+     */
200
+    public function admin_footer_text( $footer_text ) {
201
+        global $current_screen;
202 202
 
203
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
203
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
204 204
 
205 205
         if ( ! empty( $current_screen->post_type ) ) {
206
-			$page = $current_screen->post_type;
206
+            $page = $current_screen->post_type;
207 207
         }
208 208
 
209 209
         // General styles.
210 210
         if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
211 211
 
212
-			// Change the footer text
213
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
214
-
215
-				$rating_url  = esc_url(
216
-					wp_nonce_url(
217
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
218
-						'getpaid-nonce',
219
-						'getpaid-nonce'
220
-						)
221
-				);
222
-
223
-				$footer_text = sprintf(
224
-					/* translators: %s: five stars */
225
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
226
-					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
227
-				);
228
-
229
-			} else {
230
-
231
-				$footer_text = sprintf(
232
-					/* translators: %s: GetPaid */
233
-					__( 'Thank you for using %s!', 'invoicing' ),
234
-					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
235
-				);
236
-
237
-			}
238
-
239
-		}
240
-
241
-		return $footer_text;
242
-	}
243
-
244
-	/**
245
-	 * Redirects to wp.org to rate the plugin.
246
-	 *
247
-	 * @since  2.0.0
248
-	 */
249
-	public function redirect_to_wordpress_rating_page() {
250
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
251
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
252
-		exit;
253
-	}
212
+            // Change the footer text
213
+            if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
214
+
215
+                $rating_url  = esc_url(
216
+                    wp_nonce_url(
217
+                        admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
218
+                        'getpaid-nonce',
219
+                        'getpaid-nonce'
220
+                        )
221
+                );
222
+
223
+                $footer_text = sprintf(
224
+                    /* translators: %s: five stars */
225
+                    __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
226
+                    "<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
227
+                );
228
+
229
+            } else {
230
+
231
+                $footer_text = sprintf(
232
+                    /* translators: %s: GetPaid */
233
+                    __( 'Thank you for using %s!', 'invoicing' ),
234
+                    "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
235
+                );
236
+
237
+            }
238
+
239
+        }
240
+
241
+        return $footer_text;
242
+    }
254 243
 
255 244
     /**
256
-	 * Loads payment form js.
257
-	 *
258
-	 */
259
-	protected function load_payment_form_scripts() {
245
+     * Redirects to wp.org to rate the plugin.
246
+     *
247
+     * @since  2.0.0
248
+     */
249
+    public function redirect_to_wordpress_rating_page() {
250
+        update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
251
+        wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
252
+        exit;
253
+    }
254
+
255
+    /**
256
+     * Loads payment form js.
257
+     *
258
+     */
259
+    protected function load_payment_form_scripts() {
260 260
         global $post;
261 261
 
262 262
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
263
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
264
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
263
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
264
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
265 265
 
266
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
267
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
266
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
267
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
268 268
 
269
-		wp_localize_script(
269
+        wp_localize_script(
270 270
             'wpinv-admin-payment-form-script',
271 271
             'wpinvPaymentFormAdmin',
272 272
             array(
273
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
274
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
275
-				'currency'      => wpinv_currency_symbol(),
276
-				'position'      => wpinv_currency_position(),
277
-				'decimals'      => (int) wpinv_decimals(),
278
-				'thousands_sep' => wpinv_thousands_separator(),
279
-				'decimals_sep'  => wpinv_decimal_separator(),
280
-				'form_items'    => gepaid_get_form_items( $post->ID ),
281
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
273
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
274
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
275
+                'currency'      => wpinv_currency_symbol(),
276
+                'position'      => wpinv_currency_position(),
277
+                'decimals'      => (int) wpinv_decimals(),
278
+                'thousands_sep' => wpinv_thousands_separator(),
279
+                'decimals_sep'  => wpinv_decimal_separator(),
280
+                'form_items'    => gepaid_get_form_items( $post->ID ),
281
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
282 282
             )
283 283
         );
284 284
 
@@ -287,20 +287,20 @@  discard block
 block discarded – undo
287 287
     }
288 288
 
289 289
     /**
290
-	 * Add our classes to admin pages.
290
+     * Add our classes to admin pages.
291 291
      *
292 292
      * @param string $classes
293 293
      * @return string
294
-	 *
295
-	 */
294
+     *
295
+     */
296 296
     public function admin_body_class( $classes ) {
297
-		global $pagenow, $post, $current_screen;
297
+        global $pagenow, $post, $current_screen;
298 298
 
299 299
 
300 300
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
301 301
 
302 302
         if ( ! empty( $current_screen->post_type ) ) {
303
-			$page = $current_screen->post_type;
303
+            $page = $current_screen->post_type;
304 304
         }
305 305
 
306 306
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -309,29 +309,29 @@  discard block
 block discarded – undo
309 309
 
310 310
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
311 311
             $classes .= ' wpinv-cpt wpinv';
312
-		}
312
+        }
313 313
 		
314
-		if ( getpaid_is_invoice_post_type( $page ) ) {
314
+        if ( getpaid_is_invoice_post_type( $page ) ) {
315 315
             $classes .= ' getpaid-is-invoice-cpt';
316 316
         }
317 317
 
318
-		return $classes;
318
+        return $classes;
319 319
     }
320 320
 
321 321
     /**
322
-	 * Maybe show the AyeCode Connect Notice.
323
-	 */
324
-	public function init_ayecode_connect_helper(){
322
+     * Maybe show the AyeCode Connect Notice.
323
+     */
324
+    public function init_ayecode_connect_helper(){
325 325
 
326 326
         new AyeCode_Connect_Helper(
327 327
             array(
328
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
329
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
330
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
331
-				'connect_button'    => __("Connect Site","invoicing"),
332
-				'connecting_button'    => __("Connecting...","invoicing"),
333
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
334
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
328
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
329
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
330
+                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
331
+                'connect_button'    => __("Connect Site","invoicing"),
332
+                'connecting_button'    => __("Connecting...","invoicing"),
333
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
334
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
335 335
             ),
336 336
             array( 'wpi-addons' )
337 337
         );
@@ -343,21 +343,21 @@  discard block
 block discarded – undo
343 343
      */
344 344
     public function activation_redirect() {
345 345
 
346
-		// Bail if no activation redirect.
347
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
348
-			return;
349
-		}
346
+        // Bail if no activation redirect.
347
+        if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
348
+            return;
349
+        }
350 350
 
351
-		// Delete the redirect transient.
352
-		delete_transient( '_wpinv_activation_redirect' );
351
+        // Delete the redirect transient.
352
+        delete_transient( '_wpinv_activation_redirect' );
353 353
 
354
-		// Bail if activating from network, or bulk
355
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
356
-			return;
357
-		}
354
+        // Bail if activating from network, or bulk
355
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
356
+            return;
357
+        }
358 358
 
359
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
360
-		exit;
359
+        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
360
+        exit;
361 361
     }
362 362
 
363 363
     /**
@@ -372,162 +372,162 @@  discard block
 block discarded – undo
372 372
 
373 373
     }
374 374
 
375
-	/**
375
+    /**
376 376
      * Sends a payment reminder to a customer.
377
-	 * 
378
-	 * @param array $args
377
+     * 
378
+     * @param array $args
379 379
      */
380 380
     public function send_customer_invoice( $args ) {
381
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
381
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
382 382
 
383
-		if ( $sent ) {
384
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
385
-		} else {
386
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
387
-		}
383
+        if ( $sent ) {
384
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
385
+        } else {
386
+            $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
387
+        }
388 388
 
389
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
390
-		exit;
391
-	}
389
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
390
+        exit;
391
+    }
392 392
 
393
-	/**
393
+    /**
394 394
      * Sends a payment reminder to a customer.
395
-	 * 
396
-	 * @param array $args
395
+     * 
396
+     * @param array $args
397 397
      */
398 398
     public function send_customer_payment_reminder( $args ) {
399
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
399
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
400 400
 
401
-		if ( $sent ) {
402
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
403
-		} else {
404
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
405
-		}
401
+        if ( $sent ) {
402
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
403
+        } else {
404
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
405
+        }
406 406
 
407
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
408
-		exit;
409
-	}
407
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
408
+        exit;
409
+    }
410 410
 
411
-	/**
411
+    /**
412 412
      * Resets tax rates.
413
-	 * 
413
+     * 
414 414
      */
415 415
     public function admin_reset_tax_rates() {
416 416
 
417
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
418
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
419
-		exit;
417
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
418
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
419
+        exit;
420 420
 
421
-	}
421
+    }
422 422
 
423 423
     /**
424
-	 * Returns an array of admin notices.
425
-	 *
426
-	 * @since       1.0.19
424
+     * Returns an array of admin notices.
425
+     *
426
+     * @since       1.0.19
427 427
      * @return array
428
-	 */
429
-	public function get_notices() {
430
-		$notices = get_option( 'wpinv_admin_notices' );
428
+     */
429
+    public function get_notices() {
430
+        $notices = get_option( 'wpinv_admin_notices' );
431 431
         return is_array( $notices ) ? $notices : array();
432
-	}
433
-
434
-	/**
435
-	 * Clears all admin notices
436
-	 *
437
-	 * @access      public
438
-	 * @since       1.0.19
439
-	 */
440
-	public function clear_notices() {
441
-		delete_option( 'wpinv_admin_notices' );
442
-	}
443
-
444
-	/**
445
-	 * Saves a new admin notice
446
-	 *
447
-	 * @access      public
448
-	 * @since       1.0.19
449
-	 */
450
-	public function save_notice( $type, $message ) {
451
-		$notices = $this->get_notices();
452
-
453
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
454
-			$notices[ $type ] = array();
455
-		}
456
-
457
-		$notices[ $type ][] = $message;
458
-
459
-		update_option( 'wpinv_admin_notices', $notices );
460
-	}
461
-
462
-	/**
463
-	 * Displays a success notice
464
-	 *
465
-	 * @param       string $msg The message to qeue.
466
-	 * @access      public
467
-	 * @since       1.0.19
468
-	 */
469
-	public function show_success( $msg ) {
470
-		$this->save_notice( 'success', $msg );
471
-	}
472
-
473
-	/**
474
-	 * Displays a error notice
475
-	 *
476
-	 * @access      public
477
-	 * @param       string $msg The message to qeue.
478
-	 * @since       1.0.19
479
-	 */
480
-	public function show_error( $msg ) {
481
-		$this->save_notice( 'error', $msg );
482
-	}
483
-
484
-	/**
485
-	 * Displays a warning notice
486
-	 *
487
-	 * @access      public
488
-	 * @param       string $msg The message to qeue.
489
-	 * @since       1.0.19
490
-	 */
491
-	public function show_warning( $msg ) {
492
-		$this->save_notice( 'warning', $msg );
493
-	}
494
-
495
-	/**
496
-	 * Displays a info notice
497
-	 *
498
-	 * @access      public
499
-	 * @param       string $msg The message to qeue.
500
-	 * @since       1.0.19
501
-	 */
502
-	public function show_info( $msg ) {
503
-		$this->save_notice( 'info', $msg );
504
-	}
505
-
506
-	/**
507
-	 * Show notices
508
-	 *
509
-	 * @access      public
510
-	 * @since       1.0.19
511
-	 */
512
-	public function show_notices() {
432
+    }
433
+
434
+    /**
435
+     * Clears all admin notices
436
+     *
437
+     * @access      public
438
+     * @since       1.0.19
439
+     */
440
+    public function clear_notices() {
441
+        delete_option( 'wpinv_admin_notices' );
442
+    }
443
+
444
+    /**
445
+     * Saves a new admin notice
446
+     *
447
+     * @access      public
448
+     * @since       1.0.19
449
+     */
450
+    public function save_notice( $type, $message ) {
451
+        $notices = $this->get_notices();
452
+
453
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
454
+            $notices[ $type ] = array();
455
+        }
456
+
457
+        $notices[ $type ][] = $message;
458
+
459
+        update_option( 'wpinv_admin_notices', $notices );
460
+    }
461
+
462
+    /**
463
+     * Displays a success notice
464
+     *
465
+     * @param       string $msg The message to qeue.
466
+     * @access      public
467
+     * @since       1.0.19
468
+     */
469
+    public function show_success( $msg ) {
470
+        $this->save_notice( 'success', $msg );
471
+    }
472
+
473
+    /**
474
+     * Displays a error notice
475
+     *
476
+     * @access      public
477
+     * @param       string $msg The message to qeue.
478
+     * @since       1.0.19
479
+     */
480
+    public function show_error( $msg ) {
481
+        $this->save_notice( 'error', $msg );
482
+    }
483
+
484
+    /**
485
+     * Displays a warning notice
486
+     *
487
+     * @access      public
488
+     * @param       string $msg The message to qeue.
489
+     * @since       1.0.19
490
+     */
491
+    public function show_warning( $msg ) {
492
+        $this->save_notice( 'warning', $msg );
493
+    }
494
+
495
+    /**
496
+     * Displays a info notice
497
+     *
498
+     * @access      public
499
+     * @param       string $msg The message to qeue.
500
+     * @since       1.0.19
501
+     */
502
+    public function show_info( $msg ) {
503
+        $this->save_notice( 'info', $msg );
504
+    }
505
+
506
+    /**
507
+     * Show notices
508
+     *
509
+     * @access      public
510
+     * @since       1.0.19
511
+     */
512
+    public function show_notices() {
513 513
 
514 514
         $notices = $this->get_notices();
515 515
         $this->clear_notices();
516 516
 
517
-		foreach ( $notices as $type => $messages ) {
517
+        foreach ( $notices as $type => $messages ) {
518 518
 
519
-			if ( ! is_array( $messages ) ) {
520
-				continue;
521
-			}
519
+            if ( ! is_array( $messages ) ) {
520
+                continue;
521
+            }
522 522
 
523 523
             $type  = sanitize_key( $type );
524
-			foreach ( $messages as $message ) {
524
+            foreach ( $messages as $message ) {
525 525
                 $message = wp_kses_post( $message );
526
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
526
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
527 527
             }
528 528
 
529 529
         }
530 530
 
531
-	}
531
+    }
532 532
 
533 533
 }
Please login to merge, or discard this patch.
Spacing   +147 added lines, -147 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
  * The main admin class.
@@ -37,13 +37,13 @@  discard block
 block discarded – undo
37 37
     /**
38 38
 	 * Class constructor.
39 39
 	 */
40
-	public function __construct(){
40
+	public function __construct() {
41 41
 
42
-        $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
42
+        $this->admin_path = plugin_dir_path(__FILE__);
43
+		$this->admin_url   = plugins_url('/', __FILE__);
44 44
 		$this->reports     = new GetPaid_Reports();
45 45
 
46
-        if ( is_admin() ) {
46
+        if (is_admin()) {
47 47
 			$this->init_admin_hooks();
48 48
         }
49 49
 
@@ -54,18 +54,18 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 */
56 56
 	private function init_admin_hooks() {
57
-        add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
58
-        add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59
-        add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60
-        add_action( 'admin_init', array( $this, 'activation_redirect') );
61
-        add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
66
-        add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
67
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
68
-		do_action( 'getpaid_init_admin_hooks', $this );
57
+        add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'));
58
+        add_filter('admin_body_class', array($this, 'admin_body_class'));
59
+        add_action('admin_init', array($this, 'init_ayecode_connect_helper'));
60
+        add_action('admin_init', array($this, 'activation_redirect'));
61
+        add_action('admin_init', array($this, 'maybe_do_admin_action'));
62
+		add_action('admin_notices', array($this, 'show_notices'));
63
+		add_action('getpaid_authenticated_admin_action_rate_plugin', array($this, 'redirect_to_wordpress_rating_page'));
64
+		add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice'));
65
+		add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder'));
66
+        add_action('getpaid_authenticated_admin_action_reset_tax_rates', array($this, 'admin_reset_tax_rates'));
67
+		add_filter('admin_footer_text', array($this, 'admin_footer_text'));
68
+		do_action('getpaid_init_admin_hooks', $this);
69 69
 
70 70
     }
71 71
 
@@ -76,39 +76,39 @@  discard block
 block discarded – undo
76 76
 	public function enqeue_scripts() {
77 77
         global $current_screen, $pagenow;
78 78
 
79
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
79
+		$page    = isset($_GET['page']) ? $_GET['page'] : '';
80 80
 		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
81 81
 
82
-        if ( ! empty( $current_screen->post_type ) ) {
82
+        if (!empty($current_screen->post_type)) {
83 83
 			$page = $current_screen->post_type;
84 84
         }
85 85
 
86 86
         // General styles.
87
-        if ( false !== stripos( $page, 'wpi' ) ) {
87
+        if (false !== stripos($page, 'wpi')) {
88 88
 
89 89
             // Styles.
90
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
91
-            wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version );
92
-            wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' );
93
-            wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' );
90
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
91
+            wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version);
92
+            wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all');
93
+            wp_enqueue_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16');
94 94
 
95 95
             // Scripts.
96
-            wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true );
97
-            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION );
96
+            wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '4.0.13', true);
97
+            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION);
98 98
 
99
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
100
-            wp_enqueue_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker' ),  $version );
101
-            wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) );
99
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
100
+            wp_enqueue_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip', 'wp-color-picker', 'jquery-ui-datepicker'), $version);
101
+            wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18()));
102 102
 
103 103
         }
104 104
 
105 105
         // Payment form scripts.
106
-		if ( 'wpi_payment_form' == $page && $editing ) {
106
+		if ('wpi_payment_form' == $page && $editing) {
107 107
             $this->load_payment_form_scripts();
108 108
         }
109 109
 
110
-		if ( $page == 'wpinv-subscriptions' ) {
111
-			wp_enqueue_script( 'postbox' );
110
+		if ($page == 'wpinv-subscriptions') {
111
+			wp_enqueue_script('postbox');
112 112
 		}
113 113
 
114 114
     }
@@ -121,32 +121,32 @@  discard block
 block discarded – undo
121 121
         global $post;
122 122
 
123 123
 		$date_range = array(
124
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
124
+			'period' => isset($_GET['date_range']) ? sanitize_text_field($_GET['date_range']) : '7_days'
125 125
 		);
126 126
 
127
-		if ( $date_range['period'] == 'custom' ) {
127
+		if ($date_range['period'] == 'custom') {
128 128
 			
129
-			if ( isset( $_GET['from'] ) ) {
130
-				$date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
129
+			if (isset($_GET['from'])) {
130
+				$date_range['after'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['from']), current_time('timestamp')) - DAY_IN_SECONDS);
131 131
 			}
132 132
 
133
-			if ( isset( $_GET['to'] ) ) {
134
-				$date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
133
+			if (isset($_GET['to'])) {
134
+				$date_range['before'] = date('Y-m-d', strtotime(sanitize_text_field($_GET['to']), current_time('timestamp')) + DAY_IN_SECONDS);
135 135
 			}
136 136
 
137 137
 		}
138 138
 
139 139
         $i18n = array(
140
-            'ajax_url'                  => admin_url( 'admin-ajax.php' ),
141
-            'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
142
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
143
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
144
-			'rest_root'                 => esc_url_raw( rest_url() ),
140
+            'ajax_url'                  => admin_url('admin-ajax.php'),
141
+            'post_ID'                   => isset($post->ID) ? $post->ID : '',
142
+			'wpinv_nonce'               => wp_create_nonce('wpinv-nonce'),
143
+			'rest_nonce'                => wp_create_nonce('wp_rest'),
144
+			'rest_root'                 => esc_url_raw(rest_url()),
145 145
 			'date_range'                => $date_range,
146
-            'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
147
-            'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
148
-            'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
149
-            'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
146
+            'add_invoice_note_nonce'    => wp_create_nonce('add-invoice-note'),
147
+            'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'),
148
+            'invoice_item_nonce'        => wp_create_nonce('invoice-item'),
149
+            'billing_details_nonce'     => wp_create_nonce('get-billing-details'),
150 150
             'tax'                       => wpinv_tax_amount(),
151 151
             'discount'                  => 0,
152 152
 			'currency_symbol'           => wpinv_currency_symbol(),
@@ -155,35 +155,35 @@  discard block
 block discarded – undo
155 155
             'thousand_sep'              => wpinv_thousands_separator(),
156 156
             'decimal_sep'               => wpinv_decimal_separator(),
157 157
             'decimals'                  => wpinv_decimals(),
158
-            'save_invoice'              => __( 'Save Invoice', 'invoicing' ),
159
-            'status_publish'            => wpinv_status_nicename( 'publish' ),
160
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
161
-            'delete_tax_rate'           => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ),
162
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
163
-            'FillBillingDetails'        => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ),
164
-            'confirmCalcTotals'         => __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ),
165
-            'AreYouSure'                => __( 'Are you sure?', 'invoicing' ),
166
-            'errDeleteItem'             => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ),
167
-            'delete_subscription'       => __( 'Are you sure you want to delete this subscription?', 'invoicing' ),
168
-            'action_edit'               => __( 'Edit', 'invoicing' ),
169
-            'action_cancel'             => __( 'Cancel', 'invoicing' ),
170
-            'item_description'          => __( 'Item Description', 'invoicing' ),
171
-            'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
172
-            'discount_description'      => __( 'Discount Description', 'invoicing' ),
173
-            'searching'                 => __( 'Searching', 'invoicing' ),
158
+            'save_invoice'              => __('Save Invoice', 'invoicing'),
159
+            'status_publish'            => wpinv_status_nicename('publish'),
160
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
161
+            'delete_tax_rate'           => __('Are you sure you wish to delete this tax rate?', 'invoicing'),
162
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
163
+            'FillBillingDetails'        => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'),
164
+            'confirmCalcTotals'         => __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'),
165
+            'AreYouSure'                => __('Are you sure?', 'invoicing'),
166
+            'errDeleteItem'             => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'),
167
+            'delete_subscription'       => __('Are you sure you want to delete this subscription?', 'invoicing'),
168
+            'action_edit'               => __('Edit', 'invoicing'),
169
+            'action_cancel'             => __('Cancel', 'invoicing'),
170
+            'item_description'          => __('Item Description', 'invoicing'),
171
+            'invoice_description'       => __('Invoice Description', 'invoicing'),
172
+            'discount_description'      => __('Discount Description', 'invoicing'),
173
+            'searching'                 => __('Searching', 'invoicing'),
174 174
         );
175 175
 
176
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
176
+		if (!empty($post) && getpaid_is_invoice_post_type($post->post_type)) {
177 177
 
178
-			$invoice              = new WPInv_Invoice( $post );
178
+			$invoice              = new WPInv_Invoice($post);
179 179
 			$i18n['save_invoice'] = sprintf(
180
-				__( 'Save %s', 'invoicing' ),
181
-				ucfirst( $invoice->get_invoice_quote_type() )
180
+				__('Save %s', 'invoicing'),
181
+				ucfirst($invoice->get_invoice_quote_type())
182 182
 			);
183 183
 
184 184
 			$i18n['invoice_description'] = sprintf(
185
-				__( '%s Description', 'invoicing' ),
186
-				ucfirst( $invoice->get_invoice_quote_type() )
185
+				__('%s Description', 'invoicing'),
186
+				ucfirst($invoice->get_invoice_quote_type())
187 187
 			);
188 188
 
189 189
 		}
@@ -197,24 +197,24 @@  discard block
 block discarded – undo
197 197
 	 * @param  string $footer_text
198 198
 	 * @return string
199 199
 	 */
200
-	public function admin_footer_text( $footer_text ) {
200
+	public function admin_footer_text($footer_text) {
201 201
 		global $current_screen;
202 202
 
203
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
203
+		$page = isset($_GET['page']) ? $_GET['page'] : '';
204 204
 
205
-        if ( ! empty( $current_screen->post_type ) ) {
205
+        if (!empty($current_screen->post_type)) {
206 206
 			$page = $current_screen->post_type;
207 207
         }
208 208
 
209 209
         // General styles.
210
-        if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
210
+        if (apply_filters('getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing()) && false !== stripos($page, 'wpi')) {
211 211
 
212 212
 			// Change the footer text
213
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
213
+			if (!get_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', true)) {
214 214
 
215
-				$rating_url  = esc_url(
215
+				$rating_url = esc_url(
216 216
 					wp_nonce_url(
217
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
217
+						admin_url('admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin'),
218 218
 						'getpaid-nonce',
219 219
 						'getpaid-nonce'
220 220
 						)
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 
223 223
 				$footer_text = sprintf(
224 224
 					/* translators: %s: five stars */
225
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
225
+					__('If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing'),
226 226
 					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
227 227
 				);
228 228
 
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 
231 231
 				$footer_text = sprintf(
232 232
 					/* translators: %s: GetPaid */
233
-					__( 'Thank you for using %s!', 'invoicing' ),
233
+					__('Thank you for using %s!', 'invoicing'),
234 234
 					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
235 235
 				);
236 236
 
@@ -247,8 +247,8 @@  discard block
 block discarded – undo
247 247
 	 * @since  2.0.0
248 248
 	 */
249 249
 	public function redirect_to_wordpress_rating_page() {
250
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
251
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
250
+		update_user_meta(get_current_user_id(), 'getpaid_admin_footer_text_rated', 1);
251
+		wp_redirect('https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post');
252 252
 		exit;
253 253
 	}
254 254
 
@@ -259,30 +259,30 @@  discard block
 block discarded – undo
259 259
 	protected function load_payment_form_scripts() {
260 260
         global $post;
261 261
 
262
-        wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
263
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
264
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
262
+        wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
263
+		wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
264
+		wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
265 265
 
266
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
267
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
266
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
267
+		wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
268 268
 
269 269
 		wp_localize_script(
270 270
             'wpinv-admin-payment-form-script',
271 271
             'wpinvPaymentFormAdmin',
272 272
             array(
273
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
274
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
273
+				'elements'      => wpinv_get_data('payment-form-elements'),
274
+				'form_elements' => getpaid_get_payment_form_elements($post->ID),
275 275
 				'currency'      => wpinv_currency_symbol(),
276 276
 				'position'      => wpinv_currency_position(),
277 277
 				'decimals'      => (int) wpinv_decimals(),
278 278
 				'thousands_sep' => wpinv_thousands_separator(),
279 279
 				'decimals_sep'  => wpinv_decimal_separator(),
280
-				'form_items'    => gepaid_get_form_items( $post->ID ),
280
+				'form_items'    => gepaid_get_form_items($post->ID),
281 281
 				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
282 282
             )
283 283
         );
284 284
 
285
-        wp_enqueue_script( 'wpinv-admin-payment-form-script' );
285
+        wp_enqueue_script('wpinv-admin-payment-form-script');
286 286
 
287 287
     }
288 288
 
@@ -293,25 +293,25 @@  discard block
 block discarded – undo
293 293
      * @return string
294 294
 	 *
295 295
 	 */
296
-    public function admin_body_class( $classes ) {
296
+    public function admin_body_class($classes) {
297 297
 		global $pagenow, $post, $current_screen;
298 298
 
299 299
 
300
-        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
300
+        $page = isset($_GET['page']) ? $_GET['page'] : '';
301 301
 
302
-        if ( ! empty( $current_screen->post_type ) ) {
302
+        if (!empty($current_screen->post_type)) {
303 303
 			$page = $current_screen->post_type;
304 304
         }
305 305
 
306
-        if ( false !== stripos( $page, 'wpi' ) ) {
307
-            $classes .= ' wpi-' . sanitize_key( $page );
306
+        if (false !== stripos($page, 'wpi')) {
307
+            $classes .= ' wpi-' . sanitize_key($page);
308 308
         }
309 309
 
310
-        if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
310
+        if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) {
311 311
             $classes .= ' wpinv-cpt wpinv';
312 312
 		}
313 313
 		
314
-		if ( getpaid_is_invoice_post_type( $page ) ) {
314
+		if (getpaid_is_invoice_post_type($page)) {
315 315
             $classes .= ' getpaid-is-invoice-cpt';
316 316
         }
317 317
 
@@ -321,19 +321,19 @@  discard block
 block discarded – undo
321 321
     /**
322 322
 	 * Maybe show the AyeCode Connect Notice.
323 323
 	 */
324
-	public function init_ayecode_connect_helper(){
324
+	public function init_ayecode_connect_helper() {
325 325
 
326 326
         new AyeCode_Connect_Helper(
327 327
             array(
328
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
329
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
330
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
331
-				'connect_button'    => __("Connect Site","invoicing"),
332
-				'connecting_button'    => __("Connecting...","invoicing"),
333
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
334
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
328
+				'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
329
+				'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
330
+				'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
331
+				'connect_button'    => __("Connect Site", "invoicing"),
332
+				'connecting_button'    => __("Connecting...", "invoicing"),
333
+				'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
334
+				'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
335 335
             ),
336
-            array( 'wpi-addons' )
336
+            array('wpi-addons')
337 337
         );
338 338
 
339 339
     }
@@ -344,19 +344,19 @@  discard block
 block discarded – undo
344 344
     public function activation_redirect() {
345 345
 
346 346
 		// Bail if no activation redirect.
347
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || wp_doing_ajax() ) {
347
+		if (!get_transient('_wpinv_activation_redirect') || wp_doing_ajax()) {
348 348
 			return;
349 349
 		}
350 350
 
351 351
 		// Delete the redirect transient.
352
-		delete_transient( '_wpinv_activation_redirect' );
352
+		delete_transient('_wpinv_activation_redirect');
353 353
 
354 354
 		// Bail if activating from network, or bulk
355
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
355
+		if (is_network_admin() || isset($_GET['activate-multi'])) {
356 356
 			return;
357 357
 		}
358 358
 
359
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
359
+		wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
360 360
 		exit;
361 361
     }
362 362
 
@@ -365,9 +365,9 @@  discard block
 block discarded – undo
365 365
      */
366 366
     public function maybe_do_admin_action() {
367 367
 
368
-        if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
369
-            $key = sanitize_key( $_REQUEST['getpaid-admin-action'] );
370
-            do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST );
368
+        if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
369
+            $key = sanitize_key($_REQUEST['getpaid-admin-action']);
370
+            do_action("getpaid_authenticated_admin_action_$key", $_REQUEST);
371 371
         }
372 372
 
373 373
     }
@@ -377,16 +377,16 @@  discard block
 block discarded – undo
377 377
 	 * 
378 378
 	 * @param array $args
379 379
      */
380
-    public function send_customer_invoice( $args ) {
381
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
380
+    public function send_customer_invoice($args) {
381
+		$sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']));
382 382
 
383
-		if ( $sent ) {
384
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
383
+		if ($sent) {
384
+			$this->show_success(__('Invoice was successfully sent to the customer', 'invoicing'));
385 385
 		} else {
386
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
386
+			$this->show_error(__('Could not sent the invoice to the customer', 'invoicing'));
387 387
 		}
388 388
 
389
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
389
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
390 390
 		exit;
391 391
 	}
392 392
 
@@ -395,16 +395,16 @@  discard block
 block discarded – undo
395 395
 	 * 
396 396
 	 * @param array $args
397 397
      */
398
-    public function send_customer_payment_reminder( $args ) {
399
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
398
+    public function send_customer_payment_reminder($args) {
399
+		$sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id']));
400 400
 
401
-		if ( $sent ) {
402
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
401
+		if ($sent) {
402
+			$this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing'));
403 403
 		} else {
404
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
404
+			$this->show_error(__('Could not sent payment reminder to the customer', 'invoicing'));
405 405
 		}
406 406
 
407
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
407
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
408 408
 		exit;
409 409
 	}
410 410
 
@@ -414,8 +414,8 @@  discard block
 block discarded – undo
414 414
      */
415 415
     public function admin_reset_tax_rates() {
416 416
 
417
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
418
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
417
+		update_option('wpinv_tax_rates', wpinv_get_data('tax-rates'));
418
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce')));
419 419
 		exit;
420 420
 
421 421
 	}
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
      * @return array
428 428
 	 */
429 429
 	public function get_notices() {
430
-		$notices = get_option( 'wpinv_admin_notices' );
431
-        return is_array( $notices ) ? $notices : array();
430
+		$notices = get_option('wpinv_admin_notices');
431
+        return is_array($notices) ? $notices : array();
432 432
 	}
433 433
 
434 434
 	/**
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 	 * @since       1.0.19
439 439
 	 */
440 440
 	public function clear_notices() {
441
-		delete_option( 'wpinv_admin_notices' );
441
+		delete_option('wpinv_admin_notices');
442 442
 	}
443 443
 
444 444
 	/**
@@ -447,16 +447,16 @@  discard block
 block discarded – undo
447 447
 	 * @access      public
448 448
 	 * @since       1.0.19
449 449
 	 */
450
-	public function save_notice( $type, $message ) {
450
+	public function save_notice($type, $message) {
451 451
 		$notices = $this->get_notices();
452 452
 
453
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
454
-			$notices[ $type ] = array();
453
+		if (empty($notices[$type]) || !is_array($notices[$type])) {
454
+			$notices[$type] = array();
455 455
 		}
456 456
 
457
-		$notices[ $type ][] = $message;
457
+		$notices[$type][] = $message;
458 458
 
459
-		update_option( 'wpinv_admin_notices', $notices );
459
+		update_option('wpinv_admin_notices', $notices);
460 460
 	}
461 461
 
462 462
 	/**
@@ -466,8 +466,8 @@  discard block
 block discarded – undo
466 466
 	 * @access      public
467 467
 	 * @since       1.0.19
468 468
 	 */
469
-	public function show_success( $msg ) {
470
-		$this->save_notice( 'success', $msg );
469
+	public function show_success($msg) {
470
+		$this->save_notice('success', $msg);
471 471
 	}
472 472
 
473 473
 	/**
@@ -477,8 +477,8 @@  discard block
 block discarded – undo
477 477
 	 * @param       string $msg The message to qeue.
478 478
 	 * @since       1.0.19
479 479
 	 */
480
-	public function show_error( $msg ) {
481
-		$this->save_notice( 'error', $msg );
480
+	public function show_error($msg) {
481
+		$this->save_notice('error', $msg);
482 482
 	}
483 483
 
484 484
 	/**
@@ -488,8 +488,8 @@  discard block
 block discarded – undo
488 488
 	 * @param       string $msg The message to qeue.
489 489
 	 * @since       1.0.19
490 490
 	 */
491
-	public function show_warning( $msg ) {
492
-		$this->save_notice( 'warning', $msg );
491
+	public function show_warning($msg) {
492
+		$this->save_notice('warning', $msg);
493 493
 	}
494 494
 
495 495
 	/**
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
 	 * @param       string $msg The message to qeue.
500 500
 	 * @since       1.0.19
501 501
 	 */
502
-	public function show_info( $msg ) {
503
-		$this->save_notice( 'info', $msg );
502
+	public function show_info($msg) {
503
+		$this->save_notice('info', $msg);
504 504
 	}
505 505
 
506 506
 	/**
@@ -514,15 +514,15 @@  discard block
 block discarded – undo
514 514
         $notices = $this->get_notices();
515 515
         $this->clear_notices();
516 516
 
517
-		foreach ( $notices as $type => $messages ) {
517
+		foreach ($notices as $type => $messages) {
518 518
 
519
-			if ( ! is_array( $messages ) ) {
519
+			if (!is_array($messages)) {
520 520
 				continue;
521 521
 			}
522 522
 
523
-            $type  = sanitize_key( $type );
524
-			foreach ( $messages as $message ) {
525
-                $message = wp_kses_post( $message );
523
+            $type = sanitize_key($type);
524
+			foreach ($messages as $message) {
525
+                $message = wp_kses_post($message);
526 526
 				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
527 527
             }
528 528
 
Please login to merge, or discard this patch.
includes/class-getpaid-subscription-notification-emails.php 2 patches
Indentation   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -13,282 +13,282 @@
 block discarded – undo
13 13
 class GetPaid_Subscription_Notification_Emails {
14 14
 
15 15
     /**
16
-	 * The array of subscription email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $subscription_actions;
16
+     * The array of subscription email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $subscription_actions;
21 21
 
22 22
     /**
23
-	 * Class constructor
23
+     * Class constructor
24 24
      *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->subscription_actions = apply_filters(
29
-			'getpaid_notification_email_subscription_triggers',
30
-			array(
31
-				'getpaid_subscription_trialling' => 'subscription_trial',
32
-				'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
-				'getpaid_subscription_expired'   => 'subscription_expired',
34
-				'getpaid_subscription_completed' => 'subscription_complete',
35
-				'getpaid_daily_maintenance'      => 'renewal_reminder',
36
-			)
37
-		);
38
-
39
-		$this->init_hooks();
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->subscription_actions = apply_filters(
29
+            'getpaid_notification_email_subscription_triggers',
30
+            array(
31
+                'getpaid_subscription_trialling' => 'subscription_trial',
32
+                'getpaid_subscription_cancelled' => 'subscription_cancelled',
33
+                'getpaid_subscription_expired'   => 'subscription_expired',
34
+                'getpaid_subscription_completed' => 'subscription_complete',
35
+                'getpaid_daily_maintenance'      => 'renewal_reminder',
36
+            )
37
+        );
38
+
39
+        $this->init_hooks();
40 40
 
41 41
     }
42 42
 
43 43
     /**
44
-	 * Registers email hooks.
45
-	 */
46
-	public function init_hooks() {
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 ) {
50
-
51
-			$email = new GetPaid_Notification_Email( $email_type );
52
-
53
-			if ( ! $email->is_active() ) {
54
-				continue;
55
-			}
56
-
57
-			if ( method_exists( $this, $email_type ) ) {
58
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
59
-				continue;
60
-			}
61
-
62
-			do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
63
-
64
-		}
65
-
66
-	}
67
-
68
-	/**
69
-	 * Filters subscription merge tags.
70
-	 *
71
-	 * @param array $merge_tags
72
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
-	 */
74
-	public function subscription_merge_tags( $merge_tags, $object ) {
75
-
76
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
-			$merge_tags = array_merge(
78
-				$merge_tags,
79
-				$this->get_subscription_merge_tags( $object )
80
-			);
81
-		}
82
-
83
-		return $merge_tags;
84
-
85
-	}
86
-
87
-	/**
88
-	 * Generates subscription merge tags.
89
-	 *
90
-	 * @param WPInv_Subscription $subscription
91
-	 * @return array
92
-	 */
93
-	public function get_subscription_merge_tags( $subscription ) {
94
-
95
-		// Abort if it does not exist.
96
-		if ( ! $subscription->get_id() ) {
97
-			return array();
98
-		}
99
-
100
-		$invoice    = $subscription->get_parent_invoice();
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(), '' ),
110
-			'{subscription_bill_times}'       => $subscription->get_bill_times(),
111
-			'{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
-		);
113
-
114
-	}
115
-
116
-	/**
117
-	 * Checks if we should send a notification for a subscription.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return bool
121
-	 */
122
-	public function should_send_notification( $invoice ) {
123
-		return 0 != $invoice->get_id();
124
-	}
125
-
126
-	/**
127
-	 * Returns notification recipients.
128
-	 *
129
-	 * @param WPInv_Invoice $invoice
130
-	 * @return array
131
-	 */
132
-	public function get_recipients( $invoice ) {
133
-		$recipients = array( $invoice->get_email() );
134
-
135
-		$cc = $invoice->get_email_cc();
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 ) ) );
140
-		}
141
-
142
-		return $recipients;
143
-	}
144
-
145
-	/**
146
-	 * Helper function to send an email.
147
-	 *
148
-	 * @param WPInv_Subscription $subscription
149
-	 * @param GetPaid_Notification_Email $email
150
-	 * @param string $type
151
-	 * @param array $extra_args Extra template args.
152
-	 */
153
-	public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
-
155
-		// Abort in case the parent invoice does not exist.
156
-		$invoice = $subscription->get_parent_invoice();
157
-		if ( ! $this->should_send_notification( $invoice ) ) {
158
-			return;
159
-		}
160
-
161
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
162
-
163
-		$recipients  = $this->get_recipients( $invoice );
164
-		$mailer      = new GetPaid_Notification_Email_Sender();
165
-		$merge_tags  = $email->get_merge_tags();
166
-		$content     = $email->get_content( $merge_tags, $extra_args );
167
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
168
-		$attachments = $email->get_attachments();
169
-
170
-		$result = $mailer->send(
171
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
172
-			$subject,
173
-			$content,
174
-			$attachments
175
-		);
176
-
177
-		// Maybe send a copy to the admin.
178
-		if ( $email->include_admin_bcc() ) {
179
-			$mailer->send(
180
-				wpinv_get_admin_email(),
181
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
182
-				$content,
183
-				$attachments
184
-			);
185
-		}
186
-
187
-		if ( ! $result ) {
188
-			$subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
189
-		}
190
-
191
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
192
-
193
-	}
44
+     * Registers email hooks.
45
+     */
46
+    public function init_hooks() {
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 ) {
50
+
51
+            $email = new GetPaid_Notification_Email( $email_type );
52
+
53
+            if ( ! $email->is_active() ) {
54
+                continue;
55
+            }
56
+
57
+            if ( method_exists( $this, $email_type ) ) {
58
+                add_action( $hook, array( $this, $email_type ), 100, 2 );
59
+                continue;
60
+            }
61
+
62
+            do_action( 'getpaid_subscription_notification_email_register_hook', $email_type, $hook );
63
+
64
+        }
65
+
66
+    }
194 67
 
195 68
     /**
196
-	 * Sends a new trial notification.
197
-	 *
198
-	 * @param WPInv_Subscription $subscription
199
-	 */
200
-	public function subscription_trial( $subscription ) {
69
+     * Filters subscription merge tags.
70
+     *
71
+     * @param array $merge_tags
72
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
73
+     */
74
+    public function subscription_merge_tags( $merge_tags, $object ) {
201 75
 
202
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
203
-		$this->send_email( $subscription, $email, __FUNCTION__ );
76
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
77
+            $merge_tags = array_merge(
78
+                $merge_tags,
79
+                $this->get_subscription_merge_tags( $object )
80
+            );
81
+        }
204 82
 
205
-	}
83
+        return $merge_tags;
206 84
 
207
-	/**
208
-	 * Sends a cancelled subscription notification.
209
-	 *
210
-	 * @param WPInv_Subscription $subscription
211
-	 */
212
-	public function subscription_cancelled( $subscription ) {
85
+    }
213 86
 
214
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
215
-		$this->send_email( $subscription, $email, __FUNCTION__ );
87
+    /**
88
+     * Generates subscription merge tags.
89
+     *
90
+     * @param WPInv_Subscription $subscription
91
+     * @return array
92
+     */
93
+    public function get_subscription_merge_tags( $subscription ) {
94
+
95
+        // Abort if it does not exist.
96
+        if ( ! $subscription->get_id() ) {
97
+            return array();
98
+        }
99
+
100
+        $invoice    = $subscription->get_parent_invoice();
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(), '' ),
110
+            '{subscription_bill_times}'       => $subscription->get_bill_times(),
111
+            '{subscription_url}'              => esc_url( $subscription->get_view_url() ),
112
+        );
216 113
 
217
-	}
114
+    }
218 115
 
219
-	/**
220
-	 * Sends a subscription expired notification.
221
-	 *
222
-	 * @param WPInv_Subscription $subscription
223
-	 */
224
-	public function subscription_expired( $subscription ) {
116
+    /**
117
+     * Checks if we should send a notification for a subscription.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return bool
121
+     */
122
+    public function should_send_notification( $invoice ) {
123
+        return 0 != $invoice->get_id();
124
+    }
225 125
 
226
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
227
-		$this->send_email( $subscription, $email, __FUNCTION__ );
126
+    /**
127
+     * Returns notification recipients.
128
+     *
129
+     * @param WPInv_Invoice $invoice
130
+     * @return array
131
+     */
132
+    public function get_recipients( $invoice ) {
133
+        $recipients = array( $invoice->get_email() );
228 134
 
229
-	}
135
+        $cc = $invoice->get_email_cc();
230 136
 
231
-	/**
232
-	 * Sends a completed subscription notification.
233
-	 *
234
-	 * @param WPInv_Subscription $subscription
235
-	 */
236
-	public function subscription_complete( $subscription ) {
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
+        }
237 141
 
238
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
239
-		$this->send_email( $subscription, $email, __FUNCTION__ );
142
+        return $recipients;
143
+    }
240 144
 
241
-	}
145
+    /**
146
+     * Helper function to send an email.
147
+     *
148
+     * @param WPInv_Subscription $subscription
149
+     * @param GetPaid_Notification_Email $email
150
+     * @param string $type
151
+     * @param array $extra_args Extra template args.
152
+     */
153
+    public function send_email( $subscription, $email, $type, $extra_args = array() ) {
154
+
155
+        // Abort in case the parent invoice does not exist.
156
+        $invoice = $subscription->get_parent_invoice();
157
+        if ( ! $this->should_send_notification( $invoice ) ) {
158
+            return;
159
+        }
160
+
161
+        do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
162
+
163
+        $recipients  = $this->get_recipients( $invoice );
164
+        $mailer      = new GetPaid_Notification_Email_Sender();
165
+        $merge_tags  = $email->get_merge_tags();
166
+        $content     = $email->get_content( $merge_tags, $extra_args );
167
+        $subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
168
+        $attachments = $email->get_attachments();
169
+
170
+        $result = $mailer->send(
171
+            apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
172
+            $subject,
173
+            $content,
174
+            $attachments
175
+        );
176
+
177
+        // Maybe send a copy to the admin.
178
+        if ( $email->include_admin_bcc() ) {
179
+            $mailer->send(
180
+                wpinv_get_admin_email(),
181
+                $subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
182
+                $content,
183
+                $attachments
184
+            );
185
+        }
186
+
187
+        if ( ! $result ) {
188
+            $subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
189
+        }
190
+
191
+        do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
242 192
 
243
-	/**
244
-	 * Sends a subscription renewal reminder notification.
245
-	 *
246
-	 */
247
-	public function renewal_reminder() {
193
+    }
248 194
 
249
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
195
+    /**
196
+     * Sends a new trial notification.
197
+     *
198
+     * @param WPInv_Subscription $subscription
199
+     */
200
+    public function subscription_trial( $subscription ) {
250 201
 
251
-		// Fetch reminder days.
252
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
202
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
203
+        $this->send_email( $subscription, $email, __FUNCTION__ );
253 204
 
254
-		// Abort if non is set.
255
-		if ( empty( $reminder_days ) ) {
256
-			return;
257
-		}
205
+    }
258 206
 
259
-		// Fetch matching subscriptions.
207
+    /**
208
+     * Sends a cancelled subscription notification.
209
+     *
210
+     * @param WPInv_Subscription $subscription
211
+     */
212
+    public function subscription_cancelled( $subscription ) {
213
+
214
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
215
+        $this->send_email( $subscription, $email, __FUNCTION__ );
216
+
217
+    }
218
+
219
+    /**
220
+     * Sends a subscription expired notification.
221
+     *
222
+     * @param WPInv_Subscription $subscription
223
+     */
224
+    public function subscription_expired( $subscription ) {
225
+
226
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
227
+        $this->send_email( $subscription, $email, __FUNCTION__ );
228
+
229
+    }
230
+
231
+    /**
232
+     * Sends a completed subscription notification.
233
+     *
234
+     * @param WPInv_Subscription $subscription
235
+     */
236
+    public function subscription_complete( $subscription ) {
237
+
238
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
239
+        $this->send_email( $subscription, $email, __FUNCTION__ );
240
+
241
+    }
242
+
243
+    /**
244
+     * Sends a subscription renewal reminder notification.
245
+     *
246
+     */
247
+    public function renewal_reminder() {
248
+
249
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
250
+
251
+        // Fetch reminder days.
252
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
253
+
254
+        // Abort if non is set.
255
+        if ( empty( $reminder_days ) ) {
256
+            return;
257
+        }
258
+
259
+        // Fetch matching subscriptions.
260 260
         $args  = array(
261 261
             'number'             => -1,
262
-			'count_total'        => false,
263
-			'status'             => 'trialling active',
262
+            'count_total'        => false,
263
+            'status'             => 'trialling active',
264 264
             'date_expires_query' => array(
265
-				'relation'  => 'OR'
265
+                'relation'  => 'OR'
266 266
             ),
267
-		);
267
+        );
268 268
 
269
-		foreach ( $reminder_days as $days ) {
270
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
269
+        foreach ( $reminder_days as $days ) {
270
+            $date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
271 271
 
272
-			$args['date_expires_query'][] = array(
273
-				'year'  => $date['year'],
274
-				'month' => $date['month'],
275
-				'day'   => $date['day'],
276
-			);
272
+            $args['date_expires_query'][] = array(
273
+                'year'  => $date['year'],
274
+                'month' => $date['month'],
275
+                'day'   => $date['day'],
276
+            );
277 277
 
278
-		}
278
+        }
279 279
 
280
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
280
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
281 281
 
282 282
         foreach ( $subscriptions as $subscription ) {
283 283
 
284
-			// Skip packages.
285
-			if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) {
286
-				$email->object = $subscription;
287
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
288
-			}
284
+            // Skip packages.
285
+            if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) {
286
+                $email->object = $subscription;
287
+                $this->send_email( $subscription, $email, __FUNCTION__ );
288
+            }
289 289
 
290
-		}
290
+        }
291 291
 
292
-	}
292
+    }
293 293
 
294 294
 }
Please login to merge, or discard this patch.
Spacing   +63 added lines, -63 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.
@@ -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,45 +150,45 @@  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 155
 		// Abort in case the parent invoice does not exist.
156 156
 		$invoice = $subscription->get_parent_invoice();
157
-		if ( ! $this->should_send_notification( $invoice ) ) {
157
+		if (!$this->should_send_notification($invoice)) {
158 158
 			return;
159 159
 		}
160 160
 
161
-		do_action( 'getpaid_before_send_subscription_notification', $type, $subscription, $email );
161
+		do_action('getpaid_before_send_subscription_notification', $type, $subscription, $email);
162 162
 
163
-		$recipients  = $this->get_recipients( $invoice );
163
+		$recipients  = $this->get_recipients($invoice);
164 164
 		$mailer      = new GetPaid_Notification_Email_Sender();
165 165
 		$merge_tags  = $email->get_merge_tags();
166
-		$content     = $email->get_content( $merge_tags, $extra_args );
167
-		$subject     = $email->add_merge_tags( $email->get_subject(), $merge_tags );
166
+		$content     = $email->get_content($merge_tags, $extra_args);
167
+		$subject     = $email->add_merge_tags($email->get_subject(), $merge_tags);
168 168
 		$attachments = $email->get_attachments();
169 169
 
170 170
 		$result = $mailer->send(
171
-			apply_filters( 'getpaid_subscription_email_recipients', wpinv_parse_list( $recipients ), $email ),
171
+			apply_filters('getpaid_subscription_email_recipients', wpinv_parse_list($recipients), $email),
172 172
 			$subject,
173 173
 			$content,
174 174
 			$attachments
175 175
 		);
176 176
 
177 177
 		// Maybe send a copy to the admin.
178
-		if ( $email->include_admin_bcc() ) {
178
+		if ($email->include_admin_bcc()) {
179 179
 			$mailer->send(
180 180
 				wpinv_get_admin_email(),
181
-				$subject . __( ' - ADMIN BCC COPY', 'invoicing' ),
181
+				$subject . __(' - ADMIN BCC COPY', 'invoicing'),
182 182
 				$content,
183 183
 				$attachments
184 184
 			);
185 185
 		}
186 186
 
187
-		if ( ! $result ) {
188
-			$subscription->get_parent_invoice()->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
187
+		if (!$result) {
188
+			$subscription->get_parent_invoice()->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);
189 189
 		}
190 190
 
191
-		do_action( 'getpaid_after_send_subscription_notification', $type, $subscription, $email );
191
+		do_action('getpaid_after_send_subscription_notification', $type, $subscription, $email);
192 192
 
193 193
 	}
194 194
 
@@ -197,10 +197,10 @@  discard block
 block discarded – undo
197 197
 	 *
198 198
 	 * @param WPInv_Subscription $subscription
199 199
 	 */
200
-	public function subscription_trial( $subscription ) {
200
+	public function subscription_trial($subscription) {
201 201
 
202
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
203
-		$this->send_email( $subscription, $email, __FUNCTION__ );
202
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
203
+		$this->send_email($subscription, $email, __FUNCTION__);
204 204
 
205 205
 	}
206 206
 
@@ -209,10 +209,10 @@  discard block
 block discarded – undo
209 209
 	 *
210 210
 	 * @param WPInv_Subscription $subscription
211 211
 	 */
212
-	public function subscription_cancelled( $subscription ) {
212
+	public function subscription_cancelled($subscription) {
213 213
 
214
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
215
-		$this->send_email( $subscription, $email, __FUNCTION__ );
214
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
215
+		$this->send_email($subscription, $email, __FUNCTION__);
216 216
 
217 217
 	}
218 218
 
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
 	 *
222 222
 	 * @param WPInv_Subscription $subscription
223 223
 	 */
224
-	public function subscription_expired( $subscription ) {
224
+	public function subscription_expired($subscription) {
225 225
 
226
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
227
-		$this->send_email( $subscription, $email, __FUNCTION__ );
226
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
227
+		$this->send_email($subscription, $email, __FUNCTION__);
228 228
 
229 229
 	}
230 230
 
@@ -233,10 +233,10 @@  discard block
 block discarded – undo
233 233
 	 *
234 234
 	 * @param WPInv_Subscription $subscription
235 235
 	 */
236
-	public function subscription_complete( $subscription ) {
236
+	public function subscription_complete($subscription) {
237 237
 
238
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $subscription );
239
-		$this->send_email( $subscription, $email, __FUNCTION__ );
238
+		$email = new GetPaid_Notification_Email(__FUNCTION__, $subscription);
239
+		$this->send_email($subscription, $email, __FUNCTION__);
240 240
 
241 241
 	}
242 242
 
@@ -246,18 +246,18 @@  discard block
 block discarded – undo
246 246
 	 */
247 247
 	public function renewal_reminder() {
248 248
 
249
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
249
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
250 250
 
251 251
 		// Fetch reminder days.
252
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
252
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
253 253
 
254 254
 		// Abort if non is set.
255
-		if ( empty( $reminder_days ) ) {
255
+		if (empty($reminder_days)) {
256 256
 			return;
257 257
 		}
258 258
 
259 259
 		// Fetch matching subscriptions.
260
-        $args  = array(
260
+        $args = array(
261 261
             'number'             => -1,
262 262
 			'count_total'        => false,
263 263
 			'status'             => 'trialling active',
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
             ),
267 267
 		);
268 268
 
269
-		foreach ( $reminder_days as $days ) {
270
-			$date = date_parse( date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) ) );
269
+		foreach ($reminder_days as $days) {
270
+			$date = date_parse(date('Y-m-d', strtotime("+$days days", current_time('timestamp'))));
271 271
 
272 272
 			$args['date_expires_query'][] = array(
273 273
 				'year'  => $date['year'],
@@ -277,14 +277,14 @@  discard block
 block discarded – undo
277 277
 
278 278
 		}
279 279
 
280
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
280
+		$subscriptions = new GetPaid_Subscriptions_Query($args);
281 281
 
282
-        foreach ( $subscriptions as $subscription ) {
282
+        foreach ($subscriptions as $subscription) {
283 283
 
284 284
 			// Skip packages.
285
-			if ( get_post_meta( $subscription->get_product_id(), '_wpinv_type', true ) != 'package' ) {
285
+			if (get_post_meta($subscription->get_product_id(), '_wpinv_type', true) != 'package') {
286 286
 				$email->object = $subscription;
287
-            	$this->send_email( $subscription, $email, __FUNCTION__ );
287
+            	$this->send_email($subscription, $email, __FUNCTION__);
288 288
 			}
289 289
 
290 290
 		}
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +390 added lines, -390 removed lines patch added patch discarded remove patch
@@ -12,444 +12,444 @@
 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
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
151
-	}
152
-
153
-	/**
154
-	 * Helper function to send an email.
155
-	 *
156
-	 * @param WPInv_Invoice $invoice
157
-	 * @param GetPaid_Notification_Email $email
158
-	 * @param string $type
159
-	 * @param string|array $recipients
160
-	 * @param array $extra_args Extra template args.
161
-	 */
162
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
163
-
164
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
165
-
166
-		$mailer     = new GetPaid_Notification_Email_Sender();
167
-		$merge_tags = $email->get_merge_tags();
168
-
169
-		$result = $mailer->send(
170
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
171
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
172
-			$email->get_content( $merge_tags, $extra_args ),
173
-			$email->get_attachments()
174
-		);
175
-
176
-		// Maybe send a copy to the admin.
177
-		if ( $email->include_admin_bcc() ) {
178
-			$mailer->send(
179
-				wpinv_get_admin_email(),
180
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
181
-				$email->get_content( $merge_tags ),
182
-				$email->get_attachments()
183
-			);
184
-		}
185
-
186
-		if ( ! $result ) {
187
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
188
-		}
189
-
190
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
191
-
192
-		return $result;
193
-	}
194
-
195
-	/**
196
-	 * Also send emails to any cc users.
197
-	 *
198
-	 * @param array $recipients
199
-	 * @param GetPaid_Notification_Email $email
200
-	 */
201
-	public function filter_email_recipients( $recipients, $email ) {
202
-
203
-		if ( ! $email->is_admin_email() ) {
204
-			$cc = $email->object->get_email_cc();
205
-
206
-			if ( ! empty( $cc ) ) {
207
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
208
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
209
-			}
210
-
211
-		}
212
-
213
-		return $recipients;
214
-
215
-	}
216
-
217
-	/**
218
-	 * Sends a new invoice notification.
219
-	 *
220
-	 * @param WPInv_Invoice $invoice
221
-	 */
222
-	public function new_invoice( $invoice ) {
223
-
224
-		// Only send this email for invoices created via the admin page.
225
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
226
-			return;
227
-		}
228
-
229
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
230
-		$recipient = wpinv_get_admin_email();
231
-
232
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
233
-
234
-	}
235
-
236
-	/**
237
-	 * Sends a cancelled invoice notification.
238
-	 *
239
-	 * @param WPInv_Invoice $invoice
240
-	 */
241
-	public function cancelled_invoice( $invoice ) {
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
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
151
+    }
152
+
153
+    /**
154
+     * Helper function to send an email.
155
+     *
156
+     * @param WPInv_Invoice $invoice
157
+     * @param GetPaid_Notification_Email $email
158
+     * @param string $type
159
+     * @param string|array $recipients
160
+     * @param array $extra_args Extra template args.
161
+     */
162
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
163
+
164
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
165
+
166
+        $mailer     = new GetPaid_Notification_Email_Sender();
167
+        $merge_tags = $email->get_merge_tags();
168
+
169
+        $result = $mailer->send(
170
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
171
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
172
+            $email->get_content( $merge_tags, $extra_args ),
173
+            $email->get_attachments()
174
+        );
175
+
176
+        // Maybe send a copy to the admin.
177
+        if ( $email->include_admin_bcc() ) {
178
+            $mailer->send(
179
+                wpinv_get_admin_email(),
180
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
181
+                $email->get_content( $merge_tags ),
182
+                $email->get_attachments()
183
+            );
184
+        }
185
+
186
+        if ( ! $result ) {
187
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
188
+        }
189
+
190
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
191
+
192
+        return $result;
193
+    }
194
+
195
+    /**
196
+     * Also send emails to any cc users.
197
+     *
198
+     * @param array $recipients
199
+     * @param GetPaid_Notification_Email $email
200
+     */
201
+    public function filter_email_recipients( $recipients, $email ) {
202
+
203
+        if ( ! $email->is_admin_email() ) {
204
+            $cc = $email->object->get_email_cc();
205
+
206
+            if ( ! empty( $cc ) ) {
207
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
208
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
209
+            }
210
+
211
+        }
212
+
213
+        return $recipients;
214
+
215
+    }
216
+
217
+    /**
218
+     * Sends a new invoice notification.
219
+     *
220
+     * @param WPInv_Invoice $invoice
221
+     */
222
+    public function new_invoice( $invoice ) {
223
+
224
+        // Only send this email for invoices created via the admin page.
225
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
226
+            return;
227
+        }
228
+
229
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
230
+        $recipient = wpinv_get_admin_email();
231
+
232
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
233
+
234
+    }
235
+
236
+    /**
237
+     * Sends a cancelled invoice notification.
238
+     *
239
+     * @param WPInv_Invoice $invoice
240
+     */
241
+    public function cancelled_invoice( $invoice ) {
242 242
 
243
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
244
-		$recipient = wpinv_get_admin_email();
243
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
244
+        $recipient = wpinv_get_admin_email();
245 245
 
246
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
246
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
247 247
 
248
-	}
248
+    }
249 249
 
250
-	/**
251
-	 * Sends a failed invoice notification.
252
-	 *
253
-	 * @param WPInv_Invoice $invoice
254
-	 */
255
-	public function failed_invoice( $invoice ) {
250
+    /**
251
+     * Sends a failed invoice notification.
252
+     *
253
+     * @param WPInv_Invoice $invoice
254
+     */
255
+    public function failed_invoice( $invoice ) {
256 256
 
257
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
258
-		$recipient = wpinv_get_admin_email();
257
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
258
+        $recipient = wpinv_get_admin_email();
259 259
 
260
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
260
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
261 261
 
262
-	}
262
+    }
263 263
 
264
-	/**
265
-	 * Sends a notification whenever an invoice is put on hold.
266
-	 *
267
-	 * @param WPInv_Invoice $invoice
268
-	 */
269
-	public function onhold_invoice( $invoice ) {
264
+    /**
265
+     * Sends a notification whenever an invoice is put on hold.
266
+     *
267
+     * @param WPInv_Invoice $invoice
268
+     */
269
+    public function onhold_invoice( $invoice ) {
270 270
 
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
-		$recipient = $invoice->get_email();
271
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
+        $recipient = $invoice->get_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
 
278
-	/**
279
-	 * Sends a notification whenever an invoice is marked as processing payment.
280
-	 *
281
-	 * @param WPInv_Invoice $invoice
282
-	 */
283
-	public function processing_invoice( $invoice ) {
278
+    /**
279
+     * Sends a notification whenever an invoice is marked as processing payment.
280
+     *
281
+     * @param WPInv_Invoice $invoice
282
+     */
283
+    public function processing_invoice( $invoice ) {
284 284
 
285
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
-		$recipient = $invoice->get_email();
285
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
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
 
292
-	/**
293
-	 * Sends a notification whenever an invoice is paid.
294
-	 *
295
-	 * @param WPInv_Invoice $invoice
296
-	 */
297
-	public function completed_invoice( $invoice ) {
292
+    /**
293
+     * Sends a notification whenever an invoice is paid.
294
+     *
295
+     * @param WPInv_Invoice $invoice
296
+     */
297
+    public function completed_invoice( $invoice ) {
298 298
 
299
-		// (Maybe) abort if it is a renewal invoice.
300
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
301
-			return;
302
-		}
299
+        // (Maybe) abort if it is a renewal invoice.
300
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
301
+            return;
302
+        }
303 303
 
304
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
305
-		$recipient = $invoice->get_email();
304
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
305
+        $recipient = $invoice->get_email();
306 306
 
307
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
307
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
308 308
 
309
-	}
309
+    }
310 310
 
311
-	/**
312
-	 * Sends a notification whenever an invoice is refunded.
313
-	 *
314
-	 * @param WPInv_Invoice $invoice
315
-	 */
316
-	public function refunded_invoice( $invoice ) {
311
+    /**
312
+     * Sends a notification whenever an invoice is refunded.
313
+     *
314
+     * @param WPInv_Invoice $invoice
315
+     */
316
+    public function refunded_invoice( $invoice ) {
317 317
 
318
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
319
-		$recipient = $invoice->get_email();
318
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
319
+        $recipient = $invoice->get_email();
320 320
 
321
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
321
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
322 322
 
323
-	}
323
+    }
324 324
 
325
-	/**
326
-	 * Notifies a user about new invoices
327
-	 *
328
-	 * @param WPInv_Invoice $invoice
329
-	 */
330
-	public function user_invoice( $invoice ) {
325
+    /**
326
+     * Notifies a user about new invoices
327
+     *
328
+     * @param WPInv_Invoice $invoice
329
+     */
330
+    public function user_invoice( $invoice ) {
331 331
 
332
-		// Only send this email for invoices created via the admin page.
333
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
334
-			return;
335
-		}
332
+        // Only send this email for invoices created via the admin page.
333
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
334
+            return;
335
+        }
336 336
 
337
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
338
-		$recipient = $invoice->get_email();
337
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
338
+        $recipient = $invoice->get_email();
339 339
 
340
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
340
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
341 341
 
342
-	}
342
+    }
343 343
 
344
-	/**
345
-	 * Checks if an invoice is a payment form invoice.
346
-	 *
347
-	 * @param int $invoice
348
-	 * @return bool
349
-	 */
350
-	public function is_payment_form_invoice( $invoice ) {
351
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
352
-	}
344
+    /**
345
+     * Checks if an invoice is a payment form invoice.
346
+     *
347
+     * @param int $invoice
348
+     * @return bool
349
+     */
350
+    public function is_payment_form_invoice( $invoice ) {
351
+        return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
352
+    }
353 353
 
354
-	/**
355
-	 * Notifies admin about new invoice notes
356
-	 *
357
-	 * @param WPInv_Invoice $invoice
358
-	 * @param string $note
359
-	 */
360
-	public function user_note( $invoice, $note ) {
354
+    /**
355
+     * Notifies admin about new invoice notes
356
+     *
357
+     * @param WPInv_Invoice $invoice
358
+     * @param string $note
359
+     */
360
+    public function user_note( $invoice, $note ) {
361 361
 
362
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
363
-		$recipient = $invoice->get_email();
364
-
365
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
366
-
367
-	}
362
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
363
+        $recipient = $invoice->get_email();
364
+
365
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
366
+
367
+    }
368 368
 
369
-	/**
370
-	 * (Force) Sends overdue notices.
371
-	 *
372
-	 * @param WPInv_Invoice $invoice
373
-	 */
374
-	public function force_send_overdue_notice( $invoice ) {
375
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
376
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
377
-	}
378
-
379
-	/**
380
-	 * Sends overdue notices.
381
-	 *
382
-	 * @TODO: Create an invoices query class.
383
-	 */
384
-	public function overdue() {
385
-		global $wpdb;
386
-
387
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
388
-
389
-		// Fetch reminder days.
390
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
391
-
392
-		// Abort if non is set.
393
-		if ( empty( $reminder_days ) ) {
394
-			return;
395
-		}
396
-
397
-		// Retrieve date query.
398
-		$date_query = $this->get_date_query( $reminder_days );
399
-
400
-		// Invoices table.
401
-		$table = $wpdb->prefix . 'getpaid_invoices';
402
-
403
-		// Fetch invoices.
404
-		$invoices  = $wpdb->get_col(
405
-			"SELECT posts.ID FROM $wpdb->posts as posts
369
+    /**
370
+     * (Force) Sends overdue notices.
371
+     *
372
+     * @param WPInv_Invoice $invoice
373
+     */
374
+    public function force_send_overdue_notice( $invoice ) {
375
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
376
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
377
+    }
378
+
379
+    /**
380
+     * Sends overdue notices.
381
+     *
382
+     * @TODO: Create an invoices query class.
383
+     */
384
+    public function overdue() {
385
+        global $wpdb;
386
+
387
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
388
+
389
+        // Fetch reminder days.
390
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
391
+
392
+        // Abort if non is set.
393
+        if ( empty( $reminder_days ) ) {
394
+            return;
395
+        }
396
+
397
+        // Retrieve date query.
398
+        $date_query = $this->get_date_query( $reminder_days );
399
+
400
+        // Invoices table.
401
+        $table = $wpdb->prefix . 'getpaid_invoices';
402
+
403
+        // Fetch invoices.
404
+        $invoices  = $wpdb->get_col(
405
+            "SELECT posts.ID FROM $wpdb->posts as posts
406 406
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
407 407
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
408 408
 
409
-		foreach ( $invoices as $invoice ) {
409
+        foreach ( $invoices as $invoice ) {
410 410
 
411
-			// Only send this email for invoices created via the admin page.
412
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
413
-				$invoice       = new WPInv_Invoice( $invoice );
414
-				$email->object = $invoice;
411
+            // Only send this email for invoices created via the admin page.
412
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
413
+                $invoice       = new WPInv_Invoice( $invoice );
414
+                $email->object = $invoice;
415 415
 
416
-				if ( $invoice->needs_payment() ) {
417
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
418
-				}
416
+                if ( $invoice->needs_payment() ) {
417
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
418
+                }
419 419
 
420
-			}
420
+            }
421 421
 
422
-		}
422
+        }
423 423
 
424
-	}
424
+    }
425 425
 
426
-	/**
427
-	 * Calculates the date query for an invoices query
428
-	 *
429
-	 * @param array $reminder_days
430
-	 * @return string
431
-	 */
432
-	public function get_date_query( $reminder_days ) {
426
+    /**
427
+     * Calculates the date query for an invoices query
428
+     *
429
+     * @param array $reminder_days
430
+     * @return string
431
+     */
432
+    public function get_date_query( $reminder_days ) {
433 433
 
434
-		$date_query = array(
435
-			'relation'  => 'OR'
436
-		);
434
+        $date_query = array(
435
+            'relation'  => 'OR'
436
+        );
437 437
 
438
-		foreach ( $reminder_days as $days ) {
439
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
438
+        foreach ( $reminder_days as $days ) {
439
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
440 440
 
441
-			$date_query[] = array(
442
-				'year'  => $date['year'],
443
-				'month' => $date['month'],
444
-				'day'   => $date['day'],
445
-			);
441
+            $date_query[] = array(
442
+                'year'  => $date['year'],
443
+                'month' => $date['month'],
444
+                'day'   => $date['day'],
445
+            );
446 446
 
447
-		}
447
+        }
448 448
 
449
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
449
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
450 450
 
451
-		return $date_query->get_sql();
451
+        return $date_query->get_sql();
452 452
 
453
-	}
453
+    }
454 454
 
455 455
 }
Please login to merge, or discard this patch.
Spacing   +105 added lines, -105 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,35 +119,35 @@  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
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
150
+		return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice);
151 151
 	}
152 152
 
153 153
 	/**
@@ -159,35 +159,35 @@  discard block
 block discarded – undo
159 159
 	 * @param string|array $recipients
160 160
 	 * @param array $extra_args Extra template args.
161 161
 	 */
162
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
162
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
163 163
 
164
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
164
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
165 165
 
166 166
 		$mailer     = new GetPaid_Notification_Email_Sender();
167 167
 		$merge_tags = $email->get_merge_tags();
168 168
 
169 169
 		$result = $mailer->send(
170
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
171
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
172
-			$email->get_content( $merge_tags, $extra_args ),
170
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
171
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
172
+			$email->get_content($merge_tags, $extra_args),
173 173
 			$email->get_attachments()
174 174
 		);
175 175
 
176 176
 		// Maybe send a copy to the admin.
177
-		if ( $email->include_admin_bcc() ) {
177
+		if ($email->include_admin_bcc()) {
178 178
 			$mailer->send(
179 179
 				wpinv_get_admin_email(),
180
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
181
-				$email->get_content( $merge_tags ),
180
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
181
+				$email->get_content($merge_tags),
182 182
 				$email->get_attachments()
183 183
 			);
184 184
 		}
185 185
 
186
-		if ( ! $result ) {
187
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
186
+		if (!$result) {
187
+			$invoice->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);
188 188
 		}
189 189
 
190
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
190
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
191 191
 
192 192
 		return $result;
193 193
 	}
@@ -198,14 +198,14 @@  discard block
 block discarded – undo
198 198
 	 * @param array $recipients
199 199
 	 * @param GetPaid_Notification_Email $email
200 200
 	 */
201
-	public function filter_email_recipients( $recipients, $email ) {
201
+	public function filter_email_recipients($recipients, $email) {
202 202
 
203
-		if ( ! $email->is_admin_email() ) {
203
+		if (!$email->is_admin_email()) {
204 204
 			$cc = $email->object->get_email_cc();
205 205
 
206
-			if ( ! empty( $cc ) ) {
207
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
208
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
206
+			if (!empty($cc)) {
207
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
208
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
209 209
 			}
210 210
 
211 211
 		}
@@ -219,17 +219,17 @@  discard block
 block discarded – undo
219 219
 	 *
220 220
 	 * @param WPInv_Invoice $invoice
221 221
 	 */
222
-	public function new_invoice( $invoice ) {
222
+	public function new_invoice($invoice) {
223 223
 
224 224
 		// Only send this email for invoices created via the admin page.
225
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
225
+		if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) {
226 226
 			return;
227 227
 		}
228 228
 
229
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
229
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
230 230
 		$recipient = wpinv_get_admin_email();
231 231
 
232
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
232
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
233 233
 
234 234
 	}
235 235
 
@@ -238,12 +238,12 @@  discard block
 block discarded – undo
238 238
 	 *
239 239
 	 * @param WPInv_Invoice $invoice
240 240
 	 */
241
-	public function cancelled_invoice( $invoice ) {
241
+	public function cancelled_invoice($invoice) {
242 242
 
243
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
243
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
244 244
 		$recipient = wpinv_get_admin_email();
245 245
 
246
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
246
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
247 247
 
248 248
 	}
249 249
 
@@ -252,12 +252,12 @@  discard block
 block discarded – undo
252 252
 	 *
253 253
 	 * @param WPInv_Invoice $invoice
254 254
 	 */
255
-	public function failed_invoice( $invoice ) {
255
+	public function failed_invoice($invoice) {
256 256
 
257
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
257
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
258 258
 		$recipient = wpinv_get_admin_email();
259 259
 
260
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
260
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
261 261
 
262 262
 	}
263 263
 
@@ -266,12 +266,12 @@  discard block
 block discarded – undo
266 266
 	 *
267 267
 	 * @param WPInv_Invoice $invoice
268 268
 	 */
269
-	public function onhold_invoice( $invoice ) {
269
+	public function onhold_invoice($invoice) {
270 270
 
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
272 272
 		$recipient = $invoice->get_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 processing_invoice( $invoice ) {
283
+	public function processing_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
 
@@ -294,17 +294,17 @@  discard block
 block discarded – undo
294 294
 	 *
295 295
 	 * @param WPInv_Invoice $invoice
296 296
 	 */
297
-	public function completed_invoice( $invoice ) {
297
+	public function completed_invoice($invoice) {
298 298
 
299 299
 		// (Maybe) abort if it is a renewal invoice.
300
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
300
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
301 301
 			return;
302 302
 		}
303 303
 
304
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
304
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
305 305
 		$recipient = $invoice->get_email();
306 306
 
307
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
307
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
308 308
 
309 309
 	}
310 310
 
@@ -313,12 +313,12 @@  discard block
 block discarded – undo
313 313
 	 *
314 314
 	 * @param WPInv_Invoice $invoice
315 315
 	 */
316
-	public function refunded_invoice( $invoice ) {
316
+	public function refunded_invoice($invoice) {
317 317
 
318
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
318
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
319 319
 		$recipient = $invoice->get_email();
320 320
 
321
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
321
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
322 322
 
323 323
 	}
324 324
 
@@ -327,17 +327,17 @@  discard block
 block discarded – undo
327 327
 	 *
328 328
 	 * @param WPInv_Invoice $invoice
329 329
 	 */
330
-	public function user_invoice( $invoice ) {
330
+	public function user_invoice($invoice) {
331 331
 
332 332
 		// Only send this email for invoices created via the admin page.
333
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
333
+		if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) {
334 334
 			return;
335 335
 		}
336 336
 
337
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
337
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
338 338
 		$recipient = $invoice->get_email();
339 339
 
340
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
340
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
341 341
 
342 342
 	}
343 343
 
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
 	 * @param int $invoice
348 348
 	 * @return bool
349 349
 	 */
350
-	public function is_payment_form_invoice( $invoice ) {
351
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
350
+	public function is_payment_form_invoice($invoice) {
351
+		return empty($_GET['getpaid-admin-action']) && 'payment_form' == get_post_meta($invoice, 'wpinv_created_via', true);
352 352
 	}
353 353
 
354 354
 	/**
@@ -357,12 +357,12 @@  discard block
 block discarded – undo
357 357
 	 * @param WPInv_Invoice $invoice
358 358
 	 * @param string $note
359 359
 	 */
360
-	public function user_note( $invoice, $note ) {
360
+	public function user_note($invoice, $note) {
361 361
 
362
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
362
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
363 363
 		$recipient = $invoice->get_email();
364 364
 
365
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
365
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
366 366
 
367 367
 	}
368 368
 
@@ -371,9 +371,9 @@  discard block
 block discarded – undo
371 371
 	 *
372 372
 	 * @param WPInv_Invoice $invoice
373 373
 	 */
374
-	public function force_send_overdue_notice( $invoice ) {
375
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
376
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
374
+	public function force_send_overdue_notice($invoice) {
375
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
376
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
377 377
 	}
378 378
 
379 379
 	/**
@@ -384,37 +384,37 @@  discard block
 block discarded – undo
384 384
 	public function overdue() {
385 385
 		global $wpdb;
386 386
 
387
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
387
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
388 388
 
389 389
 		// Fetch reminder days.
390
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
390
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
391 391
 
392 392
 		// Abort if non is set.
393
-		if ( empty( $reminder_days ) ) {
393
+		if (empty($reminder_days)) {
394 394
 			return;
395 395
 		}
396 396
 
397 397
 		// Retrieve date query.
398
-		$date_query = $this->get_date_query( $reminder_days );
398
+		$date_query = $this->get_date_query($reminder_days);
399 399
 
400 400
 		// Invoices table.
401 401
 		$table = $wpdb->prefix . 'getpaid_invoices';
402 402
 
403 403
 		// Fetch invoices.
404
-		$invoices  = $wpdb->get_col(
404
+		$invoices = $wpdb->get_col(
405 405
 			"SELECT posts.ID FROM $wpdb->posts as posts
406 406
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
407 407
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
408 408
 
409
-		foreach ( $invoices as $invoice ) {
409
+		foreach ($invoices as $invoice) {
410 410
 
411 411
 			// Only send this email for invoices created via the admin page.
412
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
413
-				$invoice       = new WPInv_Invoice( $invoice );
412
+			if (!$this->is_payment_form_invoice($invoice)) {
413
+				$invoice       = new WPInv_Invoice($invoice);
414 414
 				$email->object = $invoice;
415 415
 
416
-				if ( $invoice->needs_payment() ) {
417
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
416
+				if ($invoice->needs_payment()) {
417
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
418 418
 				}
419 419
 
420 420
 			}
@@ -429,14 +429,14 @@  discard block
 block discarded – undo
429 429
 	 * @param array $reminder_days
430 430
 	 * @return string
431 431
 	 */
432
-	public function get_date_query( $reminder_days ) {
432
+	public function get_date_query($reminder_days) {
433 433
 
434 434
 		$date_query = array(
435 435
 			'relation'  => 'OR'
436 436
 		);
437 437
 
438
-		foreach ( $reminder_days as $days ) {
439
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
438
+		foreach ($reminder_days as $days) {
439
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
440 440
 
441 441
 			$date_query[] = array(
442 442
 				'year'  => $date['year'],
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 
447 447
 		}
448 448
 
449
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
449
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
450 450
 
451 451
 		return $date_query->get_sql();
452 452
 
Please login to merge, or discard this patch.
templates/emails/invoice-item.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -10,67 +10,67 @@  discard block
 block discarded – undo
10 10
  * @var array $columns
11 11
  */
12 12
 
13
-defined( 'ABSPATH' ) || exit;
13
+defined('ABSPATH') || exit;
14 14
 
15 15
 ?>
16 16
 
17
-<?php do_action( 'getpaid_before_email_line_item', $invoice, $item ); ?>
17
+<?php do_action('getpaid_before_email_line_item', $invoice, $item); ?>
18 18
 
19
-<tr class="wpinv_cart_item item-type-<?php echo sanitize_html_class( $item->get_type() ); ?>">
19
+<tr class="wpinv_cart_item item-type-<?php echo sanitize_html_class($item->get_type()); ?>">
20 20
 
21
-    <?php foreach ( array_keys( $columns ) as $column ): ?>
21
+    <?php foreach (array_keys($columns) as $column): ?>
22 22
 
23
-        <td class="<?php echo 'name' == $column ? 'text-left' : 'text-right' ?> wpinv_cart_item_<?php echo sanitize_html_class( $column ); ?>">
23
+        <td class="<?php echo 'name' == $column ? 'text-left' : 'text-right' ?> wpinv_cart_item_<?php echo sanitize_html_class($column); ?>">
24 24
             
25 25
             <?php
26 26
 
27 27
                 // Fires before printing a line item column.
28
-                do_action( "getpaid_email_line_item_before_$column", $item, $invoice );
28
+                do_action("getpaid_email_line_item_before_$column", $item, $invoice);
29 29
 
30 30
                 // Item name.
31
-                if ( 'name' == $column ) {
31
+                if ('name' == $column) {
32 32
 
33 33
                     // Display the name.
34
-                    echo '<div class="wpinv_email_cart_item_title">' . sanitize_text_field( $item->get_name() ) . '</div>';
34
+                    echo '<div class="wpinv_email_cart_item_title">' . sanitize_text_field($item->get_name()) . '</div>';
35 35
 
36 36
                     // And an optional description.
37 37
                     $description = $item->get_description();
38 38
 
39
-                    if ( ! empty( $description ) ) {
40
-                        $description = wp_kses_post( $description );
39
+                    if (!empty($description)) {
40
+                        $description = wp_kses_post($description);
41 41
                         echo "<p class='small'>$description</p>";
42 42
                     }
43 43
 
44 44
                     // Price help text
45
-                    $description = getpaid_item_recurring_price_help_text( $item, $invoice->get_currency() );
46
-                    if ( $description ) {
45
+                    $description = getpaid_item_recurring_price_help_text($item, $invoice->get_currency());
46
+                    if ($description) {
47 47
                         echo "<p class='small'>$description</p>";
48 48
                     }
49 49
 
50 50
                 }
51 51
 
52 52
                 // Item price.
53
-                if ( 'price' == $column ) {
53
+                if ('price' == $column) {
54 54
 
55 55
                     // Display the item price (or recurring price if this is a renewal invoice)
56 56
                     $price = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price();
57
-                    echo wpinv_price( $price, $invoice->get_currency() );
57
+                    echo wpinv_price($price, $invoice->get_currency());
58 58
 
59 59
                 }
60 60
 
61 61
                 // Item quantity.
62
-                if ( 'quantity' == $column ) {
62
+                if ('quantity' == $column) {
63 63
                     echo (int) $item->get_quantity();
64 64
                 }
65 65
 
66 66
                 // Item sub total.
67
-                if ( 'subtotal' == $column ) {
67
+                if ('subtotal' == $column) {
68 68
                     $subtotal = $invoice->is_renewal() ? $item->get_recurring_sub_total() : $item->get_sub_total();
69
-                    echo wpinv_price( $subtotal, $invoice->get_currency() );
69
+                    echo wpinv_price($subtotal, $invoice->get_currency());
70 70
                 }
71 71
 
72 72
                 // Fires when printing a line item column.
73
-                do_action( "getpaid_email_line_item_$column", $item, $invoice );
73
+                do_action("getpaid_email_line_item_$column", $item, $invoice);
74 74
 
75 75
             ?>
76 76
 
@@ -80,4 +80,4 @@  discard block
 block discarded – undo
80 80
 
81 81
 </tr>
82 82
 
83
-<?php do_action( 'getpaid_after_email_line_item', $invoice, $item ); ?>
83
+<?php do_action('getpaid_after_email_line_item', $invoice, $item); ?>
Please login to merge, or discard this patch.
templates/emails/invoice-items.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -8,18 +8,18 @@  discard block
 block discarded – undo
8 8
  * @var WPInv_Invoice $invoice
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13
-$column_count = count( $columns );
13
+$column_count = count($columns);
14 14
 ?>
15 15
 
16
-<?php do_action( 'wpinv_before_email_items', $invoice ); ?>
16
+<?php do_action('wpinv_before_email_items', $invoice); ?>
17 17
 
18 18
 
19 19
 <div id="wpinv-email-items">
20 20
 
21 21
     <h3 class="invoice-items-title">
22
-        <?php echo sprintf( esc_html__( '%s Items', 'invoicing' ), ucfirst( $invoice->get_invoice_quote_type() )); ?>
22
+        <?php echo sprintf(esc_html__('%s Items', 'invoicing'), ucfirst($invoice->get_invoice_quote_type())); ?>
23 23
     </h3>
24 24
 
25 25
     <table class="table table-bordered table-hover">
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 
29 29
             <tr class="wpinv_cart_header_row">
30 30
 
31
-                <?php foreach ( $columns as $key => $label ) : ?>
32
-                    <th class="<?php echo 'name' == $key ? 'text-left' : 'text-right' ?> wpinv_cart_item_<?php echo sanitize_html_class( $key ); ?>">
33
-                        <?php echo sanitize_text_field( $label ); ?>
31
+                <?php foreach ($columns as $key => $label) : ?>
32
+                    <th class="<?php echo 'name' == $key ? 'text-left' : 'text-right' ?> wpinv_cart_item_<?php echo sanitize_html_class($key); ?>">
33
+                        <?php echo sanitize_text_field($label); ?>
34 34
                     </th>
35 35
                 <?php endforeach; ?>
36 36
 
@@ -43,13 +43,13 @@  discard block
 block discarded – undo
43 43
             <?php
44 44
 
45 45
                 // Display the item totals.
46
-                foreach ( $invoice->get_items() as $item ) {
47
-                    wpinv_get_template( 'emails/invoice-item.php', compact( 'invoice', 'item', 'columns' ) );
46
+                foreach ($invoice->get_items() as $item) {
47
+                    wpinv_get_template('emails/invoice-item.php', compact('invoice', 'item', 'columns'));
48 48
                 }
49 49
 
50 50
                 // Display the fee totals.
51
-                foreach ( $invoice->get_fees() as $fee ) {
52
-                    wpinv_get_template( 'emails/fee-item.php', compact( 'invoice', 'fee', 'columns' ) );
51
+                foreach ($invoice->get_fees() as $fee) {
52
+                    wpinv_get_template('emails/fee-item.php', compact('invoice', 'fee', 'columns'));
53 53
                 }
54 54
 
55 55
             ?>
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
         </tbody>
58 58
 
59 59
         <tfoot>
60
-            <?php wpinv_get_template( 'emails/invoice-totals.php', compact( 'invoice', 'column_count' ) ); ?>
60
+            <?php wpinv_get_template('emails/invoice-totals.php', compact('invoice', 'column_count')); ?>
61 61
         </tfoot>
62 62
     
63 63
     </table>
Please login to merge, or discard this patch.