Completed
Push — master ( e1fcb8...b01a52 )
by Brian
26s queued 17s
created
includes/wpinv-helper-functions.php 1 patch
Spacing   +317 added lines, -317 removed lines patch added patch discarded remove patch
@@ -7,86 +7,86 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
 
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool) apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
 
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
 
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double) $amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92 92
 /**
@@ -95,32 +95,32 @@  discard block
 block discarded – undo
95 95
  * @since 1.0.19
96 96
  * @return array
97 97
  */
98
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
98
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
99 99
 	$invoice_statuses = array(
100
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
101
-        'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
102
-        'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
103
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
104
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
105
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
106
-        'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
107
-        'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
100
+		'wpi-pending'    => _x('Pending payment', 'Invoice status', 'invoicing'),
101
+        'publish'        => _x('Paid', 'Invoice status', 'invoicing'),
102
+        'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'),
103
+		'wpi-onhold'     => _x('On hold', 'Invoice status', 'invoicing'),
104
+		'wpi-cancelled'  => _x('Cancelled', 'Invoice status', 'invoicing'),
105
+		'wpi-refunded'   => _x('Refunded', 'Invoice status', 'invoicing'),
106
+        'wpi-failed'     => _x('Failed', 'Invoice status', 'invoicing'),
107
+        'wpi-renewal'    => _x('Renewal Payment', 'Invoice status', 'invoicing'),
108 108
     );
109 109
 
110
-    if ( $draft ) {
111
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
110
+    if ($draft) {
111
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
112 112
     }
113 113
 
114
-    if ( $trashed ) {
115
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
114
+    if ($trashed) {
115
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
116 116
     }
117 117
 
118
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
118
+	return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
119 119
 }
120 120
 
121
-function wpinv_status_nicename( $status ) {
122
-    $statuses = wpinv_get_invoice_statuses( true, true );
123
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
121
+function wpinv_status_nicename($status) {
122
+    $statuses = wpinv_get_invoice_statuses(true, true);
123
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
124 124
 
125 125
     return $status;
126 126
 }
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
  * Retrieves the default currency code.
130 130
  */
131 131
 function wpinv_get_currency() {
132
-    return apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) );
132
+    return apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD'));
133 133
 }
134 134
 
135 135
 /**
@@ -137,61 +137,61 @@  discard block
 block discarded – undo
137 137
  * 
138 138
  * @param string|null $currency The currency code. Defaults to the default currency.
139 139
  */
140
-function wpinv_currency_symbol( $currency = null ) {
140
+function wpinv_currency_symbol($currency = null) {
141 141
 
142 142
     // Prepare the currency.
143
-    $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency );
143
+    $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency);
144 144
 
145 145
     // Fetch all symbols.
146 146
     $symbols = wpinv_get_currency_symbols();
147 147
 
148 148
     // Fetch this currencies symbol.
149
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
149
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
150 150
 
151 151
     // Filter the symbol.
152
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
152
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
153 153
 }
154 154
 
155 155
 function wpinv_currency_position() {
156
-    $position = wpinv_get_option( 'currency_position', 'left' );
156
+    $position = wpinv_get_option('currency_position', 'left');
157 157
     
158
-    return apply_filters( 'wpinv_currency_position', $position );
158
+    return apply_filters('wpinv_currency_position', $position);
159 159
 }
160 160
 
161 161
 function wpinv_thousands_separator() {
162
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
162
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
163 163
     
164
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
164
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
165 165
 }
166 166
 
167 167
 function wpinv_decimal_separator() {
168
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
168
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
169 169
     
170
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
170
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
171 171
 }
172 172
 
173 173
 function wpinv_decimals() {
174
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
174
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
175 175
     
176
-    return absint( $decimals );
176
+    return absint($decimals);
177 177
 }
178 178
 
179 179
 /**
180 180
  * Retrieves a list of all supported currencies.
181 181
  */
182 182
 function wpinv_get_currencies() {
183
-    return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) );
183
+    return apply_filters('wpinv_currencies', wpinv_get_data('currencies'));
184 184
 }
185 185
 
186 186
 /**
187 187
  * Retrieves a list of all currency symbols.
188 188
  */
189 189
 function wpinv_get_currency_symbols() {
190
-    return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) );
190
+    return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols'));
191 191
 }
192 192
 
193
-function wpinv_price( $amount = '', $currency = '' ) {
194
-    if( empty( $currency ) ) {
193
+function wpinv_price($amount = '', $currency = '') {
194
+    if (empty($currency)) {
195 195
         $currency = wpinv_get_currency();
196 196
     }
197 197
 
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
 
200 200
     $negative = $amount < 0;
201 201
 
202
-    if ( $negative ) {
203
-        $amount = substr( $amount, 1 );
202
+    if ($negative) {
203
+        $amount = substr($amount, 1);
204 204
     }
205 205
 
206
-    $symbol = wpinv_currency_symbol( $currency );
206
+    $symbol = wpinv_currency_symbol($currency);
207 207
 
208
-    if ( $position == 'left' || $position == 'left_space' ) {
209
-        switch ( $currency ) {
208
+    if ($position == 'left' || $position == 'left_space') {
209
+        switch ($currency) {
210 210
             case "GBP" :
211 211
             case "BRL" :
212 212
             case "EUR" :
@@ -218,15 +218,15 @@  discard block
 block discarded – undo
218 218
             case "NZD" :
219 219
             case "SGD" :
220 220
             case "JPY" :
221
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
221
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
222 222
                 break;
223 223
             default :
224 224
                 //$price = $currency . ' ' . $amount;
225
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
225
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
226 226
                 break;
227 227
         }
228 228
     } else {
229
-        switch ( $currency ) {
229
+        switch ($currency) {
230 230
             case "GBP" :
231 231
             case "BRL" :
232 232
             case "EUR" :
@@ -237,83 +237,83 @@  discard block
 block discarded – undo
237 237
             case "MXN" :
238 238
             case "SGD" :
239 239
             case "JPY" :
240
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
240
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
241 241
                 break;
242 242
             default :
243 243
                 //$price = $amount . ' ' . $currency;
244
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
244
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
245 245
                 break;
246 246
         }
247 247
     }
248 248
     
249
-    if ( $negative ) {
249
+    if ($negative) {
250 250
         $price = '-' . $price;
251 251
     }
252 252
     
253
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
253
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
254 254
 
255 255
     return $price;
256 256
 }
257 257
 
258
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
258
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
259 259
     $thousands_sep = wpinv_thousands_separator();
260 260
     $decimal_sep   = wpinv_decimal_separator();
261 261
 
262
-    if ( $decimals === NULL ) {
262
+    if ($decimals === NULL) {
263 263
         $decimals = wpinv_decimals();
264 264
     }
265 265
 
266
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
267
-        $whole = substr( $amount, 0, $sep_found );
268
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
266
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
267
+        $whole = substr($amount, 0, $sep_found);
268
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
269 269
         $amount = $whole . '.' . $part;
270 270
     }
271 271
 
272
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
273
-        $amount = str_replace( ',', '', $amount );
272
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
273
+        $amount = str_replace(',', '', $amount);
274 274
     }
275 275
 
276
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
277
-        $amount = str_replace( ' ', '', $amount );
276
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
277
+        $amount = str_replace(' ', '', $amount);
278 278
     }
279 279
 
280
-    if ( empty( $amount ) ) {
280
+    if (empty($amount)) {
281 281
         $amount = 0;
282 282
     }
283 283
     
284
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
285
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
284
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
285
+    $formatted = number_format((float) $amount, $decimals, $decimal_sep, $thousands_sep);
286 286
     
287
-    if ( $calculate ) {
288
-        if ( $thousands_sep === "," ) {
289
-            $formatted = str_replace( ",", "", $formatted );
287
+    if ($calculate) {
288
+        if ($thousands_sep === ",") {
289
+            $formatted = str_replace(",", "", $formatted);
290 290
         }
291 291
         
292
-        if ( $decimal_sep === "," ) {
293
-            $formatted = str_replace( ",", ".", $formatted );
292
+        if ($decimal_sep === ",") {
293
+            $formatted = str_replace(",", ".", $formatted);
294 294
         }
295 295
     }
296 296
 
297
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
297
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
298 298
 }
299
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
299
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
300 300
 
301
-function wpinv_sanitize_key( $key ) {
301
+function wpinv_sanitize_key($key) {
302 302
     $raw_key = $key;
303
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
303
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
304 304
 
305
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
305
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
306 306
 }
307 307
 
308
-function wpinv_get_file_extension( $str ) {
309
-    $parts = explode( '.', $str );
310
-    return end( $parts );
308
+function wpinv_get_file_extension($str) {
309
+    $parts = explode('.', $str);
310
+    return end($parts);
311 311
 }
312 312
 
313
-function wpinv_string_is_image_url( $str ) {
314
-    $ext = wpinv_get_file_extension( $str );
313
+function wpinv_string_is_image_url($str) {
314
+    $ext = wpinv_get_file_extension($str);
315 315
 
316
-    switch ( strtolower( $ext ) ) {
316
+    switch (strtolower($ext)) {
317 317
         case 'jpeg';
318 318
         case 'jpg';
319 319
             $return = true;
@@ -329,33 +329,33 @@  discard block
 block discarded – undo
329 329
             break;
330 330
     }
331 331
 
332
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
332
+    return (bool) apply_filters('wpinv_string_is_image', $return, $str);
333 333
 }
334 334
 
335
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
336
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
335
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
336
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
337 337
     
338
-    if ( true === $should_log ) {
338
+    if (true === $should_log) {
339 339
         $label = '';
340
-        if ( $file && $file !== '' ) {
341
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
340
+        if ($file && $file !== '') {
341
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
342 342
         }
343 343
         
344
-        if ( $title && $title !== '' ) {
344
+        if ($title && $title !== '') {
345 345
             $label = $label !== '' ? $label . ' ' : '';
346 346
             $label .= $title . ' ';
347 347
         }
348 348
         
349
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
349
+        $label = $label !== '' ? trim($label) . ' : ' : '';
350 350
         
351
-        if ( is_array( $log ) || is_object( $log ) ) {
352
-            error_log( $label . print_r( $log, true ) );
351
+        if (is_array($log) || is_object($log)) {
352
+            error_log($label . print_r($log, true));
353 353
         } else {
354
-            error_log( $label . $log );
354
+            error_log($label . $log);
355 355
         }
356 356
 
357
-        error_log( wp_debug_backtrace_summary() );
358
-        if ( $exit ) {
357
+        error_log(wp_debug_backtrace_summary());
358
+        if ($exit) {
359 359
             exit;
360 360
         }
361 361
     }
@@ -363,32 +363,32 @@  discard block
 block discarded – undo
363 363
 
364 364
 function wpinv_is_ajax_disabled() {
365 365
     $retval = false;
366
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
366
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
367 367
 }
368 368
 
369
-function wpinv_get_current_page_url( $nocache = false ) {
369
+function wpinv_get_current_page_url($nocache = false) {
370 370
     global $wp;
371 371
 
372
-    if ( get_option( 'permalink_structure' ) ) {
373
-        $base = trailingslashit( home_url( $wp->request ) );
372
+    if (get_option('permalink_structure')) {
373
+        $base = trailingslashit(home_url($wp->request));
374 374
     } else {
375
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
376
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
375
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
376
+        $base = remove_query_arg(array('post_type', 'name'), $base);
377 377
     }
378 378
 
379 379
     $scheme = is_ssl() ? 'https' : 'http';
380
-    $uri    = set_url_scheme( $base, $scheme );
380
+    $uri    = set_url_scheme($base, $scheme);
381 381
 
382
-    if ( is_front_page() ) {
383
-        $uri = home_url( '/' );
384
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
382
+    if (is_front_page()) {
383
+        $uri = home_url('/');
384
+    } elseif (wpinv_is_checkout(array(), false)) {
385 385
         $uri = wpinv_get_checkout_uri();
386 386
     }
387 387
 
388
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
388
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
389 389
 
390
-    if ( $nocache ) {
391
-        $uri = wpinv_add_cache_busting( $uri );
390
+    if ($nocache) {
391
+        $uri = wpinv_add_cache_busting($uri);
392 392
     }
393 393
 
394 394
     return $uri;
@@ -401,46 +401,46 @@  discard block
 block discarded – undo
401 401
  * @param string $name  Constant name.
402 402
  * @param mixed  $value Value.
403 403
  */
404
-function getpaid_maybe_define_constant( $name, $value ) {
405
-	if ( ! defined( $name ) ) {
406
-		define( $name, $value );
404
+function getpaid_maybe_define_constant($name, $value) {
405
+	if (!defined($name)) {
406
+		define($name, $value);
407 407
 	}
408 408
 }
409 409
 
410 410
 function wpinv_get_php_arg_separator_output() {
411
-	return ini_get( 'arg_separator.output' );
411
+	return ini_get('arg_separator.output');
412 412
 }
413 413
 
414
-function wpinv_rgb_from_hex( $color ) {
415
-    $color = str_replace( '#', '', $color );
414
+function wpinv_rgb_from_hex($color) {
415
+    $color = str_replace('#', '', $color);
416 416
 
417 417
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
418
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
419
-    if ( empty( $color ) ) {
418
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
419
+    if (empty($color)) {
420 420
         return NULL;
421 421
     }
422 422
 
423
-    $color = str_split( $color );
423
+    $color = str_split($color);
424 424
 
425 425
     $rgb      = array();
426
-    $rgb['R'] = hexdec( $color[0] . $color[1] );
427
-    $rgb['G'] = hexdec( $color[2] . $color[3] );
428
-    $rgb['B'] = hexdec( $color[4] . $color[5] );
426
+    $rgb['R'] = hexdec($color[0] . $color[1]);
427
+    $rgb['G'] = hexdec($color[2] . $color[3]);
428
+    $rgb['B'] = hexdec($color[4] . $color[5]);
429 429
 
430 430
     return $rgb;
431 431
 }
432 432
 
433
-function wpinv_hex_darker( $color, $factor = 30 ) {
434
-    $base  = wpinv_rgb_from_hex( $color );
433
+function wpinv_hex_darker($color, $factor = 30) {
434
+    $base  = wpinv_rgb_from_hex($color);
435 435
     $color = '#';
436 436
 
437
-    foreach ( $base as $k => $v ) {
437
+    foreach ($base as $k => $v) {
438 438
         $amount      = $v / 100;
439
-        $amount      = round( $amount * $factor );
439
+        $amount      = round($amount * $factor);
440 440
         $new_decimal = $v - $amount;
441 441
 
442
-        $new_hex_component = dechex( $new_decimal );
443
-        if ( strlen( $new_hex_component ) < 2 ) {
442
+        $new_hex_component = dechex($new_decimal);
443
+        if (strlen($new_hex_component) < 2) {
444 444
             $new_hex_component = "0" . $new_hex_component;
445 445
         }
446 446
         $color .= $new_hex_component;
@@ -449,18 +449,18 @@  discard block
 block discarded – undo
449 449
     return $color;
450 450
 }
451 451
 
452
-function wpinv_hex_lighter( $color, $factor = 30 ) {
453
-    $base  = wpinv_rgb_from_hex( $color );
452
+function wpinv_hex_lighter($color, $factor = 30) {
453
+    $base  = wpinv_rgb_from_hex($color);
454 454
     $color = '#';
455 455
 
456
-    foreach ( $base as $k => $v ) {
456
+    foreach ($base as $k => $v) {
457 457
         $amount      = 255 - $v;
458 458
         $amount      = $amount / 100;
459
-        $amount      = round( $amount * $factor );
459
+        $amount      = round($amount * $factor);
460 460
         $new_decimal = $v + $amount;
461 461
 
462
-        $new_hex_component = dechex( $new_decimal );
463
-        if ( strlen( $new_hex_component ) < 2 ) {
462
+        $new_hex_component = dechex($new_decimal);
463
+        if (strlen($new_hex_component) < 2) {
464 464
             $new_hex_component = "0" . $new_hex_component;
465 465
         }
466 466
         $color .= $new_hex_component;
@@ -469,22 +469,22 @@  discard block
 block discarded – undo
469 469
     return $color;
470 470
 }
471 471
 
472
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
473
-    $hex = str_replace( '#', '', $color );
472
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
473
+    $hex = str_replace('#', '', $color);
474 474
 
475
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
476
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
477
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
475
+    $c_r = hexdec(substr($hex, 0, 2));
476
+    $c_g = hexdec(substr($hex, 2, 2));
477
+    $c_b = hexdec(substr($hex, 4, 2));
478 478
 
479
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
479
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
480 480
 
481 481
     return $brightness > 155 ? $dark : $light;
482 482
 }
483 483
 
484
-function wpinv_format_hex( $hex ) {
485
-    $hex = trim( str_replace( '#', '', $hex ) );
484
+function wpinv_format_hex($hex) {
485
+    $hex = trim(str_replace('#', '', $hex));
486 486
 
487
-    if ( strlen( $hex ) == 3 ) {
487
+    if (strlen($hex) == 3) {
488 488
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
489 489
     }
490 490
 
@@ -504,12 +504,12 @@  discard block
 block discarded – undo
504 504
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
505 505
  * @return string
506 506
  */
507
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
508
-    if ( function_exists( 'mb_strimwidth' ) ) {
509
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
507
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
508
+    if (function_exists('mb_strimwidth')) {
509
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
510 510
     }
511 511
     
512
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
512
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
513 513
 }
514 514
 
515 515
 /**
@@ -521,28 +521,28 @@  discard block
 block discarded – undo
521 521
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
522 522
  * @return int Returns the number of characters in string.
523 523
  */
524
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
525
-    if ( function_exists( 'mb_strlen' ) ) {
526
-        return mb_strlen( $str, $encoding );
524
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
525
+    if (function_exists('mb_strlen')) {
526
+        return mb_strlen($str, $encoding);
527 527
     }
528 528
         
529
-    return strlen( $str );
529
+    return strlen($str);
530 530
 }
531 531
 
532
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
533
-    if ( function_exists( 'mb_strtolower' ) ) {
534
-        return mb_strtolower( $str, $encoding );
532
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
533
+    if (function_exists('mb_strtolower')) {
534
+        return mb_strtolower($str, $encoding);
535 535
     }
536 536
     
537
-    return strtolower( $str );
537
+    return strtolower($str);
538 538
 }
539 539
 
540
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
541
-    if ( function_exists( 'mb_strtoupper' ) ) {
542
-        return mb_strtoupper( $str, $encoding );
540
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
541
+    if (function_exists('mb_strtoupper')) {
542
+        return mb_strtoupper($str, $encoding);
543 543
     }
544 544
     
545
-    return strtoupper( $str );
545
+    return strtoupper($str);
546 546
 }
547 547
 
548 548
 /**
@@ -556,12 +556,12 @@  discard block
 block discarded – undo
556 556
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
557 557
  * @return int Returns the position of the first occurrence of search in the string.
558 558
  */
559
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
560
-    if ( function_exists( 'mb_strpos' ) ) {
561
-        return mb_strpos( $str, $find, $offset, $encoding );
559
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
560
+    if (function_exists('mb_strpos')) {
561
+        return mb_strpos($str, $find, $offset, $encoding);
562 562
     }
563 563
         
564
-    return strpos( $str, $find, $offset );
564
+    return strpos($str, $find, $offset);
565 565
 }
566 566
 
567 567
 /**
@@ -575,12 +575,12 @@  discard block
 block discarded – undo
575 575
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
576 576
  * @return int Returns the position of the last occurrence of search.
577 577
  */
578
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
579
-    if ( function_exists( 'mb_strrpos' ) ) {
580
-        return mb_strrpos( $str, $find, $offset, $encoding );
578
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
579
+    if (function_exists('mb_strrpos')) {
580
+        return mb_strrpos($str, $find, $offset, $encoding);
581 581
     }
582 582
         
583
-    return strrpos( $str, $find, $offset );
583
+    return strrpos($str, $find, $offset);
584 584
 }
585 585
 
586 586
 /**
@@ -595,16 +595,16 @@  discard block
 block discarded – undo
595 595
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
596 596
  * @return string
597 597
  */
598
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
599
-    if ( function_exists( 'mb_substr' ) ) {
600
-        if ( $length === null ) {
601
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
598
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
599
+    if (function_exists('mb_substr')) {
600
+        if ($length === null) {
601
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
602 602
         } else {
603
-            return mb_substr( $str, $start, $length, $encoding );
603
+            return mb_substr($str, $start, $length, $encoding);
604 604
         }
605 605
     }
606 606
         
607
-    return substr( $str, $start, $length );
607
+    return substr($str, $start, $length);
608 608
 }
609 609
 
610 610
 /**
@@ -616,48 +616,48 @@  discard block
 block discarded – undo
616 616
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
617 617
  * @return string The width of string.
618 618
  */
619
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
620
-    if ( function_exists( 'mb_strwidth' ) ) {
621
-        return mb_strwidth( $str, $encoding );
619
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
620
+    if (function_exists('mb_strwidth')) {
621
+        return mb_strwidth($str, $encoding);
622 622
     }
623 623
     
624
-    return wpinv_utf8_strlen( $str, $encoding );
624
+    return wpinv_utf8_strlen($str, $encoding);
625 625
 }
626 626
 
627
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
628
-    if ( function_exists( 'mb_strlen' ) ) {
629
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
627
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
628
+    if (function_exists('mb_strlen')) {
629
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
630 630
         $str_end = "";
631 631
         
632
-        if ( $lower_str_end ) {
633
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
632
+        if ($lower_str_end) {
633
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
634 634
         } else {
635
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
635
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
636 636
         }
637 637
 
638 638
         return $first_letter . $str_end;
639 639
     }
640 640
     
641
-    return ucfirst( $str );
641
+    return ucfirst($str);
642 642
 }
643 643
 
644
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
645
-    if ( function_exists( 'mb_convert_case' ) ) {
646
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
644
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
645
+    if (function_exists('mb_convert_case')) {
646
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
647 647
     }
648 648
     
649
-    return ucwords( $str );
649
+    return ucwords($str);
650 650
 }
651 651
 
652
-function wpinv_period_in_days( $period, $unit ) {
653
-    $period = absint( $period );
652
+function wpinv_period_in_days($period, $unit) {
653
+    $period = absint($period);
654 654
     
655
-    if ( $period > 0 ) {
656
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
655
+    if ($period > 0) {
656
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
657 657
             $period = $period * 7;
658
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
658
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
659 659
             $period = $period * 30;
660
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
660
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
661 661
             $period = $period * 365;
662 662
         }
663 663
     }
@@ -665,14 +665,14 @@  discard block
 block discarded – undo
665 665
     return $period;
666 666
 }
667 667
 
668
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
669
-    if ( function_exists( 'cal_days_in_month' ) ) {
670
-        return cal_days_in_month( $calendar, $month, $year );
668
+function wpinv_cal_days_in_month($calendar, $month, $year) {
669
+    if (function_exists('cal_days_in_month')) {
670
+        return cal_days_in_month($calendar, $month, $year);
671 671
     }
672 672
 
673 673
     // Fallback in case the calendar extension is not loaded in PHP
674 674
     // Only supports Gregorian calendar
675
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
675
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
676 676
 }
677 677
 
678 678
 /**
@@ -683,11 +683,11 @@  discard block
 block discarded – undo
683 683
  *
684 684
  * @return string
685 685
  */
686
-function wpi_help_tip( $tip, $allow_html = false ) {
687
-    if ( $allow_html ) {
688
-        $tip = wpi_sanitize_tooltip( $tip );
686
+function wpi_help_tip($tip, $allow_html = false) {
687
+    if ($allow_html) {
688
+        $tip = wpi_sanitize_tooltip($tip);
689 689
     } else {
690
-        $tip = esc_attr( $tip );
690
+        $tip = esc_attr($tip);
691 691
     }
692 692
 
693 693
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -701,8 +701,8 @@  discard block
 block discarded – undo
701 701
  * @param string $var
702 702
  * @return string
703 703
  */
704
-function wpi_sanitize_tooltip( $var ) {
705
-    return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
704
+function wpi_sanitize_tooltip($var) {
705
+    return htmlspecialchars(wp_kses(html_entity_decode($var), array(
706 706
         'br'     => array(),
707 707
         'em'     => array(),
708 708
         'strong' => array(),
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
         'li'     => array(),
713 713
         'ol'     => array(),
714 714
         'p'      => array(),
715
-    ) ) );
715
+    )));
716 716
 }
717 717
 
718 718
 /**
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
  */
723 723
 function wpinv_get_screen_ids() {
724 724
 
725
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
725
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
726 726
 
727 727
     $screen_ids = array(
728 728
         'toplevel_page_' . $screen_id,
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
         'invoicing_page_wpi-addons',
741 741
     );
742 742
 
743
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
743
+    return apply_filters('wpinv_screen_ids', $screen_ids);
744 744
 }
745 745
 
746 746
 /**
@@ -751,14 +751,14 @@  discard block
 block discarded – undo
751 751
  * @param array|string $list List of values.
752 752
  * @return array Sanitized array of values.
753 753
  */
754
-function wpinv_parse_list( $list ) {
754
+function wpinv_parse_list($list) {
755 755
 
756
-    if ( empty( $list ) ) {
756
+    if (empty($list)) {
757 757
         $list = array();
758 758
     }
759 759
 
760
-	if ( ! is_array( $list ) ) {
761
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
760
+	if (!is_array($list)) {
761
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
762 762
 	}
763 763
 
764 764
 	return $list;
@@ -772,16 +772,16 @@  discard block
 block discarded – undo
772 772
  * @param string $key Type of data to fetch.
773 773
  * @return mixed Fetched data.
774 774
  */
775
-function wpinv_get_data( $key ) {
775
+function wpinv_get_data($key) {
776 776
 
777 777
     // Try fetching it from the cache.
778
-    $data = wp_cache_get( "wpinv-data-$key", 'wpinv' );
779
-    if( $data ) {
778
+    $data = wp_cache_get("wpinv-data-$key", 'wpinv');
779
+    if ($data) {
780 780
         return $data;
781 781
     }
782 782
 
783
-    $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
784
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
783
+    $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php");
784
+	wp_cache_set("wpinv-data-$key", $data, 'wpinv');
785 785
 
786 786
 	return $data;
787 787
 }
@@ -795,10 +795,10 @@  discard block
 block discarded – undo
795 795
  * @param bool $first_empty Whether or not the first item in the list should be empty
796 796
  * @return mixed Fetched data.
797 797
  */
798
-function wpinv_maybe_add_empty_option( $options, $first_empty ) {
798
+function wpinv_maybe_add_empty_option($options, $first_empty) {
799 799
 
800
-    if ( ! empty( $options ) && $first_empty ) {
801
-        return array_merge( array( '' => '' ), $options );
800
+    if (!empty($options) && $first_empty) {
801
+        return array_merge(array('' => ''), $options);
802 802
     }
803 803
     return $options;
804 804
 
@@ -810,21 +810,21 @@  discard block
 block discarded – undo
810 810
  * @param mixed $var Data to sanitize.
811 811
  * @return string|array
812 812
  */
813
-function wpinv_clean( $var ) {
813
+function wpinv_clean($var) {
814 814
 
815
-	if ( is_array( $var ) ) {
816
-		return array_map( 'wpinv_clean', $var );
815
+	if (is_array($var)) {
816
+		return array_map('wpinv_clean', $var);
817 817
     }
818 818
 
819
-    if ( is_object( $var ) ) {
820
-		$object_vars = get_object_vars( $var );
821
-		foreach ( $object_vars as $property_name => $property_value ) {
822
-			$var->$property_name = wpinv_clean( $property_value );
819
+    if (is_object($var)) {
820
+		$object_vars = get_object_vars($var);
821
+		foreach ($object_vars as $property_name => $property_value) {
822
+			$var->$property_name = wpinv_clean($property_value);
823 823
         }
824 824
         return $var;
825 825
 	}
826 826
     
827
-    return is_string( $var ) ? sanitize_text_field( $var ) : $var;
827
+    return is_string($var) ? sanitize_text_field($var) : $var;
828 828
 }
829 829
 
830 830
 /**
@@ -833,43 +833,43 @@  discard block
 block discarded – undo
833 833
  * @param string $str Data to convert.
834 834
  * @return string|array
835 835
  */
836
-function getpaid_convert_price_string_to_options( $str ) {
836
+function getpaid_convert_price_string_to_options($str) {
837 837
 
838
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
839
-    $options     = array();
838
+	$raw_options = array_map('trim', explode(',', $str));
839
+    $options = array();
840 840
 
841
-    foreach ( $raw_options as $option ) {
841
+    foreach ($raw_options as $option) {
842 842
 
843
-        if ( '' == $option ) {
843
+        if ('' == $option) {
844 844
             continue;
845 845
         }
846 846
 
847
-        $option = array_map( 'trim', explode( '|', $option ) );
847
+        $option = array_map('trim', explode('|', $option));
848 848
 
849 849
         $price = null;
850 850
         $label = null;
851 851
 
852
-        if ( isset( $option[0] ) && '' !=  $option[0] ) {
853
-            $label  = $option[0];
852
+        if (isset($option[0]) && '' != $option[0]) {
853
+            $label = $option[0];
854 854
         }
855 855
 
856
-        if ( isset( $option[1] ) && '' !=  $option[1] ) {
856
+        if (isset($option[1]) && '' != $option[1]) {
857 857
             $price = $option[1];
858 858
         }
859 859
 
860
-        if ( ! isset( $price ) ) {
860
+        if (!isset($price)) {
861 861
             $price = $label;
862 862
         }
863 863
 
864
-        if ( ! isset( $price ) || ! is_numeric( $price ) ) {
864
+        if (!isset($price) || !is_numeric($price)) {
865 865
             continue;
866 866
         }
867 867
 
868
-        if ( ! isset( $label ) ) {
868
+        if (!isset($label)) {
869 869
             $label = $price;
870 870
         }
871 871
 
872
-        $options[ $price ] = $label;
872
+        $options[$price] = $label;
873 873
     }
874 874
 
875 875
     return $options;
@@ -878,22 +878,22 @@  discard block
 block discarded – undo
878 878
 /**
879 879
  * Returns the help tip.
880 880
  */
881
-function getpaid_get_help_tip( $tip, $additional_classes = '' ) {
882
-    $additional_classes = sanitize_html_class( $additional_classes );
883
-    $tip                = esc_attr__( $tip );
881
+function getpaid_get_help_tip($tip, $additional_classes = '') {
882
+    $additional_classes = sanitize_html_class($additional_classes);
883
+    $tip                = esc_attr__($tip);
884 884
     return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>";
885 885
 }
886 886
 
887 887
 /**
888 888
  * Formats a date
889 889
  */
890
-function getpaid_format_date( $date ) {
890
+function getpaid_format_date($date) {
891 891
 
892
-    if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) {
892
+    if (empty($date) || $date == '0000-00-00 00:00:00') {
893 893
         return '';
894 894
     }
895 895
 
896
-    return date_i18n( /** @scrutinizer ignore-type */get_option( 'date_format' ), strtotime( $date ) );
896
+    return date_i18n(/** @scrutinizer ignore-type */get_option('date_format'), strtotime($date));
897 897
 
898 898
 }
899 899
 
@@ -902,9 +902,9 @@  discard block
 block discarded – undo
902 902
  *
903 903
  * @return string
904 904
  */
905
-function getpaid_format_date_value( $date, $default = "&mdash;" ) {
906
-    $date = getpaid_format_date( $date );
907
-    return empty( $date ) ? $default : $date;
905
+function getpaid_format_date_value($date, $default = "&mdash;") {
906
+    $date = getpaid_format_date($date);
907
+    return empty($date) ? $default : $date;
908 908
 }
909 909
 
910 910
 /**
@@ -914,16 +914,16 @@  discard block
 block discarded – undo
914 914
  * @param  integer $limit Limit size in characters.
915 915
  * @return string
916 916
  */
917
-function getpaid_limit_length( $string, $limit ) {
917
+function getpaid_limit_length($string, $limit) {
918 918
     $str_limit = $limit - 3;
919 919
 
920
-	if ( function_exists( 'mb_strimwidth' ) ) {
921
-		if ( mb_strlen( $string ) > $limit ) {
922
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
920
+	if (function_exists('mb_strimwidth')) {
921
+		if (mb_strlen($string) > $limit) {
922
+			$string = mb_strimwidth($string, 0, $str_limit) . '...';
923 923
 		}
924 924
 	} else {
925
-		if ( strlen( $string ) > $limit ) {
926
-			$string = substr( $string, 0, $str_limit ) . '...';
925
+		if (strlen($string) > $limit) {
926
+			$string = substr($string, 0, $str_limit) . '...';
927 927
 		}
928 928
 	}
929 929
     return $string;
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
  * @since 1.0.19
938 938
  */
939 939
 function getpaid_api() {
940
-    return getpaid()->get( 'api' );
940
+    return getpaid()->get('api');
941 941
 }
942 942
 
943 943
 /**
@@ -947,7 +947,7 @@  discard block
 block discarded – undo
947 947
  * @since 1.0.19
948 948
  */
949 949
 function getpaid_post_types() {
950
-    return getpaid()->get( 'post_types' );
950
+    return getpaid()->get('post_types');
951 951
 }
952 952
 
953 953
 /**
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
  * @since 1.0.19
958 958
  */
959 959
 function getpaid_session() {
960
-    return getpaid()->get( 'session' );
960
+    return getpaid()->get('session');
961 961
 }
962 962
 
963 963
 /**
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
  * @since 1.0.19
968 968
  */
969 969
 function getpaid_notes() {
970
-    return getpaid()->get( 'notes' );
970
+    return getpaid()->get('notes');
971 971
 }
972 972
 
973 973
 /**
@@ -979,26 +979,26 @@  discard block
 block discarded – undo
979 979
  * 
980 980
  * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query
981 981
  */
982
-function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
982
+function getpaid_get_subscriptions($args = array(), $return = 'results') {
983 983
 
984 984
     // Do not retrieve all fields if we just want the count.
985
-    if ( 'count' == $return ) {
985
+    if ('count' == $return) {
986 986
         $args['fields'] = 'id';
987 987
         $args['number'] = 1;
988 988
     }
989 989
 
990 990
     // Do not count all matches if we just want the results.
991
-    if ( 'results' == $return ) {
991
+    if ('results' == $return) {
992 992
         $args['count_total'] = false;
993 993
     }
994 994
 
995
-    $query = new GetPaid_Subscriptions_Query( $args );
995
+    $query = new GetPaid_Subscriptions_Query($args);
996 996
 
997
-    if ( 'results' == $return ) {
997
+    if ('results' == $return) {
998 998
         return $query->get_results();
999 999
     }
1000 1000
 
1001
-    if ( 'count' == $return ) {
1001
+    if ('count' == $return) {
1002 1002
         return $query->get_total();
1003 1003
     }
1004 1004
 
@@ -1015,13 +1015,13 @@  discard block
 block discarded – undo
1015 1015
     return apply_filters(
1016 1016
         'getpaid_get_subscription_statuses',
1017 1017
         array(
1018
-            'pending'    => __( 'Pending', 'invoicing' ),
1019
-            'trialling'  => __( 'Trialing', 'invoicing' ),
1020
-            'active'     => __( 'Active', 'invoicing' ),
1021
-            'failing'    => __( 'Failing', 'invoicing' ),
1022
-            'expired'    => __( 'Expired', 'invoicing' ),
1023
-            'completed'  => __( 'Complete', 'invoicing' ),
1024
-            'cancelled'  =>__( 'Cancelled', 'invoicing' ),
1018
+            'pending'    => __('Pending', 'invoicing'),
1019
+            'trialling'  => __('Trialing', 'invoicing'),
1020
+            'active'     => __('Active', 'invoicing'),
1021
+            'failing'    => __('Failing', 'invoicing'),
1022
+            'expired'    => __('Expired', 'invoicing'),
1023
+            'completed'  => __('Complete', 'invoicing'),
1024
+            'cancelled'  =>__('Cancelled', 'invoicing'),
1025 1025
         )
1026 1026
     );
1027 1027
 
@@ -1032,9 +1032,9 @@  discard block
 block discarded – undo
1032 1032
  * 
1033 1033
  * @return string
1034 1034
  */
1035
-function getpaid_get_subscription_status_label( $status ) {
1035
+function getpaid_get_subscription_status_label($status) {
1036 1036
     $statuses = getpaid_get_subscription_statuses();
1037
-    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( $status );
1037
+    return isset($statuses[$status]) ? $statuses[$status] : ucfirst($status);
1038 1038
 }
1039 1039
 
1040 1040
 /**
@@ -1064,14 +1064,14 @@  discard block
 block discarded – undo
1064 1064
  * 
1065 1065
  * @return array
1066 1066
  */
1067
-function getpaid_get_subscription_status_counts( $args = array() ) {
1067
+function getpaid_get_subscription_status_counts($args = array()) {
1068 1068
 
1069
-    $statuses = array_keys( getpaid_get_subscription_statuses() );
1069
+    $statuses = array_keys(getpaid_get_subscription_statuses());
1070 1070
     $counts   = array();
1071 1071
 
1072
-    foreach ( $statuses as $status ) {
1073
-        $_args             = wp_parse_args( "status=$status", $args );
1074
-        $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
1072
+    foreach ($statuses as $status) {
1073
+        $_args             = wp_parse_args("status=$status", $args);
1074
+        $counts[$status] = getpaid_get_subscriptions($_args, 'count');
1075 1075
     }
1076 1076
 
1077 1077
     return $counts;
@@ -1083,20 +1083,20 @@  discard block
 block discarded – undo
1083 1083
  * 
1084 1084
  * @return string
1085 1085
  */
1086
-function getpaid_get_subscription_period_label( $period ) {
1086
+function getpaid_get_subscription_period_label($period) {
1087 1087
 
1088 1088
     $periods = array(
1089
-        'd'     => __( 'day', 'invoicing' ),
1090
-        'day'   => __( 'day', 'invoicing' ),
1091
-        'w'     => __( 'week', 'invoicing' ),
1092
-        'week'  => __( 'week', 'invoicing' ),
1093
-        'm'     => __( 'month', 'invoicing' ),
1094
-        'month' => __( 'month', 'invoicing' ),
1095
-        'y'     => __( 'year', 'invoicing' ),
1096
-        'year'  => __( 'year', 'invoicing' ),
1089
+        'd'     => __('day', 'invoicing'),
1090
+        'day'   => __('day', 'invoicing'),
1091
+        'w'     => __('week', 'invoicing'),
1092
+        'week'  => __('week', 'invoicing'),
1093
+        'm'     => __('month', 'invoicing'),
1094
+        'month' => __('month', 'invoicing'),
1095
+        'y'     => __('year', 'invoicing'),
1096
+        'year'  => __('year', 'invoicing'),
1097 1097
     );
1098 1098
 
1099
-    return isset( $periods[ $period ] ) ? strtolower( $periods[ $period ] ) : strtolower( $periods['d'] );
1099
+    return isset($periods[$period]) ? strtolower($periods[$period]) : strtolower($periods['d']);
1100 1100
 }
1101 1101
 
1102 1102
 /**
@@ -1105,7 +1105,7 @@  discard block
 block discarded – undo
1105 1105
  * @return GetPaid_Admin
1106 1106
  */
1107 1107
 function getpaid_admin() {
1108
-    return getpaid()->get( 'admin' );
1108
+    return getpaid()->get('admin');
1109 1109
 }
1110 1110
 
1111 1111
 /**
@@ -1115,6 +1115,6 @@  discard block
 block discarded – undo
1115 1115
  * @param string $base the base url
1116 1116
  * @return string
1117 1117
  */
1118
-function getpaid_get_authenticated_action_url( $action, $base = false ) {
1119
-    return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' );
1118
+function getpaid_get_authenticated_action_url($action, $base = false) {
1119
+    return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce');
1120 1120
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 2 patches
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -14,61 +14,61 @@  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
-	 */
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 28
     public $admin_url;
29 29
 
30 30
     /**
31
-	 * Class constructor.
32
-	 */
33
-	public function __construct(){
31
+     * Class constructor.
32
+     */
33
+    public function __construct(){
34 34
 
35 35
         $this->admin_path  = plugin_dir_path( __FILE__ );
36 36
         $this->admin_url   = plugins_url( '/', __FILE__ );
37 37
 
38 38
         if ( is_admin() ) {
39
-			$this->init_admin_hooks();
39
+            $this->init_admin_hooks();
40 40
         }
41 41
 
42 42
     }
43 43
 
44 44
     /**
45
-	 * Init action and filter hooks
46
-	 *
47
-	 */
48
-	private function init_admin_hooks() {
45
+     * Init action and filter hooks
46
+     *
47
+     */
48
+    private function init_admin_hooks() {
49 49
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
50 50
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
51 51
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
52 52
         add_action( 'admin_init', array( $this, 'activation_redirect') );
53 53
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
54
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
-		do_action( 'getpaid_init_admin_hooks', $this );
54
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
+        do_action( 'getpaid_init_admin_hooks', $this );
58 58
 
59 59
     }
60 60
 
61 61
     /**
62
-	 * Register admin scripts
63
-	 *
64
-	 */
65
-	public function enqeue_scripts() {
62
+     * Register admin scripts
63
+     *
64
+     */
65
+    public function enqeue_scripts() {
66 66
         global $current_screen;
67 67
 
68 68
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
69 69
 
70 70
         if ( ! empty( $current_screen->post_type ) ) {
71
-			$page = $current_screen->post_type;
71
+            $page = $current_screen->post_type;
72 72
         }
73 73
 
74 74
         // General styles.
@@ -92,30 +92,30 @@  discard block
 block discarded – undo
92 92
         }
93 93
 
94 94
         // Payment form scripts.
95
-		if ( 'wpi_payment_form' == $page ) {
95
+        if ( 'wpi_payment_form' == $page ) {
96 96
             $this->load_payment_form_scripts();
97 97
         }
98 98
 
99 99
         if ( $page == 'wpinv-subscriptions' ) {
100
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
101
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
102
-		}
100
+            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
101
+            wp_enqueue_script( 'wpinv-sub-admin-script' );
102
+        }
103 103
 
104
-		if ( $page == 'wpinv-reports' ) {
105
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
106
-		}
104
+        if ( $page == 'wpinv-reports' ) {
105
+            wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
106
+        }
107 107
 
108
-		if ( $page == 'wpinv-subscriptions' ) {
109
-			wp_enqueue_script( 'postbox' );
110
-		}
108
+        if ( $page == 'wpinv-subscriptions' ) {
109
+            wp_enqueue_script( 'postbox' );
110
+        }
111 111
 
112 112
     }
113 113
 
114 114
     /**
115
-	 * Returns admin js translations.
116
-	 *
117
-	 */
118
-	protected function get_admin_i18() {
115
+     * Returns admin js translations.
116
+     *
117
+     */
118
+    protected function get_admin_i18() {
119 119
         global $post;
120 120
 
121 121
         return array(
@@ -156,33 +156,33 @@  discard block
 block discarded – undo
156 156
     }
157 157
 
158 158
     /**
159
-	 * Loads payment form js.
160
-	 *
161
-	 */
162
-	protected function load_payment_form_scripts() {
159
+     * Loads payment form js.
160
+     *
161
+     */
162
+    protected function load_payment_form_scripts() {
163 163
         global $post;
164 164
 
165 165
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
166
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
167
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
166
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
167
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
168 168
 
169
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
170
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
169
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
170
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
171 171
 
172
-		wp_localize_script(
172
+        wp_localize_script(
173 173
             'wpinv-admin-payment-form-script',
174 174
             'wpinvPaymentFormAdmin',
175 175
             array(
176
-				'elements'      => $this->form_elements->get_elements(),
177
-				'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
178
-				'all_items'     => $this->form_elements->get_published_items(),
179
-				'currency'      => wpinv_currency_symbol(),
180
-				'position'      => wpinv_currency_position(),
181
-				'decimals'      => (int) wpinv_decimals(),
182
-				'thousands_sep' => wpinv_thousands_separator(),
183
-				'decimals_sep'  => wpinv_decimal_separator(),
184
-				'form_items'    => $this->form_elements->get_form_items( $post->ID ),
185
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
176
+                'elements'      => $this->form_elements->get_elements(),
177
+                'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
178
+                'all_items'     => $this->form_elements->get_published_items(),
179
+                'currency'      => wpinv_currency_symbol(),
180
+                'position'      => wpinv_currency_position(),
181
+                'decimals'      => (int) wpinv_decimals(),
182
+                'thousands_sep' => wpinv_thousands_separator(),
183
+                'decimals_sep'  => wpinv_decimal_separator(),
184
+                'form_items'    => $this->form_elements->get_form_items( $post->ID ),
185
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
186 186
             )
187 187
         );
188 188
 
@@ -191,20 +191,20 @@  discard block
 block discarded – undo
191 191
     }
192 192
 
193 193
     /**
194
-	 * Add our classes to admin pages.
194
+     * Add our classes to admin pages.
195 195
      *
196 196
      * @param string $classes
197 197
      * @return string
198
-	 *
199
-	 */
198
+     *
199
+     */
200 200
     public function admin_body_class( $classes ) {
201
-		global $pagenow, $post, $current_screen;
201
+        global $pagenow, $post, $current_screen;
202 202
 
203 203
 
204 204
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
205 205
 
206 206
         if ( ! empty( $current_screen->post_type ) ) {
207
-			$page = $current_screen->post_type;
207
+            $page = $current_screen->post_type;
208 208
         }
209 209
 
210 210
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -215,27 +215,27 @@  discard block
 block discarded – undo
215 215
             $classes .= ' wpinv-cpt wpinv';
216 216
         }
217 217
 
218
-		if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
219
-			$classes .= ' wpi-editable-n';
220
-		}
218
+        if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
219
+            $classes .= ' wpi-editable-n';
220
+        }
221 221
 
222
-		return $classes;
222
+        return $classes;
223 223
     }
224 224
 
225 225
     /**
226
-	 * Maybe show the AyeCode Connect Notice.
227
-	 */
228
-	public function init_ayecode_connect_helper(){
226
+     * Maybe show the AyeCode Connect Notice.
227
+     */
228
+    public function init_ayecode_connect_helper(){
229 229
 
230 230
         new AyeCode_Connect_Helper(
231 231
             array(
232
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
233
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
234
-				'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>" ),
235
-				'connect_button'    => __("Connect Site","invoicing"),
236
-				'connecting_button'    => __("Connecting...","invoicing"),
237
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
238
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
232
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
233
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
234
+                '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>" ),
235
+                'connect_button'    => __("Connect Site","invoicing"),
236
+                'connecting_button'    => __("Connecting...","invoicing"),
237
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
238
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
239 239
             ),
240 240
             array( 'wpi-addons' )
241 241
         );
@@ -247,21 +247,21 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function activation_redirect() {
249 249
 
250
-		// Bail if no activation redirect.
251
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || is_ajax() ) {
252
-			return;
253
-		}
250
+        // Bail if no activation redirect.
251
+        if ( ! get_transient( '_wpinv_activation_redirect' ) || is_ajax() ) {
252
+            return;
253
+        }
254 254
 
255
-		// Delete the redirect transient.
256
-		delete_transient( '_wpinv_activation_redirect' );
255
+        // Delete the redirect transient.
256
+        delete_transient( '_wpinv_activation_redirect' );
257 257
 
258
-		// Bail if activating from network, or bulk
259
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
260
-			return;
261
-		}
258
+        // Bail if activating from network, or bulk
259
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
260
+            return;
261
+        }
262 262
 
263
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
264
-		exit;
263
+        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
264
+        exit;
265 265
     }
266 266
 
267 267
     /**
@@ -276,150 +276,150 @@  discard block
 block discarded – undo
276 276
 
277 277
     }
278 278
 
279
-	/**
279
+    /**
280 280
      * Sends a payment reminder to a customer.
281
-	 * 
282
-	 * @param array $args
281
+     * 
282
+     * @param array $args
283 283
      */
284 284
     public function send_customer_invoice( $args ) {
285
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
285
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
286 286
 
287
-		if ( $sent ) {
288
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
289
-		} else {
290
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
291
-		}
287
+        if ( $sent ) {
288
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
289
+        } else {
290
+            $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
291
+        }
292 292
 
293
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
294
-		exit;
295
-	}
293
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
294
+        exit;
295
+    }
296 296
 
297
-	/**
297
+    /**
298 298
      * Sends a payment reminder to a customer.
299
-	 * 
300
-	 * @param array $args
299
+     * 
300
+     * @param array $args
301 301
      */
302 302
     public function send_customer_payment_reminder( $args ) {
303
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
303
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
304 304
 
305
-		if ( $sent ) {
306
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
307
-		} else {
308
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
309
-		}
305
+        if ( $sent ) {
306
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
307
+        } else {
308
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
309
+        }
310 310
 
311
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
312
-		exit;
313
-	}
311
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
312
+        exit;
313
+    }
314 314
 
315 315
     /**
316
-	 * Returns an array of admin notices.
317
-	 *
318
-	 * @since       1.0.19
316
+     * Returns an array of admin notices.
317
+     *
318
+     * @since       1.0.19
319 319
      * @return array
320
-	 */
321
-	public function get_notices() {
322
-		$notices = get_option( 'wpinv_admin_notices' );
320
+     */
321
+    public function get_notices() {
322
+        $notices = get_option( 'wpinv_admin_notices' );
323 323
         return is_array( $notices ) ? $notices : array();
324
-	}
325
-
326
-	/**
327
-	 * Clears all admin notices
328
-	 *
329
-	 * @access      public
330
-	 * @since       1.0.19
331
-	 */
332
-	public function clear_notices() {
333
-		delete_option( 'wpinv_admin_notices' );
334
-	}
335
-
336
-	/**
337
-	 * Saves a new admin notice
338
-	 *
339
-	 * @access      public
340
-	 * @since       1.0.19
341
-	 */
342
-	public function save_notice( $type, $message ) {
343
-		$notices = $this->get_notices();
344
-
345
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
346
-			$notices[ $type ] = array();
347
-		}
348
-
349
-		$notices[ $type ][] = $message;
350
-
351
-		update_option( 'wpinv_admin_notices', $notices );
352
-	}
353
-
354
-	/**
355
-	 * Displays a success notice
356
-	 *
357
-	 * @param       string $msg The message to qeue.
358
-	 * @access      public
359
-	 * @since       1.0.19
360
-	 */
361
-	public function show_success( $msg ) {
362
-		$this->save_notice( 'success', $msg );
363
-	}
364
-
365
-	/**
366
-	 * Displays a error notice
367
-	 *
368
-	 * @access      public
369
-	 * @param       string $msg The message to qeue.
370
-	 * @since       1.0.19
371
-	 */
372
-	public function show_error( $msg ) {
373
-		$this->save_notice( 'error', $msg );
374
-	}
375
-
376
-	/**
377
-	 * Displays a warning notice
378
-	 *
379
-	 * @access      public
380
-	 * @param       string $msg The message to qeue.
381
-	 * @since       1.0.19
382
-	 */
383
-	public function show_warning( $msg ) {
384
-		$this->save_notice( 'warning', $msg );
385
-	}
386
-
387
-	/**
388
-	 * Displays a info notice
389
-	 *
390
-	 * @access      public
391
-	 * @param       string $msg The message to qeue.
392
-	 * @since       1.0.19
393
-	 */
394
-	public function show_info( $msg ) {
395
-		$this->save_notice( 'info', $msg );
396
-	}
397
-
398
-	/**
399
-	 * Show notices
400
-	 *
401
-	 * @access      public
402
-	 * @since       1.0.19
403
-	 */
404
-	public function show_notices() {
324
+    }
325
+
326
+    /**
327
+     * Clears all admin notices
328
+     *
329
+     * @access      public
330
+     * @since       1.0.19
331
+     */
332
+    public function clear_notices() {
333
+        delete_option( 'wpinv_admin_notices' );
334
+    }
335
+
336
+    /**
337
+     * Saves a new admin notice
338
+     *
339
+     * @access      public
340
+     * @since       1.0.19
341
+     */
342
+    public function save_notice( $type, $message ) {
343
+        $notices = $this->get_notices();
344
+
345
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
346
+            $notices[ $type ] = array();
347
+        }
348
+
349
+        $notices[ $type ][] = $message;
350
+
351
+        update_option( 'wpinv_admin_notices', $notices );
352
+    }
353
+
354
+    /**
355
+     * Displays a success notice
356
+     *
357
+     * @param       string $msg The message to qeue.
358
+     * @access      public
359
+     * @since       1.0.19
360
+     */
361
+    public function show_success( $msg ) {
362
+        $this->save_notice( 'success', $msg );
363
+    }
364
+
365
+    /**
366
+     * Displays a error notice
367
+     *
368
+     * @access      public
369
+     * @param       string $msg The message to qeue.
370
+     * @since       1.0.19
371
+     */
372
+    public function show_error( $msg ) {
373
+        $this->save_notice( 'error', $msg );
374
+    }
375
+
376
+    /**
377
+     * Displays a warning notice
378
+     *
379
+     * @access      public
380
+     * @param       string $msg The message to qeue.
381
+     * @since       1.0.19
382
+     */
383
+    public function show_warning( $msg ) {
384
+        $this->save_notice( 'warning', $msg );
385
+    }
386
+
387
+    /**
388
+     * Displays a info notice
389
+     *
390
+     * @access      public
391
+     * @param       string $msg The message to qeue.
392
+     * @since       1.0.19
393
+     */
394
+    public function show_info( $msg ) {
395
+        $this->save_notice( 'info', $msg );
396
+    }
397
+
398
+    /**
399
+     * Show notices
400
+     *
401
+     * @access      public
402
+     * @since       1.0.19
403
+     */
404
+    public function show_notices() {
405 405
 
406 406
         $notices = $this->get_notices();
407 407
         $this->clear_notices();
408 408
 
409
-		foreach ( $notices as $type => $messages ) {
409
+        foreach ( $notices as $type => $messages ) {
410 410
 
411
-			if ( ! is_array( $messages ) ) {
412
-				continue;
413
-			}
411
+            if ( ! is_array( $messages ) ) {
412
+                continue;
413
+            }
414 414
 
415 415
             $type  = sanitize_key( $type );
416
-			foreach ( $messages as $message ) {
416
+            foreach ( $messages as $message ) {
417 417
                 $message = wp_kses_post( $message );
418
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
418
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
419 419
             }
420 420
 
421 421
         }
422 422
 
423
-	}
423
+    }
424 424
 
425 425
 }
Please login to merge, or discard this patch.
Spacing   +124 added lines, -124 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.
@@ -30,12 +30,12 @@  discard block
 block discarded – undo
30 30
     /**
31 31
 	 * Class constructor.
32 32
 	 */
33
-	public function __construct(){
33
+	public function __construct() {
34 34
 
35
-        $this->admin_path  = plugin_dir_path( __FILE__ );
36
-        $this->admin_url   = plugins_url( '/', __FILE__ );
35
+        $this->admin_path  = plugin_dir_path(__FILE__);
36
+        $this->admin_url   = plugins_url('/', __FILE__);
37 37
 
38
-        if ( is_admin() ) {
38
+        if (is_admin()) {
39 39
 			$this->init_admin_hooks();
40 40
         }
41 41
 
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 */
48 48
 	private function init_admin_hooks() {
49
-        add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
50
-        add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
51
-        add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
52
-        add_action( 'admin_init', array( $this, 'activation_redirect') );
53
-        add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
54
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
55
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
56
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
57
-		do_action( 'getpaid_init_admin_hooks', $this );
49
+        add_action('admin_enqueue_scripts', array($this, 'enqeue_scripts'));
50
+        add_filter('admin_body_class', array($this, 'admin_body_class'));
51
+        add_action('admin_init', array($this, 'init_ayecode_connect_helper'));
52
+        add_action('admin_init', array($this, 'activation_redirect'));
53
+        add_action('admin_init', array($this, 'maybe_do_admin_action'));
54
+		add_action('admin_notices', array($this, 'show_notices'));
55
+		add_action('getpaid_authenticated_admin_action_send_invoice', array($this, 'send_customer_invoice'));
56
+		add_action('getpaid_authenticated_admin_action_send_invoice_reminder', array($this, 'send_customer_payment_reminder'));
57
+		do_action('getpaid_init_admin_hooks', $this);
58 58
 
59 59
     }
60 60
 
@@ -65,48 +65,48 @@  discard block
 block discarded – undo
65 65
 	public function enqeue_scripts() {
66 66
         global $current_screen;
67 67
 
68
-        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
68
+        $page = isset($_GET['page']) ? $_GET['page'] : '';
69 69
 
70
-        if ( ! empty( $current_screen->post_type ) ) {
70
+        if (!empty($current_screen->post_type)) {
71 71
 			$page = $current_screen->post_type;
72 72
         }
73 73
 
74 74
         // General styles.
75
-        if ( false!== stripos( $page, 'wpi' ) ) {
75
+        if (false !== stripos($page, 'wpi')) {
76 76
 
77 77
             // Styles.
78
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
79
-            wp_enqueue_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array( 'wp-color-picker' ), $version );
80
-            wp_enqueue_style( 'select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all' );
81
-            wp_enqueue_style( 'wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
82
-            wp_enqueue_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16' );
78
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
79
+            wp_enqueue_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array('wp-color-picker'), $version);
80
+            wp_enqueue_style('select2', WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), '4.0.13', 'all');
81
+            wp_enqueue_style('wp_enqueue_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
82
+            wp_enqueue_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui.min.css', array(), '1.8.16');
83 83
 
84 84
             // Scripts.
85
-            wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '4.0.13', true );
86
-            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array( 'jquery' ), WPINV_VERSION );
85
+            wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '4.0.13', true);
86
+            wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full.min.js', array('jquery'), WPINV_VERSION);
87 87
 
88
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
89
-            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 );
90
-            wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', apply_filters( 'wpinv_admin_js_localize', $this->get_admin_i18() ) );
88
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
89
+            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);
90
+            wp_localize_script('wpinv-admin-script', 'WPInv_Admin', apply_filters('wpinv_admin_js_localize', $this->get_admin_i18()));
91 91
 
92 92
         }
93 93
 
94 94
         // Payment form scripts.
95
-		if ( 'wpi_payment_form' == $page ) {
95
+		if ('wpi_payment_form' == $page) {
96 96
             $this->load_payment_form_scripts();
97 97
         }
98 98
 
99
-        if ( $page == 'wpinv-subscriptions' ) {
100
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
101
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
99
+        if ($page == 'wpinv-subscriptions') {
100
+			wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
101
+			wp_enqueue_script('wpinv-sub-admin-script');
102 102
 		}
103 103
 
104
-		if ( $page == 'wpinv-reports' ) {
105
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
104
+		if ($page == 'wpinv-reports') {
105
+			wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7');
106 106
 		}
107 107
 
108
-		if ( $page == 'wpinv-subscriptions' ) {
109
-			wp_enqueue_script( 'postbox' );
108
+		if ($page == 'wpinv-subscriptions') {
109
+			wp_enqueue_script('postbox');
110 110
 		}
111 111
 
112 112
     }
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
         global $post;
120 120
 
121 121
         return array(
122
-            'ajax_url'                  => admin_url( 'admin-ajax.php' ),
123
-            'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
124
-            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
125
-            'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
126
-            'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
127
-            'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
128
-            'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
122
+            'ajax_url'                  => admin_url('admin-ajax.php'),
123
+            'post_ID'                   => isset($post->ID) ? $post->ID : '',
124
+            'wpinv_nonce'               => wp_create_nonce('wpinv-nonce'),
125
+            'add_invoice_note_nonce'    => wp_create_nonce('add-invoice-note'),
126
+            'delete_invoice_note_nonce' => wp_create_nonce('delete-invoice-note'),
127
+            'invoice_item_nonce'        => wp_create_nonce('invoice-item'),
128
+            'billing_details_nonce'     => wp_create_nonce('get-billing-details'),
129 129
             'tax'                       => wpinv_tax_amount(),
130 130
             'discount'                  => wpinv_discount_amount(),
131 131
             'currency_symbol'           => wpinv_currency_symbol(),
@@ -133,24 +133,24 @@  discard block
 block discarded – undo
133 133
             'thousand_sep'              => wpinv_thousands_separator(),
134 134
             'decimal_sep'               => wpinv_decimal_separator(),
135 135
             'decimals'                  => wpinv_decimals(),
136
-            'save_invoice'              => __( 'Save Invoice', 'invoicing' ),
137
-            'status_publish'            => wpinv_status_nicename( 'publish' ),
138
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
139
-            'delete_tax_rate'           => __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ),
140
-            'status_pending'            => wpinv_status_nicename( 'wpi-pending' ),
141
-            'OneItemMin'                => __( 'Invoice must contain at least one item', 'invoicing' ),
142
-            'FillBillingDetails'        => __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ),
143
-            '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' ),
144
-            'AreYouSure'                => __( 'Are you sure?', 'invoicing' ),
145
-            'emptyInvoice'              => __( 'Add at least one item to save invoice!', 'invoicing' ),
146
-            'errDeleteItem'             => __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ),
147
-            'delete_subscription'       => __( 'Are you sure you want to delete this subscription?', 'invoicing' ),
148
-            'action_edit'               => __( 'Edit', 'invoicing' ),
149
-            'action_cancel'             => __( 'Cancel', 'invoicing' ),
150
-            'item_description'          => __( 'Item Description', 'invoicing' ),
151
-            'invoice_description'       => __( 'Invoice Description', 'invoicing' ),
152
-            'discount_description'      => __( 'Discount Description', 'invoicing' ),
153
-            'searching'                 => __( 'Searching', 'invoicing' ),
136
+            'save_invoice'              => __('Save Invoice', 'invoicing'),
137
+            'status_publish'            => wpinv_status_nicename('publish'),
138
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
139
+            'delete_tax_rate'           => __('Are you sure you wish to delete this tax rate?', 'invoicing'),
140
+            'status_pending'            => wpinv_status_nicename('wpi-pending'),
141
+            'OneItemMin'                => __('Invoice must contain at least one item', 'invoicing'),
142
+            'FillBillingDetails'        => __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'),
143
+            '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'),
144
+            'AreYouSure'                => __('Are you sure?', 'invoicing'),
145
+            'emptyInvoice'              => __('Add at least one item to save invoice!', 'invoicing'),
146
+            'errDeleteItem'             => __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'),
147
+            'delete_subscription'       => __('Are you sure you want to delete this subscription?', 'invoicing'),
148
+            'action_edit'               => __('Edit', 'invoicing'),
149
+            'action_cancel'             => __('Cancel', 'invoicing'),
150
+            'item_description'          => __('Item Description', 'invoicing'),
151
+            'invoice_description'       => __('Invoice Description', 'invoicing'),
152
+            'discount_description'      => __('Discount Description', 'invoicing'),
153
+            'searching'                 => __('Searching', 'invoicing'),
154 154
         );
155 155
 
156 156
     }
@@ -162,31 +162,31 @@  discard block
 block discarded – undo
162 162
 	protected function load_payment_form_scripts() {
163 163
         global $post;
164 164
 
165
-        wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
166
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
167
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
165
+        wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
166
+		wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
167
+		wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
168 168
 
169
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
170
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
169
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
170
+		wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
171 171
 
172 172
 		wp_localize_script(
173 173
             'wpinv-admin-payment-form-script',
174 174
             'wpinvPaymentFormAdmin',
175 175
             array(
176 176
 				'elements'      => $this->form_elements->get_elements(),
177
-				'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
177
+				'form_elements' => $this->form_elements->get_form_elements($post->ID),
178 178
 				'all_items'     => $this->form_elements->get_published_items(),
179 179
 				'currency'      => wpinv_currency_symbol(),
180 180
 				'position'      => wpinv_currency_position(),
181 181
 				'decimals'      => (int) wpinv_decimals(),
182 182
 				'thousands_sep' => wpinv_thousands_separator(),
183 183
 				'decimals_sep'  => wpinv_decimal_separator(),
184
-				'form_items'    => $this->form_elements->get_form_items( $post->ID ),
184
+				'form_items'    => $this->form_elements->get_form_items($post->ID),
185 185
 				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
186 186
             )
187 187
         );
188 188
 
189
-        wp_enqueue_script( 'wpinv-admin-payment-form-script' );
189
+        wp_enqueue_script('wpinv-admin-payment-form-script');
190 190
 
191 191
     }
192 192
 
@@ -197,25 +197,25 @@  discard block
 block discarded – undo
197 197
      * @return string
198 198
 	 *
199 199
 	 */
200
-    public function admin_body_class( $classes ) {
200
+    public function admin_body_class($classes) {
201 201
 		global $pagenow, $post, $current_screen;
202 202
 
203 203
 
204
-        $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
204
+        $page = isset($_GET['page']) ? $_GET['page'] : '';
205 205
 
206
-        if ( ! empty( $current_screen->post_type ) ) {
206
+        if (!empty($current_screen->post_type)) {
207 207
 			$page = $current_screen->post_type;
208 208
         }
209 209
 
210
-        if ( false !== stripos( $page, 'wpi' ) ) {
211
-            $classes .= ' wpi-' . sanitize_key( $page );
210
+        if (false !== stripos($page, 'wpi')) {
211
+            $classes .= ' wpi-' . sanitize_key($page);
212 212
         }
213 213
 
214
-        if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
214
+        if (in_array($page, wpinv_parse_list('wpi_invoice wpi_payment_form wpi_quote'))) {
215 215
             $classes .= ' wpinv-cpt wpinv';
216 216
         }
217 217
 
218
-		if ( $pagenow == 'post.php' && $page == 'wpi_item' && ! empty( $post ) && ! wpinv_item_is_editable( $post ) ) {
218
+		if ($pagenow == 'post.php' && $page == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
219 219
 			$classes .= ' wpi-editable-n';
220 220
 		}
221 221
 
@@ -225,19 +225,19 @@  discard block
 block discarded – undo
225 225
     /**
226 226
 	 * Maybe show the AyeCode Connect Notice.
227 227
 	 */
228
-	public function init_ayecode_connect_helper(){
228
+	public function init_ayecode_connect_helper() {
229 229
 
230 230
         new AyeCode_Connect_Helper(
231 231
             array(
232
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
233
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
234
-				'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>" ),
235
-				'connect_button'    => __("Connect Site","invoicing"),
236
-				'connecting_button'    => __("Connecting...","invoicing"),
237
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
238
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
232
+				'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
233
+				'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
234
+				'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>"),
235
+				'connect_button'    => __("Connect Site", "invoicing"),
236
+				'connecting_button'    => __("Connecting...", "invoicing"),
237
+				'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
238
+				'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
239 239
             ),
240
-            array( 'wpi-addons' )
240
+            array('wpi-addons')
241 241
         );
242 242
 
243 243
     }
@@ -248,19 +248,19 @@  discard block
 block discarded – undo
248 248
     public function activation_redirect() {
249 249
 
250 250
 		// Bail if no activation redirect.
251
-		if ( ! get_transient( '_wpinv_activation_redirect' ) || is_ajax() ) {
251
+		if (!get_transient('_wpinv_activation_redirect') || is_ajax()) {
252 252
 			return;
253 253
 		}
254 254
 
255 255
 		// Delete the redirect transient.
256
-		delete_transient( '_wpinv_activation_redirect' );
256
+		delete_transient('_wpinv_activation_redirect');
257 257
 
258 258
 		// Bail if activating from network, or bulk
259
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
259
+		if (is_network_admin() || isset($_GET['activate-multi'])) {
260 260
 			return;
261 261
 		}
262 262
 
263
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
263
+		wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
264 264
 		exit;
265 265
     }
266 266
 
@@ -269,9 +269,9 @@  discard block
 block discarded – undo
269 269
      */
270 270
     public function maybe_do_admin_action() {
271 271
 
272
-        if ( wpinv_current_user_can_manage_invoicing() && isset( $_REQUEST['getpaid-admin-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
273
-            $key = sanitize_key( $_REQUEST['getpaid-admin-action'] );
274
-            do_action( "getpaid_authenticated_admin_action_$key", $_REQUEST );
272
+        if (wpinv_current_user_can_manage_invoicing() && isset($_REQUEST['getpaid-admin-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
273
+            $key = sanitize_key($_REQUEST['getpaid-admin-action']);
274
+            do_action("getpaid_authenticated_admin_action_$key", $_REQUEST);
275 275
         }
276 276
 
277 277
     }
@@ -281,16 +281,16 @@  discard block
 block discarded – undo
281 281
 	 * 
282 282
 	 * @param array $args
283 283
      */
284
-    public function send_customer_invoice( $args ) {
285
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
284
+    public function send_customer_invoice($args) {
285
+		$sent = getpaid()->get('invoice_emails')->user_invoice(new WPInv_Invoice($args['invoice_id']));
286 286
 
287
-		if ( $sent ) {
288
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
287
+		if ($sent) {
288
+			$this->show_success(__('Invoice was successfully sent to the customer', 'invoicing'));
289 289
 		} else {
290
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
290
+			$this->show_error(__('Could not sent the invoice to the customer', 'invoicing'));
291 291
 		}
292 292
 
293
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
293
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
294 294
 		exit;
295 295
 	}
296 296
 
@@ -299,16 +299,16 @@  discard block
 block discarded – undo
299 299
 	 * 
300 300
 	 * @param array $args
301 301
      */
302
-    public function send_customer_payment_reminder( $args ) {
303
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
302
+    public function send_customer_payment_reminder($args) {
303
+		$sent = getpaid()->get('invoice_emails')->force_send_overdue_notice(new WPInv_Invoice($args['invoice_id']));
304 304
 
305
-		if ( $sent ) {
306
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
305
+		if ($sent) {
306
+			$this->show_success(__('Payment reminder was successfully sent to the customer', 'invoicing'));
307 307
 		} else {
308
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
308
+			$this->show_error(__('Could not sent payment reminder to the customer', 'invoicing'));
309 309
 		}
310 310
 
311
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
311
+		wp_safe_redirect(remove_query_arg(array('getpaid-admin-action', 'getpaid-nonce', 'invoice_id')));
312 312
 		exit;
313 313
 	}
314 314
 
@@ -319,8 +319,8 @@  discard block
 block discarded – undo
319 319
      * @return array
320 320
 	 */
321 321
 	public function get_notices() {
322
-		$notices = get_option( 'wpinv_admin_notices' );
323
-        return is_array( $notices ) ? $notices : array();
322
+		$notices = get_option('wpinv_admin_notices');
323
+        return is_array($notices) ? $notices : array();
324 324
 	}
325 325
 
326 326
 	/**
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
 	 * @since       1.0.19
331 331
 	 */
332 332
 	public function clear_notices() {
333
-		delete_option( 'wpinv_admin_notices' );
333
+		delete_option('wpinv_admin_notices');
334 334
 	}
335 335
 
336 336
 	/**
@@ -339,16 +339,16 @@  discard block
 block discarded – undo
339 339
 	 * @access      public
340 340
 	 * @since       1.0.19
341 341
 	 */
342
-	public function save_notice( $type, $message ) {
342
+	public function save_notice($type, $message) {
343 343
 		$notices = $this->get_notices();
344 344
 
345
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
346
-			$notices[ $type ] = array();
345
+		if (empty($notices[$type]) || !is_array($notices[$type])) {
346
+			$notices[$type] = array();
347 347
 		}
348 348
 
349
-		$notices[ $type ][] = $message;
349
+		$notices[$type][] = $message;
350 350
 
351
-		update_option( 'wpinv_admin_notices', $notices );
351
+		update_option('wpinv_admin_notices', $notices);
352 352
 	}
353 353
 
354 354
 	/**
@@ -358,8 +358,8 @@  discard block
 block discarded – undo
358 358
 	 * @access      public
359 359
 	 * @since       1.0.19
360 360
 	 */
361
-	public function show_success( $msg ) {
362
-		$this->save_notice( 'success', $msg );
361
+	public function show_success($msg) {
362
+		$this->save_notice('success', $msg);
363 363
 	}
364 364
 
365 365
 	/**
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
 	 * @param       string $msg The message to qeue.
370 370
 	 * @since       1.0.19
371 371
 	 */
372
-	public function show_error( $msg ) {
373
-		$this->save_notice( 'error', $msg );
372
+	public function show_error($msg) {
373
+		$this->save_notice('error', $msg);
374 374
 	}
375 375
 
376 376
 	/**
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
 	 * @param       string $msg The message to qeue.
381 381
 	 * @since       1.0.19
382 382
 	 */
383
-	public function show_warning( $msg ) {
384
-		$this->save_notice( 'warning', $msg );
383
+	public function show_warning($msg) {
384
+		$this->save_notice('warning', $msg);
385 385
 	}
386 386
 
387 387
 	/**
@@ -391,8 +391,8 @@  discard block
 block discarded – undo
391 391
 	 * @param       string $msg The message to qeue.
392 392
 	 * @since       1.0.19
393 393
 	 */
394
-	public function show_info( $msg ) {
395
-		$this->save_notice( 'info', $msg );
394
+	public function show_info($msg) {
395
+		$this->save_notice('info', $msg);
396 396
 	}
397 397
 
398 398
 	/**
@@ -406,15 +406,15 @@  discard block
 block discarded – undo
406 406
         $notices = $this->get_notices();
407 407
         $this->clear_notices();
408 408
 
409
-		foreach ( $notices as $type => $messages ) {
409
+		foreach ($notices as $type => $messages) {
410 410
 
411
-			if ( ! is_array( $messages ) ) {
411
+			if (!is_array($messages)) {
412 412
 				continue;
413 413
 			}
414 414
 
415
-            $type  = sanitize_key( $type );
416
-			foreach ( $messages as $message ) {
417
-                $message = wp_kses_post( $message );
415
+            $type = sanitize_key($type);
416
+			foreach ($messages as $message) {
417
+                $message = wp_kses_post($message);
418 418
 				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
419 419
             }
420 420
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-resend-invoice.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if (!defined('ABSPATH')) {
9 9
 	exit; // Exit if accessed directly
10 10
 }
11 11
 
@@ -19,12 +19,12 @@  discard block
 block discarded – undo
19 19
 	 *
20 20
 	 * @param WP_Post $post
21 21
 	 */
22
-    public static function output( $post ) {
22
+    public static function output($post) {
23 23
 
24 24
         // Fetch the invoice.
25
-        $invoice = new WPInv_Invoice( $post );
25
+        $invoice = new WPInv_Invoice($post);
26 26
 
27
-        do_action( 'wpinv_metabox_resend_invoice_before', $invoice );
27
+        do_action('wpinv_metabox_resend_invoice_before', $invoice);
28 28
 
29 29
         $email_url = esc_url(
30 30
             add_query_arg(
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
         );
51 51
 
52 52
         ?>
53
-            <p class="wpi-meta-row wpi-resend-info"><?php _e( "This will send a copy of the invoice to the customer's email address.", 'invoicing' ); ?></p>
54
-            <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo $email_url; ?>" class="button button-secondary"><?php _e( 'Resend Invoice', 'invoicing' ); ?></a></p>
55
-            <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo $reminder_url; ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p>
53
+            <p class="wpi-meta-row wpi-resend-info"><?php _e("This will send a copy of the invoice to the customer's email address.", 'invoicing'); ?></p>
54
+            <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo $email_url; ?>" class="button button-secondary"><?php _e('Resend Invoice', 'invoicing'); ?></a></p>
55
+            <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo $reminder_url; ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p>
56 56
         <?php
57 57
 
58
-        do_action( 'wpinv_metabox_resend_invoice_after', $invoice );
58
+        do_action('wpinv_metabox_resend_invoice_after', $invoice);
59 59
 
60 60
     }
61 61
 
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 2 patches
Indentation   +613 added lines, -613 removed lines patch added patch discarded remove patch
@@ -13,614 +13,614 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-
29
-		// Invoice table columns.
30
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
32
-
33
-		// Items table columns.
34
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
40
-
41
-		// Payment forms columns.
42
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
45
-
46
-		// Discount table columns.
47
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
48
-
49
-		// Deleting posts.
50
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
-	}
53
-
54
-	/**
55
-	 * Post updated messages.
56
-	 */
57
-	public static function post_updated_messages( $messages ) {
58
-		global $post;
59
-
60
-		$messages['wpi_discount'] = array(
61
-			0   => '',
62
-			1   => __( 'Discount updated.', 'invoicing' ),
63
-			2   => __( 'Custom field updated.', 'invoicing' ),
64
-			3   => __( 'Custom field deleted.', 'invoicing' ),
65
-			4   => __( 'Discount updated.', 'invoicing' ),
66
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
-			6   => __( 'Discount updated.', 'invoicing' ),
68
-			7   => __( 'Discount saved.', 'invoicing' ),
69
-			8   => __( 'Discount submitted.', 'invoicing' ),
70
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
-			10  => __( 'Discount draft updated.', 'invoicing' ),
72
-		);
73
-
74
-		$messages['wpi_payment_form'] = array(
75
-			0   => '',
76
-			1   => __( 'Payment Form updated.', 'invoicing' ),
77
-			2   => __( 'Custom field updated.', 'invoicing' ),
78
-			3   => __( 'Custom field deleted.', 'invoicing' ),
79
-			4   => __( 'Payment Form updated.', 'invoicing' ),
80
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
-			6   => __( 'Payment Form updated.', 'invoicing' ),
82
-			7   => __( 'Payment Form saved.', 'invoicing' ),
83
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
84
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
86
-		);
87
-
88
-		return $messages;
89
-
90
-	}
91
-
92
-	/**
93
-	 * Post row actions.
94
-	 */
95
-	public static function post_row_actions( $actions, $post ) {
96
-
97
-		$post = get_post( $post );
98
-
99
-		// We do not want to edit the default payment form.
100
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
-			unset( $actions['trash'] );
102
-			unset( $actions['inline hide-if-no-js'] );
103
-		}
104
-
105
-		return $actions;
106
-	}
107
-
108
-	/**
109
-	 * Returns an array of invoice table columns.
110
-	 */
111
-	public static function invoice_columns( $columns ) {
112
-
113
-		$columns = array(
114
-			'cb'                => $columns['cb'],
115
-			'number'            => __( 'Invoice', 'invoicing' ),
116
-			'customer'          => __( 'Customer', 'invoicing' ),
117
-			'invoice_date'      => __( 'Date', 'invoicing' ),
118
-			'amount'            => __( 'Amount', 'invoicing' ),
119
-			'recurring'         => __( 'Recurring', 'invoicing' ),
120
-			'status'            => __( 'Status', 'invoicing' ),
121
-			'wpi_actions'       => __( 'Actions', 'invoicing' ),
122
-		);
123
-
124
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
125
-	}
126
-
127
-	/**
128
-	 * Displays invoice table columns.
129
-	 */
130
-	public static function display_invoice_columns( $column_name, $post_id ) {
131
-
132
-		$invoice = new WPInv_Invoice( $post_id );
133
-
134
-		switch ( $column_name ) {
135
-
136
-			case 'invoice_date' :
137
-				$date_time = sanitize_text_field( $invoice->get_created_date() );
138
-				$date      = mysql2date( get_option( 'date_format' ), $date_time );
139
-				echo "<span title='$date_time'>$date</span>";
140
-				break;
141
-
142
-			case 'amount' :
143
-
144
-				$amount = $invoice->get_total();
145
-				$formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
146
-
147
-				if ( $invoice->is_refunded() ) {
148
-					$refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
149
-					echo "<del>$formated_amount</del><ins>$refunded_amount</ins>";
150
-				} else {
151
-
152
-					$discount = $invoice->get_total_discount();
153
-
154
-					if ( ! empty( $discount ) ) {
155
-						$new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
156
-						echo "<del>$new_amount</del><ins>$formated_amount</ins>";
157
-					} else {
158
-						echo $formated_amount;
159
-					}
160
-
161
-				}
162
-
163
-				break;
164
-
165
-			case 'status' :
166
-				$status       = sanitize_text_field( $invoice->get_status() );
167
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
168
-
169
-				// If it is paid, show the gateway title.
170
-				if ( $invoice->is_paid() ) {
171
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
173 19
 
174
-					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175
-				} else {
176
-					echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
177
-				}
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
178 22
 
179
-				// If it is not paid, display the overdue and view status.
180
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
181 25
 
182
-					// Invoice view status.
183
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
185
-					} else {
186
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
187
-					}
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
188 28
 
189
-					// Display the overview status.
190
-					if ( wpinv_get_option( 'overdue_active' ) ) {
191
-						$due_date = $invoice->get_due_date();
29
+        // Invoice table columns.
30
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
192 32
 
193
-						if ( ! empty( $due_date ) ) {
194
-							$date = mysql2date( get_option( 'date_format' ), $due_date );
195
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $date );
196
-							echo "<p class='description' style='color: #888;' title='$due_date'>$date</p>";
197
-						}
198
-					}
33
+        // Items table columns.
34
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
199 40
 
200
-				}
41
+        // Payment forms columns.
42
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
201 45
 
202
-				break;
46
+        // Discount table columns.
47
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
203 48
 
204
-			case 'recurring':
49
+        // Deleting posts.
50
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
+    }
205 53
 
206
-				if ( $invoice->is_recurring() ) {
207
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208
-				} else {
209
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
210
-				}
211
-				break;
54
+    /**
55
+     * Post updated messages.
56
+     */
57
+    public static function post_updated_messages( $messages ) {
58
+        global $post;
59
+
60
+        $messages['wpi_discount'] = array(
61
+            0   => '',
62
+            1   => __( 'Discount updated.', 'invoicing' ),
63
+            2   => __( 'Custom field updated.', 'invoicing' ),
64
+            3   => __( 'Custom field deleted.', 'invoicing' ),
65
+            4   => __( 'Discount updated.', 'invoicing' ),
66
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
+            6   => __( 'Discount updated.', 'invoicing' ),
68
+            7   => __( 'Discount saved.', 'invoicing' ),
69
+            8   => __( 'Discount submitted.', 'invoicing' ),
70
+            9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
+            10  => __( 'Discount draft updated.', 'invoicing' ),
72
+        );
73
+
74
+        $messages['wpi_payment_form'] = array(
75
+            0   => '',
76
+            1   => __( 'Payment Form updated.', 'invoicing' ),
77
+            2   => __( 'Custom field updated.', 'invoicing' ),
78
+            3   => __( 'Custom field deleted.', 'invoicing' ),
79
+            4   => __( 'Payment Form updated.', 'invoicing' ),
80
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
+            6   => __( 'Payment Form updated.', 'invoicing' ),
82
+            7   => __( 'Payment Form saved.', 'invoicing' ),
83
+            8   => __( 'Payment Form submitted.', 'invoicing' ),
84
+            9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
+            10  => __( 'Payment Form draft updated.', 'invoicing' ),
86
+        );
87
+
88
+        return $messages;
89
+
90
+    }
91
+
92
+    /**
93
+     * Post row actions.
94
+     */
95
+    public static function post_row_actions( $actions, $post ) {
96
+
97
+        $post = get_post( $post );
98
+
99
+        // We do not want to edit the default payment form.
100
+        if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
+            unset( $actions['trash'] );
102
+            unset( $actions['inline hide-if-no-js'] );
103
+        }
104
+
105
+        return $actions;
106
+    }
107
+
108
+    /**
109
+     * Returns an array of invoice table columns.
110
+     */
111
+    public static function invoice_columns( $columns ) {
112
+
113
+        $columns = array(
114
+            'cb'                => $columns['cb'],
115
+            'number'            => __( 'Invoice', 'invoicing' ),
116
+            'customer'          => __( 'Customer', 'invoicing' ),
117
+            'invoice_date'      => __( 'Date', 'invoicing' ),
118
+            'amount'            => __( 'Amount', 'invoicing' ),
119
+            'recurring'         => __( 'Recurring', 'invoicing' ),
120
+            'status'            => __( 'Status', 'invoicing' ),
121
+            'wpi_actions'       => __( 'Actions', 'invoicing' ),
122
+        );
123
+
124
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
125
+    }
126
+
127
+    /**
128
+     * Displays invoice table columns.
129
+     */
130
+    public static function display_invoice_columns( $column_name, $post_id ) {
131
+
132
+        $invoice = new WPInv_Invoice( $post_id );
133
+
134
+        switch ( $column_name ) {
135
+
136
+            case 'invoice_date' :
137
+                $date_time = sanitize_text_field( $invoice->get_created_date() );
138
+                $date      = mysql2date( get_option( 'date_format' ), $date_time );
139
+                echo "<span title='$date_time'>$date</span>";
140
+                break;
141
+
142
+            case 'amount' :
143
+
144
+                $amount = $invoice->get_total();
145
+                $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
146
+
147
+                if ( $invoice->is_refunded() ) {
148
+                    $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
149
+                    echo "<del>$formated_amount</del><ins>$refunded_amount</ins>";
150
+                } else {
151
+
152
+                    $discount = $invoice->get_total_discount();
153
+
154
+                    if ( ! empty( $discount ) ) {
155
+                        $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
156
+                        echo "<del>$new_amount</del><ins>$formated_amount</ins>";
157
+                    } else {
158
+                        echo $formated_amount;
159
+                    }
160
+
161
+                }
162
+
163
+                break;
164
+
165
+            case 'status' :
166
+                $status       = sanitize_text_field( $invoice->get_status() );
167
+                $status_label = sanitize_text_field( $invoice->get_status_nicename() );
168
+
169
+                // If it is paid, show the gateway title.
170
+                if ( $invoice->is_paid() ) {
171
+                    $gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
212 173
 
213
-			case 'number' :
174
+                    echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175
+                } else {
176
+                    echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
177
+                }
214 178
 
215
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
217
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
179
+                // If it is not paid, display the overdue and view status.
180
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
218 181
 
219
-				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
182
+                    // Invoice view status.
183
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
185
+                    } else {
186
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
187
+                    }
220 188
 
221
-				break;
189
+                    // Display the overview status.
190
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
191
+                        $due_date = $invoice->get_due_date();
222 192
 
223
-			case 'customer' :
193
+                        if ( ! empty( $due_date ) ) {
194
+                            $date = mysql2date( get_option( 'date_format' ), $due_date );
195
+                            $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $date );
196
+                            echo "<p class='description' style='color: #888;' title='$due_date'>$date</p>";
197
+                        }
198
+                    }
199
+
200
+                }
201
+
202
+                break;
203
+
204
+            case 'recurring':
205
+
206
+                if ( $invoice->is_recurring() ) {
207
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208
+                } else {
209
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
210
+                }
211
+                break;
212
+
213
+            case 'number' :
214
+
215
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
+                $invoice_number  = sanitize_text_field( $invoice->get_number() );
217
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
218
+
219
+                echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
220
+
221
+                break;
222
+
223
+            case 'customer' :
224 224
 	
225
-				$customer_name = $invoice->get_user_full_name();
225
+                $customer_name = $invoice->get_user_full_name();
226 226
 	
227
-				if ( empty( $customer_name ) ) {
228
-					$customer_name = $invoice->get_email();
229
-				}
227
+                if ( empty( $customer_name ) ) {
228
+                    $customer_name = $invoice->get_email();
229
+                }
230 230
 	
231
-				if ( ! empty( $customer_name ) ) {
232
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
234
-					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235
-				} else {
236
-					echo '<div>&mdash;</div>';
237
-				}
231
+                if ( ! empty( $customer_name ) ) {
232
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
234
+                    echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235
+                } else {
236
+                    echo '<div>&mdash;</div>';
237
+                }
238
+
239
+                break;
240
+
241
+            case 'wpi_actions' :
242
+
243
+                if ( $invoice->is_draft() ) {
244
+                    return;
245
+                }
246
+
247
+                $url    = esc_url( $invoice->get_view_url() );
248
+                $print  = esc_attr__( 'Print invoice', 'invoicing' );
249
+                echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
250
+
251
+                $url    = esc_url(
252
+                    wp_nonce_url(
253
+                        add_query_arg(
254
+                            array(
255
+                                'getpaid-admin-action' => 'send_invoice',
256
+                                'invoice_id'           => $invoice->get_id()
257
+                            )
258
+                        ),
259
+                        'getpaid-nonce',
260
+                        'getpaid-nonce'
261
+                    )
262
+                );
263
+
264
+                $send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
265
+                echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
266
+
267
+                break;
268
+        }
238 269
 
239
-				break;
270
+    }
240 271
 
241
-			case 'wpi_actions' :
242
-
243
-				if ( $invoice->is_draft() ) {
244
-					return;
245
-				}
246
-
247
-				$url    = esc_url( $invoice->get_view_url() );
248
-				$print  = esc_attr__( 'Print invoice', 'invoicing' );
249
-				echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
272
+    /**
273
+     * Returns an array of payment forms table columns.
274
+     */
275
+    public static function payment_form_columns( $columns ) {
250 276
 
251
-				$url    = esc_url(
252
-					wp_nonce_url(
253
-						add_query_arg(
254
-							array(
255
-								'getpaid-admin-action' => 'send_invoice',
256
-								'invoice_id'           => $invoice->get_id()
257
-							)
258
-						),
259
-						'getpaid-nonce',
260
-						'getpaid-nonce'
261
-					)
262
-				);
277
+        $columns = array(
278
+            'cb'                => $columns['cb'],
279
+            'title'             => __( 'Name', 'invoicing' ),
280
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
+            'earnings'          => __( 'Revenue', 'invoicing' ),
282
+            'refunds'           => __( 'Refunded', 'invoicing' ),
283
+            'items'             => __( 'Items', 'invoicing' ),
284
+            'date'              => __( 'Date', 'invoicing' ),
285
+        );
263 286
 
264
-				$send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
265
-				echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
287
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
266 288
 
267
-				break;
268
-		}
289
+    }
269 290
 
270
-	}
291
+    /**
292
+     * Displays payment form table columns.
293
+     */
294
+    public static function display_payment_form_columns( $column_name, $post_id ) {
271 295
 
272
-	/**
273
-	 * Returns an array of payment forms table columns.
274
-	 */
275
-	public static function payment_form_columns( $columns ) {
296
+        // Retrieve the payment form.
297
+        $form = new GetPaid_Payment_Form( $post_id );
276 298
 
277
-		$columns = array(
278
-			'cb'                => $columns['cb'],
279
-			'title'             => __( 'Name', 'invoicing' ),
280
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
-			'earnings'          => __( 'Revenue', 'invoicing' ),
282
-			'refunds'           => __( 'Refunded', 'invoicing' ),
283
-			'items'             => __( 'Items', 'invoicing' ),
284
-			'date'              => __( 'Date', 'invoicing' ),
285
-		);
299
+        switch ( $column_name ) {
286 300
 
287
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
301
+            case 'earnings' :
302
+                echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
303
+                break;
288 304
 
289
-	}
305
+            case 'refunds' :
306
+                echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
307
+                break;
290 308
 
291
-	/**
292
-	 * Displays payment form table columns.
293
-	 */
294
-	public static function display_payment_form_columns( $column_name, $post_id ) {
309
+            case 'refunds' :
310
+                echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
311
+                break;
295 312
 
296
-		// Retrieve the payment form.
297
-		$form = new GetPaid_Payment_Form( $post_id );
313
+            case 'shortcode' :
298 314
 
299
-		switch ( $column_name ) {
315
+                if ( $form->is_default() ) {
316
+                    echo '&mdash;';
317
+                } else {
318
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
319
+                }
300 320
 
301
-			case 'earnings' :
302
-				echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
303
-				break;
321
+                break;
304 322
 
305
-			case 'refunds' :
306
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
307
-				break;
323
+            case 'items' :
308 324
 
309
-			case 'refunds' :
310
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
311
-				break;
325
+                $items = $form->get_items();
312 326
 
313
-			case 'shortcode' :
327
+                if ( $form->is_default() || empty( $items ) ) {
328
+                    echo '&mdash;';
329
+                    return;
330
+                }
314 331
 
315
-				if ( $form->is_default() ) {
316
-					echo '&mdash;';
317
-				} else {
318
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
319
-				}
332
+                $_items = array();
320 333
 
321
-				break;
334
+                foreach ( $items as $item ) {
335
+                    $url = $item->get_edit_url();
322 336
 
323
-			case 'items' :
337
+                    if ( empty( $url ) ) {
338
+                        $_items[] = sanitize_text_field( $item->get_name() );
339
+                    } else {
340
+                        $_items[] = sprintf(
341
+                            '<a href="%s">%s</a>',
342
+                            esc_url( $url ),
343
+                            sanitize_text_field( $item->get_name() )
344
+                        );
345
+                    }
324 346
 
325
-				$items = $form->get_items();
347
+                }
326 348
 
327
-				if ( $form->is_default() || empty( $items ) ) {
328
-					echo '&mdash;';
329
-					return;
330
-				}
349
+                echo implode( '<br>', $_items );
331 350
 
332
-				$_items = array();
351
+                break;
333 352
 
334
-				foreach ( $items as $item ) {
335
-					$url = $item->get_edit_url();
353
+        }
336 354
 
337
-					if ( empty( $url ) ) {
338
-						$_items[] = sanitize_text_field( $item->get_name() );
339
-					} else {
340
-						$_items[] = sprintf(
341
-							'<a href="%s">%s</a>',
342
-							esc_url( $url ),
343
-							sanitize_text_field( $item->get_name() )
344
-						);
345
-					}
355
+    }
346 356
 
347
-				}
357
+    /**
358
+     * Filters post states.
359
+     */
360
+    public static function filter_payment_form_state( $post_states, $post ) {
348 361
 
349
-				echo implode( '<br>', $_items );
362
+        if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
+            $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
364
+        }
365
+	
366
+        return $post_states;
350 367
 
351
-				break;
368
+    }
352 369
 
353
-		}
370
+    /**
371
+     * Returns an array of coupon table columns.
372
+     */
373
+    public static function discount_columns( $columns ) {
374
+
375
+        $columns = array(
376
+            'cb'                => $columns['cb'],
377
+            'title'             => __( 'Name', 'invoicing' ),
378
+            'code'              => __( 'Code', 'invoicing' ),
379
+            'amount'            => __( 'Amount', 'invoicing' ),
380
+            'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
+            'start_date'        => __( 'Start Date', 'invoicing' ),
382
+            'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
383
+        );
384
+
385
+        return apply_filters( 'wpi_discount_table_columns', $columns );
386
+    }
354 387
 
355
-	}
388
+    /**
389
+     * Filters post states.
390
+     */
391
+    public static function filter_discount_state( $post_states, $post ) {
356 392
 
357
-	/**
358
-	 * Filters post states.
359
-	 */
360
-	public static function filter_payment_form_state( $post_states, $post ) {
393
+        if ( 'wpi_discount' == $post->post_type ) {
361 394
 
362
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
364
-		}
365
-	
366
-		return $post_states;
395
+            $discount = new WPInv_Discount( $post );
367 396
 
368
-	}
397
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
369 398
 
370
-	/**
371
-	 * Returns an array of coupon table columns.
372
-	 */
373
-	public static function discount_columns( $columns ) {
399
+            if ( $status != 'publish' ) {
400
+                return array(
401
+                    'discount_status' => wpinv_discount_status( $status ),
402
+                );
403
+            }
374 404
 
375
-		$columns = array(
376
-			'cb'                => $columns['cb'],
377
-			'title'             => __( 'Name', 'invoicing' ),
378
-			'code'              => __( 'Code', 'invoicing' ),
379
-			'amount'            => __( 'Amount', 'invoicing' ),
380
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
-			'start_date'        => __( 'Start Date', 'invoicing' ),
382
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
383
-		);
405
+            return array();
384 406
 
385
-		return apply_filters( 'wpi_discount_table_columns', $columns );
386
-	}
407
+        }
387 408
 
388
-	/**
389
-	 * Filters post states.
390
-	 */
391
-	public static function filter_discount_state( $post_states, $post ) {
409
+        return $post_states;
392 410
 
393
-		if ( 'wpi_discount' == $post->post_type ) {
411
+    }
394 412
 
395
-			$discount = new WPInv_Discount( $post );
413
+    /**
414
+     * Returns an array of items table columns.
415
+     */
416
+    public static function item_columns( $columns ) {
417
+        global $wpinv_euvat;
418
+
419
+        $columns = array(
420
+            'cb'                => $columns['cb'],
421
+            'title'             => __( 'Name', 'invoicing' ),
422
+            'price'             => __( 'Price', 'invoicing' ),
423
+            'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
+            'vat_class'         => __( 'VAT class', 'invoicing' ),
425
+            'type'              => __( 'Type', 'invoicing' ),
426
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
427
+        );
428
+
429
+        if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
+            unset( $columns['vat_rule'] );
431
+        }
396 432
 
397
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
433
+        if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
+            unset( $columns['vat_class'] );
435
+        }
398 436
 
399
-			if ( $status != 'publish' ) {
400
-				return array(
401
-					'discount_status' => wpinv_discount_status( $status ),
402
-				);
403
-			}
437
+        return apply_filters( 'wpi_item_table_columns', $columns );
438
+    }
404 439
 
405
-			return array();
440
+    /**
441
+     * Returns an array of sortable items table columns.
442
+     */
443
+    public static function sortable_item_columns( $columns ) {
444
+
445
+        return array_merge(
446
+            $columns,
447
+            array(
448
+                'price'     => 'price',
449
+                'vat_rule'  => 'vat_rule',
450
+                'vat_class' => 'vat_class',
451
+                'type'      => 'type',
452
+            )
453
+        );
454
+
455
+    }
406 456
 
407
-		}
457
+    /**
458
+     * Displays items table columns.
459
+     */
460
+    public static function display_item_columns( $column_name, $post_id ) {
461
+        global $wpinv_euvat;
408 462
 
409
-		return $post_states;
463
+        $item = new WPInv_Item( $post_id );
410 464
 
411
-	}
465
+        switch ( $column_name ) {
412 466
 
413
-	/**
414
-	 * Returns an array of items table columns.
415
-	 */
416
-	public static function item_columns( $columns ) {
417
-		global $wpinv_euvat;
467
+            case 'price' :
418 468
 
419
-		$columns = array(
420
-			'cb'                => $columns['cb'],
421
-			'title'             => __( 'Name', 'invoicing' ),
422
-			'price'             => __( 'Price', 'invoicing' ),
423
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
425
-			'type'              => __( 'Type', 'invoicing' ),
426
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
427
-		);
469
+                if ( ! $item->is_recurring() ) {
470
+                    echo $item->get_the_price();
471
+                    break;
472
+                }
428 473
 
429
-		if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
-			unset( $columns['vat_rule'] );
431
-		}
474
+                $price = wp_sprintf(
475
+                    __( '%s / %s', 'invoicing' ),
476
+                    $item->get_the_price(),
477
+                    WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() )
478
+                );
432 479
 
433
-		if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
-			unset( $columns['vat_class'] );
435
-		}
480
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
481
+                    echo $price;
482
+                    break;
483
+                }
436 484
 
437
-		return apply_filters( 'wpi_item_table_columns', $columns );
438
-	}
485
+                echo $item->get_the_initial_price();
439 486
 
440
-	/**
441
-	 * Returns an array of sortable items table columns.
442
-	 */
443
-	public static function sortable_item_columns( $columns ) {
487
+                echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
488
+                break;
444 489
 
445
-		return array_merge(
446
-			$columns,
447
-			array(
448
-				'price'     => 'price',
449
-				'vat_rule'  => 'vat_rule',
450
-				'vat_class' => 'vat_class',
451
-				'type'      => 'type',
452
-			)
453
-		);
490
+            case 'vat_rule' :
491
+                echo $wpinv_euvat->item_rule_label( $item->get_id() );
492
+                break;
454 493
 
455
-	}
494
+            case 'vat_class' :
495
+                echo $wpinv_euvat->item_class_label( $item->get_id() );
496
+                break;
456 497
 
457
-	/**
458
-	 * Displays items table columns.
459
-	 */
460
-	public static function display_item_columns( $column_name, $post_id ) {
461
-		global $wpinv_euvat;
498
+            case 'shortcode' :
499
+                echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500
+                break;
462 501
 
463
-		$item = new WPInv_Item( $post_id );
502
+            case 'type' :
503
+                echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504
+                break;
464 505
 
465
-		switch ( $column_name ) {
506
+        }
466 507
 
467
-			case 'price' :
508
+    }
468 509
 
469
-				if ( ! $item->is_recurring() ) {
470
-					echo $item->get_the_price();
471
-					break;
472
-				}
510
+    /**
511
+     * Lets users filter items using taxes.
512
+     */
513
+    public static function add_item_filters( $post_type ) {
514
+        global $wpinv_euvat;
515
+
516
+        // Abort if we're not dealing with items.
517
+        if ( $post_type != 'wpi_item' ) {
518
+            return;
519
+        }
520
+
521
+        // Filter by vat rules.
522
+        if ( $wpinv_euvat->allow_vat_rules() ) {
523
+	
524
+            // Sanitize selected vat rule.
525
+            $vat_rule   = '';
526
+            if ( isset( $_GET['vat_rule'] ) && array_key_exists(  $_GET['vat_rule'], $wpinv_euvat->get_rules() ) ) {
527
+                $vat_rule   =  $_GET['vat_rule'];
528
+            }
529
+
530
+            // Filter by VAT rule.
531
+            echo wpinv_html_select(
532
+                array(
533
+                    'options'          => array_merge(
534
+                        array(
535
+                            '' => __( 'All VAT rules', 'invoicing' )
536
+                        ),
537
+                        $wpinv_euvat->get_rules()
538
+                    ),
539
+                    'name'             => 'vat_rule',
540
+                    'id'               => 'vat_rule',
541
+                    'selected'         => $vat_rule,
542
+                    'show_option_all'  => false,
543
+                    'show_option_none' => false,
544
+                    'class'            => 'gdmbx2-text-medium',
545
+                )
546
+            );
547
+
548
+            // Filter by VAT class.
549
+        }
473 550
 
474
-				$price = wp_sprintf(
475
-					__( '%s / %s', 'invoicing' ),
476
-					$item->get_the_price(),
477
-					WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() )
478
-				);
551
+        // Filter by vat class.
552
+        if ( $wpinv_euvat->allow_vat_classes() ) {
553
+	
554
+            // Sanitize selected vat rule.
555
+            $vat_class   = '';
556
+            if ( isset( $_GET['vat_class'] ) && array_key_exists(  $_GET['vat_class'], $wpinv_euvat->get_all_classes() ) ) {
557
+                $vat_class   =  $_GET['vat_class'];
558
+            }
559
+
560
+            echo wpinv_html_select(
561
+                array(
562
+                    'options'          => array_merge(
563
+                        array(
564
+                            '' => __( 'All VAT classes', 'invoicing' )
565
+                        ),
566
+                        $wpinv_euvat->get_all_classes()
567
+                    ),
568
+                    'name'             => 'vat_class',
569
+                    'id'               => 'vat_class',
570
+                    'selected'         => $vat_class,
571
+                    'show_option_all'  => false,
572
+                    'show_option_none' => false,
573
+                    'class'            => 'gdmbx2-text-medium',
574
+                )
575
+            );
479 576
 
480
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
481
-					echo $price;
482
-					break;
483
-				}
577
+        }
484 578
 
485
-				echo $item->get_the_initial_price();
579
+        // Filter by item type.
580
+        $type   = '';
581
+        if( isset( $_GET['type'] ) && array_key_exists(  $_GET['type'], wpinv_get_item_types() ) ) {
582
+            $type   =  $_GET['type'];
583
+        }
486 584
 
487
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
488
-				break;
585
+        echo wpinv_html_select(
586
+            array(
587
+                'options'          => array_merge(
588
+                    array(
589
+                        '' => __( 'All item types', 'invoicing' )
590
+                    ),
591
+                    wpinv_get_item_types()
592
+                ),
593
+                'name'             => 'type',
594
+                'id'               => 'type',
595
+                'selected'         => $type,
596
+                'show_option_all'  => false,
597
+                'show_option_none' => false,
598
+                'class'            => 'gdmbx2-text-medium',
599
+            )
600
+        );
601
+
602
+    }
489 603
 
490
-			case 'vat_rule' :
491
-				echo $wpinv_euvat->item_rule_label( $item->get_id() );
492
-				break;
604
+    /**
605
+     * Filters the item query.
606
+     */
607
+    public static function filter_item_query( $query ) {
493 608
 
494
-			case 'vat_class' :
495
-				echo $wpinv_euvat->item_class_label( $item->get_id() );
496
-				break;
609
+        // modify the query only if it admin and main query.
610
+        if ( ! ( is_admin() && $query->is_main_query() ) ){ 
611
+            return $query;
612
+        }
497 613
 
498
-			case 'shortcode' :
499
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500
-				break;
614
+        // we want to modify the query for our items.
615
+        if ( 'wpi_item' != $query->query['post_type'] ){
616
+            return $query;
617
+        }
501 618
 
502
-			case 'type' :
503
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504
-				break;
619
+        if ( empty( $query->query_vars['meta_query'] ) ) {
620
+            $query->query_vars['meta_query'] = array();
621
+        }
505 622
 
506
-		}
507
-
508
-	}
509
-
510
-	/**
511
-	 * Lets users filter items using taxes.
512
-	 */
513
-	public static function add_item_filters( $post_type ) {
514
-		global $wpinv_euvat;
515
-
516
-		// Abort if we're not dealing with items.
517
-		if ( $post_type != 'wpi_item' ) {
518
-			return;
519
-		}
520
-
521
-		// Filter by vat rules.
522
-		if ( $wpinv_euvat->allow_vat_rules() ) {
523
-	
524
-			// Sanitize selected vat rule.
525
-			$vat_rule   = '';
526
-			if ( isset( $_GET['vat_rule'] ) && array_key_exists(  $_GET['vat_rule'], $wpinv_euvat->get_rules() ) ) {
527
-				$vat_rule   =  $_GET['vat_rule'];
528
-			}
529
-
530
-			// Filter by VAT rule.
531
-			echo wpinv_html_select(
532
-				array(
533
-					'options'          => array_merge(
534
-						array(
535
-							'' => __( 'All VAT rules', 'invoicing' )
536
-						),
537
-						$wpinv_euvat->get_rules()
538
-					),
539
-					'name'             => 'vat_rule',
540
-					'id'               => 'vat_rule',
541
-					'selected'         => $vat_rule,
542
-					'show_option_all'  => false,
543
-					'show_option_none' => false,
544
-					'class'            => 'gdmbx2-text-medium',
545
-				)
546
-			);
547
-
548
-			// Filter by VAT class.
549
-		}
550
-
551
-		// Filter by vat class.
552
-		if ( $wpinv_euvat->allow_vat_classes() ) {
553
-	
554
-			// Sanitize selected vat rule.
555
-			$vat_class   = '';
556
-			if ( isset( $_GET['vat_class'] ) && array_key_exists(  $_GET['vat_class'], $wpinv_euvat->get_all_classes() ) ) {
557
-				$vat_class   =  $_GET['vat_class'];
558
-			}
559
-
560
-			echo wpinv_html_select(
561
-				array(
562
-					'options'          => array_merge(
563
-						array(
564
-							'' => __( 'All VAT classes', 'invoicing' )
565
-						),
566
-						$wpinv_euvat->get_all_classes()
567
-					),
568
-					'name'             => 'vat_class',
569
-					'id'               => 'vat_class',
570
-					'selected'         => $vat_class,
571
-					'show_option_all'  => false,
572
-					'show_option_none' => false,
573
-					'class'            => 'gdmbx2-text-medium',
574
-				)
575
-			);
576
-
577
-		}
578
-
579
-		// Filter by item type.
580
-		$type   = '';
581
-		if( isset( $_GET['type'] ) && array_key_exists(  $_GET['type'], wpinv_get_item_types() ) ) {
582
-			$type   =  $_GET['type'];
583
-		}
584
-
585
-		echo wpinv_html_select(
586
-			array(
587
-				'options'          => array_merge(
588
-					array(
589
-						'' => __( 'All item types', 'invoicing' )
590
-					),
591
-					wpinv_get_item_types()
592
-				),
593
-				'name'             => 'type',
594
-				'id'               => 'type',
595
-				'selected'         => $type,
596
-				'show_option_all'  => false,
597
-				'show_option_none' => false,
598
-				'class'            => 'gdmbx2-text-medium',
599
-			)
600
-		);
601
-
602
-	}
603
-
604
-	/**
605
-	 * Filters the item query.
606
-	 */
607
-	public static function filter_item_query( $query ) {
608
-
609
-		// modify the query only if it admin and main query.
610
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
611
-			return $query;
612
-		}
613
-
614
-		// we want to modify the query for our items.
615
-		if ( 'wpi_item' != $query->query['post_type'] ){
616
-			return $query;
617
-		}
618
-
619
-		if ( empty( $query->query_vars['meta_query'] ) ) {
620
-			$query->query_vars['meta_query'] = array();
621
-		}
622
-
623
-		// Filter vat rule type
623
+        // Filter vat rule type
624 624
         if ( ! empty( $_GET['vat_rule'] ) ) {
625 625
             $query->query_vars['meta_query'][] = array(
626 626
                 'key'     => '_wpinv_vat_rule',
@@ -645,94 +645,94 @@  discard block
 block discarded – undo
645 645
                 'value'   => sanitize_text_field( $_GET['type'] ),
646 646
                 'compare' => '='
647 647
             );
648
-		}
649
-
650
-	}
651
-
652
-	/**
653
-	 * Reorders items.
654
-	 */
655
-	public static function reorder_items( $vars ) {
656
-		global $typenow;
657
-
658
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
659
-			return $vars;
660
-		}
661
-
662
-		// By item type.
663
-		if ( 'type' == $vars['orderby'] ) {
664
-			return array_merge(
665
-				$vars,
666
-				array(
667
-					'meta_key' => '_wpinv_type',
668
-					'orderby'  => 'meta_value'
669
-				)
670
-			);
671
-		}
672
-
673
-		// By vat class.
674
-		if ( 'vat_class' == $vars['orderby'] ) {
675
-			return array_merge(
676
-				$vars,
677
-				array(
678
-					'meta_key' => '_wpinv_vat_class',
679
-					'orderby'  => 'meta_value'
680
-				)
681
-			);
682
-		}
683
-
684
-		// By vat rule.
685
-		if ( 'vat_rule' == $vars['orderby'] ) {
686
-			return array_merge(
687
-				$vars,
688
-				array(
689
-					'meta_key' => '_wpinv_vat_rule',
690
-					'orderby'  => 'meta_value'
691
-				)
692
-			);
693
-		}
694
-
695
-		// By price.
696
-		if ( 'price' == $vars['orderby'] ) {
697
-			return array_merge(
698
-				$vars,
699
-				array(
700
-					'meta_key' => '_wpinv_price',
701
-					'orderby'  => 'meta_value_num'
702
-				)
703
-			);
704
-		}
705
-
706
-		return $vars;
707
-
708
-	}
709
-
710
-	/**
711
-	 * Fired when deleting a post.
712
-	 */
713
-	public static function delete_post( $post_id ) {
714
-
715
-		switch ( get_post_type( $post_id ) ) {
716
-
717
-			case 'wpi_item' :
718
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
719
-				break;
720
-
721
-			case 'wpi_payment_form' :
722
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
723
-				break;
724
-
725
-			case 'wpi_discount' :
726
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
727
-				break;
728
-
729
-			case 'wpi_invoice' :
730
-				$invoice = new WPInv_Invoice( $post_id );
731
-				do_action( "getpaid_before_delete_invoice", $invoice );
732
-				$invoice->get_data_store()->delete_items( $invoice );
733
-				$invoice->get_data_store()->delete_special_fields( $invoice );
734
-				break;
735
-		}
736
-	}
648
+        }
649
+
650
+    }
651
+
652
+    /**
653
+     * Reorders items.
654
+     */
655
+    public static function reorder_items( $vars ) {
656
+        global $typenow;
657
+
658
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
659
+            return $vars;
660
+        }
661
+
662
+        // By item type.
663
+        if ( 'type' == $vars['orderby'] ) {
664
+            return array_merge(
665
+                $vars,
666
+                array(
667
+                    'meta_key' => '_wpinv_type',
668
+                    'orderby'  => 'meta_value'
669
+                )
670
+            );
671
+        }
672
+
673
+        // By vat class.
674
+        if ( 'vat_class' == $vars['orderby'] ) {
675
+            return array_merge(
676
+                $vars,
677
+                array(
678
+                    'meta_key' => '_wpinv_vat_class',
679
+                    'orderby'  => 'meta_value'
680
+                )
681
+            );
682
+        }
683
+
684
+        // By vat rule.
685
+        if ( 'vat_rule' == $vars['orderby'] ) {
686
+            return array_merge(
687
+                $vars,
688
+                array(
689
+                    'meta_key' => '_wpinv_vat_rule',
690
+                    'orderby'  => 'meta_value'
691
+                )
692
+            );
693
+        }
694
+
695
+        // By price.
696
+        if ( 'price' == $vars['orderby'] ) {
697
+            return array_merge(
698
+                $vars,
699
+                array(
700
+                    'meta_key' => '_wpinv_price',
701
+                    'orderby'  => 'meta_value_num'
702
+                )
703
+            );
704
+        }
705
+
706
+        return $vars;
707
+
708
+    }
709
+
710
+    /**
711
+     * Fired when deleting a post.
712
+     */
713
+    public static function delete_post( $post_id ) {
714
+
715
+        switch ( get_post_type( $post_id ) ) {
716
+
717
+            case 'wpi_item' :
718
+                do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
719
+                break;
720
+
721
+            case 'wpi_payment_form' :
722
+                do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
723
+                break;
724
+
725
+            case 'wpi_discount' :
726
+                do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
727
+                break;
728
+
729
+            case 'wpi_invoice' :
730
+                $invoice = new WPInv_Invoice( $post_id );
731
+                do_action( "getpaid_before_delete_invoice", $invoice );
732
+                $invoice->get_data_store()->delete_items( $invoice );
733
+                $invoice->get_data_store()->delete_special_fields( $invoice );
734
+                break;
735
+        }
736
+    }
737 737
 
738 738
 }
Please login to merge, or discard this patch.
Spacing   +192 added lines, -192 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
  * Post types Admin Class
@@ -21,68 +21,68 @@  discard block
 block discarded – undo
21 21
 		GetPaid_Metaboxes::init();
22 22
 
23 23
 		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
24
+		add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages');
25 25
 
26 26
 		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
27
+		add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2);
28 28
 
29 29
 		// Invoice table columns.
30
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
30
+		add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100);
31
+		add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2);
32 32
 
33 33
 		// Items table columns.
34
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
34
+		add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100);
35
+		add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20);
36
+		add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2);
37
+		add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100);
38
+		add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100);
39
+		add_action('request', array(__CLASS__, 'reorder_items'), 100);
40 40
 
41 41
 		// Payment forms columns.
42
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
42
+		add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100);
43
+		add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2);
44
+		add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2);
45 45
 
46 46
 		// Discount table columns.
47
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
47
+		add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100);
48 48
 
49 49
 		// Deleting posts.
50
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
50
+		add_action('delete_post', array(__CLASS__, 'delete_post'));
51
+		add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2);
52 52
 	}
53 53
 
54 54
 	/**
55 55
 	 * Post updated messages.
56 56
 	 */
57
-	public static function post_updated_messages( $messages ) {
57
+	public static function post_updated_messages($messages) {
58 58
 		global $post;
59 59
 
60 60
 		$messages['wpi_discount'] = array(
61 61
 			0   => '',
62
-			1   => __( 'Discount updated.', 'invoicing' ),
63
-			2   => __( 'Custom field updated.', 'invoicing' ),
64
-			3   => __( 'Custom field deleted.', 'invoicing' ),
65
-			4   => __( 'Discount updated.', 'invoicing' ),
66
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
-			6   => __( 'Discount updated.', 'invoicing' ),
68
-			7   => __( 'Discount saved.', 'invoicing' ),
69
-			8   => __( 'Discount submitted.', 'invoicing' ),
70
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
-			10  => __( 'Discount draft updated.', 'invoicing' ),
62
+			1   => __('Discount updated.', 'invoicing'),
63
+			2   => __('Custom field updated.', 'invoicing'),
64
+			3   => __('Custom field deleted.', 'invoicing'),
65
+			4   => __('Discount updated.', 'invoicing'),
66
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
67
+			6   => __('Discount updated.', 'invoicing'),
68
+			7   => __('Discount saved.', 'invoicing'),
69
+			8   => __('Discount submitted.', 'invoicing'),
70
+			9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
71
+			10  => __('Discount draft updated.', 'invoicing'),
72 72
 		);
73 73
 
74 74
 		$messages['wpi_payment_form'] = array(
75 75
 			0   => '',
76
-			1   => __( 'Payment Form updated.', 'invoicing' ),
77
-			2   => __( 'Custom field updated.', 'invoicing' ),
78
-			3   => __( 'Custom field deleted.', 'invoicing' ),
79
-			4   => __( 'Payment Form updated.', 'invoicing' ),
80
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
-			6   => __( 'Payment Form updated.', 'invoicing' ),
82
-			7   => __( 'Payment Form saved.', 'invoicing' ),
83
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
84
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
76
+			1   => __('Payment Form updated.', 'invoicing'),
77
+			2   => __('Custom field updated.', 'invoicing'),
78
+			3   => __('Custom field deleted.', 'invoicing'),
79
+			4   => __('Payment Form updated.', 'invoicing'),
80
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
81
+			6   => __('Payment Form updated.', 'invoicing'),
82
+			7   => __('Payment Form saved.', 'invoicing'),
83
+			8   => __('Payment Form submitted.', 'invoicing'),
84
+			9   => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
85
+			10  => __('Payment Form draft updated.', 'invoicing'),
86 86
 		);
87 87
 
88 88
 		return $messages;
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 	/**
93 93
 	 * Post row actions.
94 94
 	 */
95
-	public static function post_row_actions( $actions, $post ) {
95
+	public static function post_row_actions($actions, $post) {
96 96
 
97
-		$post = get_post( $post );
97
+		$post = get_post($post);
98 98
 
99 99
 		// We do not want to edit the default payment form.
100
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
-			unset( $actions['trash'] );
102
-			unset( $actions['inline hide-if-no-js'] );
100
+		if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) {
101
+			unset($actions['trash']);
102
+			unset($actions['inline hide-if-no-js']);
103 103
 		}
104 104
 
105 105
 		return $actions;
@@ -108,51 +108,51 @@  discard block
 block discarded – undo
108 108
 	/**
109 109
 	 * Returns an array of invoice table columns.
110 110
 	 */
111
-	public static function invoice_columns( $columns ) {
111
+	public static function invoice_columns($columns) {
112 112
 
113 113
 		$columns = array(
114 114
 			'cb'                => $columns['cb'],
115
-			'number'            => __( 'Invoice', 'invoicing' ),
116
-			'customer'          => __( 'Customer', 'invoicing' ),
117
-			'invoice_date'      => __( 'Date', 'invoicing' ),
118
-			'amount'            => __( 'Amount', 'invoicing' ),
119
-			'recurring'         => __( 'Recurring', 'invoicing' ),
120
-			'status'            => __( 'Status', 'invoicing' ),
121
-			'wpi_actions'       => __( 'Actions', 'invoicing' ),
115
+			'number'            => __('Invoice', 'invoicing'),
116
+			'customer'          => __('Customer', 'invoicing'),
117
+			'invoice_date'      => __('Date', 'invoicing'),
118
+			'amount'            => __('Amount', 'invoicing'),
119
+			'recurring'         => __('Recurring', 'invoicing'),
120
+			'status'            => __('Status', 'invoicing'),
121
+			'wpi_actions'       => __('Actions', 'invoicing'),
122 122
 		);
123 123
 
124
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
124
+		return apply_filters('wpi_invoice_table_columns', $columns);
125 125
 	}
126 126
 
127 127
 	/**
128 128
 	 * Displays invoice table columns.
129 129
 	 */
130
-	public static function display_invoice_columns( $column_name, $post_id ) {
130
+	public static function display_invoice_columns($column_name, $post_id) {
131 131
 
132
-		$invoice = new WPInv_Invoice( $post_id );
132
+		$invoice = new WPInv_Invoice($post_id);
133 133
 
134
-		switch ( $column_name ) {
134
+		switch ($column_name) {
135 135
 
136 136
 			case 'invoice_date' :
137
-				$date_time = sanitize_text_field( $invoice->get_created_date() );
138
-				$date      = mysql2date( get_option( 'date_format' ), $date_time );
137
+				$date_time = sanitize_text_field($invoice->get_created_date());
138
+				$date      = mysql2date(get_option('date_format'), $date_time);
139 139
 				echo "<span title='$date_time'>$date</span>";
140 140
 				break;
141 141
 
142 142
 			case 'amount' :
143 143
 
144 144
 				$amount = $invoice->get_total();
145
-				$formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
145
+				$formated_amount = wpinv_price(wpinv_format_amount($amount), $invoice->get_currency());
146 146
 
147
-				if ( $invoice->is_refunded() ) {
148
-					$refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
147
+				if ($invoice->is_refunded()) {
148
+					$refunded_amount = wpinv_price(wpinv_format_amount(0), $invoice->get_currency());
149 149
 					echo "<del>$formated_amount</del><ins>$refunded_amount</ins>";
150 150
 				} else {
151 151
 
152 152
 					$discount = $invoice->get_total_discount();
153 153
 
154
-					if ( ! empty( $discount ) ) {
155
-						$new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
154
+					if (!empty($discount)) {
155
+						$new_amount = wpinv_price(wpinv_format_amount($amount + $discount), $invoice->get_currency());
156 156
 						echo "<del>$new_amount</del><ins>$formated_amount</ins>";
157 157
 					} else {
158 158
 						echo $formated_amount;
@@ -163,13 +163,13 @@  discard block
 block discarded – undo
163 163
 				break;
164 164
 
165 165
 			case 'status' :
166
-				$status       = sanitize_text_field( $invoice->get_status() );
167
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
166
+				$status       = sanitize_text_field($invoice->get_status());
167
+				$status_label = sanitize_text_field($invoice->get_status_nicename());
168 168
 
169 169
 				// If it is paid, show the gateway title.
170
-				if ( $invoice->is_paid() ) {
171
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
170
+				if ($invoice->is_paid()) {
171
+					$gateway = sanitize_text_field($invoice->get_gateway_title());
172
+					$gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), $gateway);
173 173
 
174 174
 					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175 175
 				} else {
@@ -177,22 +177,22 @@  discard block
 block discarded – undo
177 177
 				}
178 178
 
179 179
 				// If it is not paid, display the overdue and view status.
180
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
180
+				if (!$invoice->is_paid() && !$invoice->is_refunded()) {
181 181
 
182 182
 					// Invoice view status.
183
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
183
+					if (wpinv_is_invoice_viewed($invoice->get_id())) {
184
+						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>';
185 185
 					} else {
186
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
186
+						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>';
187 187
 					}
188 188
 
189 189
 					// Display the overview status.
190
-					if ( wpinv_get_option( 'overdue_active' ) ) {
190
+					if (wpinv_get_option('overdue_active')) {
191 191
 						$due_date = $invoice->get_due_date();
192 192
 
193
-						if ( ! empty( $due_date ) ) {
194
-							$date = mysql2date( get_option( 'date_format' ), $due_date );
195
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $date );
193
+						if (!empty($due_date)) {
194
+							$date = mysql2date(get_option('date_format'), $due_date);
195
+							$date = wp_sprintf(__('Due %s', 'invoicing'), $date);
196 196
 							echo "<p class='description' style='color: #888;' title='$due_date'>$date</p>";
197 197
 						}
198 198
 					}
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 
204 204
 			case 'recurring':
205 205
 
206
-				if ( $invoice->is_recurring() ) {
206
+				if ($invoice->is_recurring()) {
207 207
 					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208 208
 				} else {
209 209
 					echo '<i class="fa fa-times" style="color:#616161;"></i>';
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
 
213 213
 			case 'number' :
214 214
 
215
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
217
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
215
+				$edit_link       = esc_url(get_edit_post_link($invoice->get_id()));
216
+				$invoice_number  = sanitize_text_field($invoice->get_number());
217
+				$invoice_details = esc_attr__('View Invoice Details', 'invoicing');
218 218
 
219 219
 				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
220 220
 
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
 	
225 225
 				$customer_name = $invoice->get_user_full_name();
226 226
 	
227
-				if ( empty( $customer_name ) ) {
227
+				if (empty($customer_name)) {
228 228
 					$customer_name = $invoice->get_email();
229 229
 				}
230 230
 	
231
-				if ( ! empty( $customer_name ) ) {
232
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
231
+				if (!empty($customer_name)) {
232
+					$customer_details = esc_attr__('View Customer Details', 'invoicing');
233
+					$view_link        = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php')));
234 234
 					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235 235
 				} else {
236 236
 					echo '<div>&mdash;</div>';
@@ -240,12 +240,12 @@  discard block
 block discarded – undo
240 240
 
241 241
 			case 'wpi_actions' :
242 242
 
243
-				if ( $invoice->is_draft() ) {
243
+				if ($invoice->is_draft()) {
244 244
 					return;
245 245
 				}
246 246
 
247
-				$url    = esc_url( $invoice->get_view_url() );
248
-				$print  = esc_attr__( 'Print invoice', 'invoicing' );
247
+				$url    = esc_url($invoice->get_view_url());
248
+				$print  = esc_attr__('Print invoice', 'invoicing');
249 249
 				echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
250 250
 
251 251
 				$url    = esc_url(
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 					)
262 262
 				);
263 263
 
264
-				$send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
264
+				$send = esc_attr__('Send invoice to customer', 'invoicing');
265 265
 				echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
266 266
 
267 267
 				break;
@@ -272,50 +272,50 @@  discard block
 block discarded – undo
272 272
 	/**
273 273
 	 * Returns an array of payment forms table columns.
274 274
 	 */
275
-	public static function payment_form_columns( $columns ) {
275
+	public static function payment_form_columns($columns) {
276 276
 
277 277
 		$columns = array(
278 278
 			'cb'                => $columns['cb'],
279
-			'title'             => __( 'Name', 'invoicing' ),
280
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
-			'earnings'          => __( 'Revenue', 'invoicing' ),
282
-			'refunds'           => __( 'Refunded', 'invoicing' ),
283
-			'items'             => __( 'Items', 'invoicing' ),
284
-			'date'              => __( 'Date', 'invoicing' ),
279
+			'title'             => __('Name', 'invoicing'),
280
+			'shortcode'         => __('Shortcode', 'invoicing'),
281
+			'earnings'          => __('Revenue', 'invoicing'),
282
+			'refunds'           => __('Refunded', 'invoicing'),
283
+			'items'             => __('Items', 'invoicing'),
284
+			'date'              => __('Date', 'invoicing'),
285 285
 		);
286 286
 
287
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
287
+		return apply_filters('wpi_payment_form_table_columns', $columns);
288 288
 
289 289
 	}
290 290
 
291 291
 	/**
292 292
 	 * Displays payment form table columns.
293 293
 	 */
294
-	public static function display_payment_form_columns( $column_name, $post_id ) {
294
+	public static function display_payment_form_columns($column_name, $post_id) {
295 295
 
296 296
 		// Retrieve the payment form.
297
-		$form = new GetPaid_Payment_Form( $post_id );
297
+		$form = new GetPaid_Payment_Form($post_id);
298 298
 
299
-		switch ( $column_name ) {
299
+		switch ($column_name) {
300 300
 
301 301
 			case 'earnings' :
302
-				echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
302
+				echo wpinv_price(wpinv_format_amount($form->get_earned()));
303 303
 				break;
304 304
 
305 305
 			case 'refunds' :
306
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
306
+				echo wpinv_price(wpinv_format_amount($form->get_refunded()));
307 307
 				break;
308 308
 
309 309
 			case 'refunds' :
310
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
310
+				echo wpinv_price(wpinv_format_amount($form->get_refunded()));
311 311
 				break;
312 312
 
313 313
 			case 'shortcode' :
314 314
 
315
-				if ( $form->is_default() ) {
315
+				if ($form->is_default()) {
316 316
 					echo '&mdash;';
317 317
 				} else {
318
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
318
+					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>';
319 319
 				}
320 320
 
321 321
 				break;
@@ -324,29 +324,29 @@  discard block
 block discarded – undo
324 324
 
325 325
 				$items = $form->get_items();
326 326
 
327
-				if ( $form->is_default() || empty( $items ) ) {
327
+				if ($form->is_default() || empty($items)) {
328 328
 					echo '&mdash;';
329 329
 					return;
330 330
 				}
331 331
 
332 332
 				$_items = array();
333 333
 
334
-				foreach ( $items as $item ) {
334
+				foreach ($items as $item) {
335 335
 					$url = $item->get_edit_url();
336 336
 
337
-					if ( empty( $url ) ) {
338
-						$_items[] = sanitize_text_field( $item->get_name() );
337
+					if (empty($url)) {
338
+						$_items[] = sanitize_text_field($item->get_name());
339 339
 					} else {
340 340
 						$_items[] = sprintf(
341 341
 							'<a href="%s">%s</a>',
342
-							esc_url( $url ),
343
-							sanitize_text_field( $item->get_name() )
342
+							esc_url($url),
343
+							sanitize_text_field($item->get_name())
344 344
 						);
345 345
 					}
346 346
 
347 347
 				}
348 348
 
349
-				echo implode( '<br>', $_items );
349
+				echo implode('<br>', $_items);
350 350
 
351 351
 				break;
352 352
 
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
 	/**
358 358
 	 * Filters post states.
359 359
 	 */
360
-	public static function filter_payment_form_state( $post_states, $post ) {
360
+	public static function filter_payment_form_state($post_states, $post) {
361 361
 
362
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
362
+		if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) {
363
+			$post_states['default_form'] = __('Default Payment Form', 'invoicing');
364 364
 		}
365 365
 	
366 366
 		return $post_states;
@@ -370,35 +370,35 @@  discard block
 block discarded – undo
370 370
 	/**
371 371
 	 * Returns an array of coupon table columns.
372 372
 	 */
373
-	public static function discount_columns( $columns ) {
373
+	public static function discount_columns($columns) {
374 374
 
375 375
 		$columns = array(
376 376
 			'cb'                => $columns['cb'],
377
-			'title'             => __( 'Name', 'invoicing' ),
378
-			'code'              => __( 'Code', 'invoicing' ),
379
-			'amount'            => __( 'Amount', 'invoicing' ),
380
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
-			'start_date'        => __( 'Start Date', 'invoicing' ),
382
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
377
+			'title'             => __('Name', 'invoicing'),
378
+			'code'              => __('Code', 'invoicing'),
379
+			'amount'            => __('Amount', 'invoicing'),
380
+			'usage'             => __('Usage / Limit', 'invoicing'),
381
+			'start_date'        => __('Start Date', 'invoicing'),
382
+			'expiry_date'       => __('Expiry Date', 'invoicing'),
383 383
 		);
384 384
 
385
-		return apply_filters( 'wpi_discount_table_columns', $columns );
385
+		return apply_filters('wpi_discount_table_columns', $columns);
386 386
 	}
387 387
 
388 388
 	/**
389 389
 	 * Filters post states.
390 390
 	 */
391
-	public static function filter_discount_state( $post_states, $post ) {
391
+	public static function filter_discount_state($post_states, $post) {
392 392
 
393
-		if ( 'wpi_discount' == $post->post_type ) {
393
+		if ('wpi_discount' == $post->post_type) {
394 394
 
395
-			$discount = new WPInv_Discount( $post );
395
+			$discount = new WPInv_Discount($post);
396 396
 
397 397
 			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
398 398
 
399
-			if ( $status != 'publish' ) {
399
+			if ($status != 'publish') {
400 400
 				return array(
401
-					'discount_status' => wpinv_discount_status( $status ),
401
+					'discount_status' => wpinv_discount_status($status),
402 402
 				);
403 403
 			}
404 404
 
@@ -413,34 +413,34 @@  discard block
 block discarded – undo
413 413
 	/**
414 414
 	 * Returns an array of items table columns.
415 415
 	 */
416
-	public static function item_columns( $columns ) {
416
+	public static function item_columns($columns) {
417 417
 		global $wpinv_euvat;
418 418
 
419 419
 		$columns = array(
420 420
 			'cb'                => $columns['cb'],
421
-			'title'             => __( 'Name', 'invoicing' ),
422
-			'price'             => __( 'Price', 'invoicing' ),
423
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
425
-			'type'              => __( 'Type', 'invoicing' ),
426
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
421
+			'title'             => __('Name', 'invoicing'),
422
+			'price'             => __('Price', 'invoicing'),
423
+			'vat_rule'          => __('VAT rule', 'invoicing'),
424
+			'vat_class'         => __('VAT class', 'invoicing'),
425
+			'type'              => __('Type', 'invoicing'),
426
+			'shortcode'         => __('Shortcode', 'invoicing'),
427 427
 		);
428 428
 
429
-		if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
-			unset( $columns['vat_rule'] );
429
+		if (!$wpinv_euvat->allow_vat_rules()) {
430
+			unset($columns['vat_rule']);
431 431
 		}
432 432
 
433
-		if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
-			unset( $columns['vat_class'] );
433
+		if (!$wpinv_euvat->allow_vat_classes()) {
434
+			unset($columns['vat_class']);
435 435
 		}
436 436
 
437
-		return apply_filters( 'wpi_item_table_columns', $columns );
437
+		return apply_filters('wpi_item_table_columns', $columns);
438 438
 	}
439 439
 
440 440
 	/**
441 441
 	 * Returns an array of sortable items table columns.
442 442
 	 */
443
-	public static function sortable_item_columns( $columns ) {
443
+	public static function sortable_item_columns($columns) {
444 444
 
445 445
 		return array_merge(
446 446
 			$columns,
@@ -457,50 +457,50 @@  discard block
 block discarded – undo
457 457
 	/**
458 458
 	 * Displays items table columns.
459 459
 	 */
460
-	public static function display_item_columns( $column_name, $post_id ) {
460
+	public static function display_item_columns($column_name, $post_id) {
461 461
 		global $wpinv_euvat;
462 462
 
463
-		$item = new WPInv_Item( $post_id );
463
+		$item = new WPInv_Item($post_id);
464 464
 
465
-		switch ( $column_name ) {
465
+		switch ($column_name) {
466 466
 
467 467
 			case 'price' :
468 468
 
469
-				if ( ! $item->is_recurring() ) {
469
+				if (!$item->is_recurring()) {
470 470
 					echo $item->get_the_price();
471 471
 					break;
472 472
 				}
473 473
 
474 474
 				$price = wp_sprintf(
475
-					__( '%s / %s', 'invoicing' ),
475
+					__('%s / %s', 'invoicing'),
476 476
 					$item->get_the_price(),
477
-					WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->get_recurring_period(), $item->get_recurring_interval() )
477
+					WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->get_recurring_period(), $item->get_recurring_interval())
478 478
 				);
479 479
 
480
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
480
+				if ($item->get_the_price() == $item->get_the_initial_price()) {
481 481
 					echo $price;
482 482
 					break;
483 483
 				}
484 484
 
485 485
 				echo $item->get_the_initial_price();
486 486
 
487
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
487
+				echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>';
488 488
 				break;
489 489
 
490 490
 			case 'vat_rule' :
491
-				echo $wpinv_euvat->item_rule_label( $item->get_id() );
491
+				echo $wpinv_euvat->item_rule_label($item->get_id());
492 492
 				break;
493 493
 
494 494
 			case 'vat_class' :
495
-				echo $wpinv_euvat->item_class_label( $item->get_id() );
495
+				echo $wpinv_euvat->item_class_label($item->get_id());
496 496
 				break;
497 497
 
498 498
 			case 'shortcode' :
499
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
499
+				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500 500
 				break;
501 501
 
502 502
 			case 'type' :
503
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
503
+				echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504 504
 				break;
505 505
 
506 506
 		}
@@ -510,21 +510,21 @@  discard block
 block discarded – undo
510 510
 	/**
511 511
 	 * Lets users filter items using taxes.
512 512
 	 */
513
-	public static function add_item_filters( $post_type ) {
513
+	public static function add_item_filters($post_type) {
514 514
 		global $wpinv_euvat;
515 515
 
516 516
 		// Abort if we're not dealing with items.
517
-		if ( $post_type != 'wpi_item' ) {
517
+		if ($post_type != 'wpi_item') {
518 518
 			return;
519 519
 		}
520 520
 
521 521
 		// Filter by vat rules.
522
-		if ( $wpinv_euvat->allow_vat_rules() ) {
522
+		if ($wpinv_euvat->allow_vat_rules()) {
523 523
 	
524 524
 			// Sanitize selected vat rule.
525
-			$vat_rule   = '';
526
-			if ( isset( $_GET['vat_rule'] ) && array_key_exists(  $_GET['vat_rule'], $wpinv_euvat->get_rules() ) ) {
527
-				$vat_rule   =  $_GET['vat_rule'];
525
+			$vat_rule = '';
526
+			if (isset($_GET['vat_rule']) && array_key_exists($_GET['vat_rule'], $wpinv_euvat->get_rules())) {
527
+				$vat_rule = $_GET['vat_rule'];
528 528
 			}
529 529
 
530 530
 			// Filter by VAT rule.
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 				array(
533 533
 					'options'          => array_merge(
534 534
 						array(
535
-							'' => __( 'All VAT rules', 'invoicing' )
535
+							'' => __('All VAT rules', 'invoicing')
536 536
 						),
537 537
 						$wpinv_euvat->get_rules()
538 538
 					),
@@ -549,19 +549,19 @@  discard block
 block discarded – undo
549 549
 		}
550 550
 
551 551
 		// Filter by vat class.
552
-		if ( $wpinv_euvat->allow_vat_classes() ) {
552
+		if ($wpinv_euvat->allow_vat_classes()) {
553 553
 	
554 554
 			// Sanitize selected vat rule.
555
-			$vat_class   = '';
556
-			if ( isset( $_GET['vat_class'] ) && array_key_exists(  $_GET['vat_class'], $wpinv_euvat->get_all_classes() ) ) {
557
-				$vat_class   =  $_GET['vat_class'];
555
+			$vat_class = '';
556
+			if (isset($_GET['vat_class']) && array_key_exists($_GET['vat_class'], $wpinv_euvat->get_all_classes())) {
557
+				$vat_class = $_GET['vat_class'];
558 558
 			}
559 559
 
560 560
 			echo wpinv_html_select(
561 561
 				array(
562 562
 					'options'          => array_merge(
563 563
 						array(
564
-							'' => __( 'All VAT classes', 'invoicing' )
564
+							'' => __('All VAT classes', 'invoicing')
565 565
 						),
566 566
 						$wpinv_euvat->get_all_classes()
567 567
 					),
@@ -577,16 +577,16 @@  discard block
 block discarded – undo
577 577
 		}
578 578
 
579 579
 		// Filter by item type.
580
-		$type   = '';
581
-		if( isset( $_GET['type'] ) && array_key_exists(  $_GET['type'], wpinv_get_item_types() ) ) {
582
-			$type   =  $_GET['type'];
580
+		$type = '';
581
+		if (isset($_GET['type']) && array_key_exists($_GET['type'], wpinv_get_item_types())) {
582
+			$type = $_GET['type'];
583 583
 		}
584 584
 
585 585
 		echo wpinv_html_select(
586 586
 			array(
587 587
 				'options'          => array_merge(
588 588
 					array(
589
-						'' => __( 'All item types', 'invoicing' )
589
+						'' => __('All item types', 'invoicing')
590 590
 					),
591 591
 					wpinv_get_item_types()
592 592
 				),
@@ -604,45 +604,45 @@  discard block
 block discarded – undo
604 604
 	/**
605 605
 	 * Filters the item query.
606 606
 	 */
607
-	public static function filter_item_query( $query ) {
607
+	public static function filter_item_query($query) {
608 608
 
609 609
 		// modify the query only if it admin and main query.
610
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
610
+		if (!(is_admin() && $query->is_main_query())) { 
611 611
 			return $query;
612 612
 		}
613 613
 
614 614
 		// we want to modify the query for our items.
615
-		if ( 'wpi_item' != $query->query['post_type'] ){
615
+		if ('wpi_item' != $query->query['post_type']) {
616 616
 			return $query;
617 617
 		}
618 618
 
619
-		if ( empty( $query->query_vars['meta_query'] ) ) {
619
+		if (empty($query->query_vars['meta_query'])) {
620 620
 			$query->query_vars['meta_query'] = array();
621 621
 		}
622 622
 
623 623
 		// Filter vat rule type
624
-        if ( ! empty( $_GET['vat_rule'] ) ) {
624
+        if (!empty($_GET['vat_rule'])) {
625 625
             $query->query_vars['meta_query'][] = array(
626 626
                 'key'     => '_wpinv_vat_rule',
627
-                'value'   => sanitize_text_field( $_GET['vat_rule'] ),
627
+                'value'   => sanitize_text_field($_GET['vat_rule']),
628 628
                 'compare' => '='
629 629
             );
630 630
         }
631 631
 
632 632
         // Filter vat class
633
-        if ( ! empty( $_GET['vat_class'] ) ) {
633
+        if (!empty($_GET['vat_class'])) {
634 634
             $query->query_vars['meta_query'][] = array(
635 635
                 'key'     => '_wpinv_vat_class',
636
-                'value'   => sanitize_text_field( $_GET['vat_class'] ),
636
+                'value'   => sanitize_text_field($_GET['vat_class']),
637 637
                 'compare' => '='
638 638
             );
639 639
         }
640 640
 
641 641
         // Filter item type
642
-        if ( ! empty( $_GET['type'] ) ) {
642
+        if (!empty($_GET['type'])) {
643 643
             $query->query_vars['meta_query'][] = array(
644 644
                 'key'     => '_wpinv_type',
645
-                'value'   => sanitize_text_field( $_GET['type'] ),
645
+                'value'   => sanitize_text_field($_GET['type']),
646 646
                 'compare' => '='
647 647
             );
648 648
 		}
@@ -652,15 +652,15 @@  discard block
 block discarded – undo
652 652
 	/**
653 653
 	 * Reorders items.
654 654
 	 */
655
-	public static function reorder_items( $vars ) {
655
+	public static function reorder_items($vars) {
656 656
 		global $typenow;
657 657
 
658
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
658
+		if ('wpi_item' !== $typenow || empty($vars['orderby'])) {
659 659
 			return $vars;
660 660
 		}
661 661
 
662 662
 		// By item type.
663
-		if ( 'type' == $vars['orderby'] ) {
663
+		if ('type' == $vars['orderby']) {
664 664
 			return array_merge(
665 665
 				$vars,
666 666
 				array(
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
 		}
672 672
 
673 673
 		// By vat class.
674
-		if ( 'vat_class' == $vars['orderby'] ) {
674
+		if ('vat_class' == $vars['orderby']) {
675 675
 			return array_merge(
676 676
 				$vars,
677 677
 				array(
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
 		}
683 683
 
684 684
 		// By vat rule.
685
-		if ( 'vat_rule' == $vars['orderby'] ) {
685
+		if ('vat_rule' == $vars['orderby']) {
686 686
 			return array_merge(
687 687
 				$vars,
688 688
 				array(
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
 		}
694 694
 
695 695
 		// By price.
696
-		if ( 'price' == $vars['orderby'] ) {
696
+		if ('price' == $vars['orderby']) {
697 697
 			return array_merge(
698 698
 				$vars,
699 699
 				array(
@@ -710,27 +710,27 @@  discard block
 block discarded – undo
710 710
 	/**
711 711
 	 * Fired when deleting a post.
712 712
 	 */
713
-	public static function delete_post( $post_id ) {
713
+	public static function delete_post($post_id) {
714 714
 
715
-		switch ( get_post_type( $post_id ) ) {
715
+		switch (get_post_type($post_id)) {
716 716
 
717 717
 			case 'wpi_item' :
718
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
718
+				do_action("getpaid_before_delete_item", new WPInv_Item($post_id));
719 719
 				break;
720 720
 
721 721
 			case 'wpi_payment_form' :
722
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
722
+				do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id));
723 723
 				break;
724 724
 
725 725
 			case 'wpi_discount' :
726
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
726
+				do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id));
727 727
 				break;
728 728
 
729 729
 			case 'wpi_invoice' :
730
-				$invoice = new WPInv_Invoice( $post_id );
731
-				do_action( "getpaid_before_delete_invoice", $invoice );
732
-				$invoice->get_data_store()->delete_items( $invoice );
733
-				$invoice->get_data_store()->delete_special_fields( $invoice );
730
+				$invoice = new WPInv_Invoice($post_id);
731
+				do_action("getpaid_before_delete_invoice", $invoice);
732
+				$invoice->get_data_store()->delete_items($invoice);
733
+				$invoice->get_data_store()->delete_special_fields($invoice);
734 734
 				break;
735 735
 		}
736 736
 	}
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -181,7 +181,7 @@
 block discarded – undo
181 181
     $message = wpinv_email_style_body( $message );
182 182
     $to      = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) );
183 183
 
184
-	return $mailer->send(
184
+    return $mailer->send(
185 185
         $to,
186 186
         $subject,
187 187
         $message,
Please login to merge, or discard this patch.
Spacing   +123 added lines, -123 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/wpinv-email-invoice-details.php', $args );
44
+    $args = compact('invoice', 'email_type', 'sent_to_admin');
45
+    wpinv_get_template('emails/wpinv-email-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
 /**
@@ -55,17 +55,17 @@  discard block
 block discarded – undo
55 55
  * @param string $email_type
56 56
  * @param bool $sent_to_admin
57 57
  */
58
-function wpinv_email_invoice_items( $invoice, $email_type, $sent_to_admin ) {
58
+function wpinv_email_invoice_items($invoice, $email_type, $sent_to_admin) {
59 59
 
60 60
     // Prepare line items.
61
-    $columns = getpaid_invoice_item_columns( $invoice );
62
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
61
+    $columns = getpaid_invoice_item_columns($invoice);
62
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
63 63
 
64 64
     // Load the template.
65
-    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) );
65
+    wpinv_get_template('emails/wpinv-email-invoice-items.php', compact('invoice', 'columns', 'email_type', 'sent_to_admin'));
66 66
 
67 67
 }
68
-add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
68
+add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3);
69 69
 
70 70
 
71 71
 /**
@@ -75,13 +75,13 @@  discard block
 block discarded – undo
75 75
  * @param string $email_type
76 76
  * @param bool $sent_to_admin
77 77
  */
78
-function wpinv_email_billing_details( $invoice, $email_type, $sent_to_admin ) {
78
+function wpinv_email_billing_details($invoice, $email_type, $sent_to_admin) {
79 79
 
80
-    $args = compact( 'invoice', 'email_type', 'sent_to_admin' );
81
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', $args );
80
+    $args = compact('invoice', 'email_type', 'sent_to_admin');
81
+    wpinv_get_template('emails/wpinv-email-billing-details.php', $args);
82 82
 
83 83
 }
84
-add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
84
+add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3);
85 85
 
86 86
 /**
87 87
  * Returns email css.
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
  */
90 90
 function getpaid_get_email_css() {
91 91
 
92
-    $css = wpinv_get_template_html( 'emails/wpinv-email-styles.php' );
93
-    return apply_filters( 'wpinv_email_styles', $css );
92
+    $css = wpinv_get_template_html('emails/wpinv-email-styles.php');
93
+    return apply_filters('wpinv_email_styles', $css);
94 94
 
95 95
 }
96 96
 
@@ -101,17 +101,17 @@  discard block
 block discarded – undo
101 101
  * @return string
102 102
  * 
103 103
  */
104
-function wpinv_email_style_body( $content ) {
104
+function wpinv_email_style_body($content) {
105 105
 
106 106
     $css = getpaid_get_email_css();
107 107
 
108 108
     // Inline the css.
109 109
     try {
110
-        $emogrifier = new Emogrifier( $content, $css );
110
+        $emogrifier = new Emogrifier($content, $css);
111 111
         $_content   = $emogrifier->emogrify();
112 112
         $content    = $_content;
113
-    } catch ( Exception $e ) {
114
-        wpinv_error_log( $e->getMessage(), 'emogrifier' );
113
+    } catch (Exception $e) {
114
+        wpinv_error_log($e->getMessage(), 'emogrifier');
115 115
     }
116 116
 
117 117
     return $content;
@@ -120,37 +120,37 @@  discard block
 block discarded – undo
120 120
 
121 121
 // Backwards compatibility.
122 122
 function wpinv_init_transactional_emails() {
123
-    foreach ( apply_filters( 'wpinv_email_actions', array() ) as $action ) {
124
-        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
123
+    foreach (apply_filters('wpinv_email_actions', array()) as $action) {
124
+        add_action($action, 'wpinv_send_transactional_email', 10, 10);
125 125
     }
126 126
 }
127
-add_action( 'init', 'wpinv_init_transactional_emails' );
127
+add_action('init', 'wpinv_init_transactional_emails');
128 128
 
129 129
 function wpinv_send_transactional_email() {
130 130
     $args       = func_get_args();
131 131
     $function   = current_filter() . '_notification';
132
-    do_action_ref_array( $function, $args );
132
+    do_action_ref_array($function, $args);
133 133
 }
134 134
 
135 135
 function wpinv_mail_get_from_address() {
136
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
137
-    return sanitize_email( $from_address );
136
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from'));
137
+    return sanitize_email($from_address);
138 138
 }
139 139
 
140 140
 function wpinv_mail_get_from_name() {
141
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
142
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
141
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name'));
142
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
143 143
 }
144 144
 
145
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
146
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
147
-    return ( $active ? true : false );
145
+function wpinv_mail_admin_bcc_active($mail_type = '') {
146
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
147
+    return ($active ? true : false);
148 148
 }
149 149
     
150
-function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
151
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
150
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
151
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
152 152
 
153
-    switch ( $email_type ) {
153
+    switch ($email_type) {
154 154
         case 'html' :
155 155
             $content_type = 'text/html';
156 156
             break;
@@ -175,11 +175,11 @@  discard block
 block discarded – undo
175 175
  * @param array        $attachments Any files to attach to the email.
176 176
  * @param string|array $cc An email or array of extra emails to send a copy of the email to.
177 177
  */
178
-function wpinv_mail_send( $to, $subject, $message, $deprecated, $attachments = array(), $cc = array() ) {
178
+function wpinv_mail_send($to, $subject, $message, $deprecated, $attachments = array(), $cc = array()) {
179 179
 
180 180
     $mailer  = new GetPaid_Notification_Email_Sender();
181
-    $message = wpinv_email_style_body( $message );
182
-    $to      = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) );
181
+    $message = wpinv_email_style_body($message);
182
+    $to      = array_merge(wpinv_parse_list($to), wpinv_parse_list($cc));
183 183
 
184 184
 	return $mailer->send(
185 185
         $to,
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
  * @return array
197 197
  */
198 198
 function wpinv_get_emails() {
199
-    return apply_filters( 'wpinv_get_emails', wpinv_get_data( 'email-settings' ) );
199
+    return apply_filters('wpinv_get_emails', wpinv_get_data('email-settings'));
200 200
 }
201 201
 
202 202
 /**
@@ -205,172 +205,172 @@  discard block
 block discarded – undo
205 205
  * @param array $settings
206 206
  * @return array
207 207
  */
208
-function wpinv_settings_emails( $settings = array() ) {
209
-    $settings = array_merge( $settings, wpinv_get_emails() );
210
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
208
+function wpinv_settings_emails($settings = array()) {
209
+    $settings = array_merge($settings, wpinv_get_emails());
210
+    return apply_filters('wpinv_settings_get_emails', $settings);
211 211
 }
212
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
212
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
213 213
 
214 214
 /**
215 215
  * Filter email section names.
216 216
  * 
217 217
  */
218
-function wpinv_settings_sections_emails( $settings ) {
219
-    foreach  ( wpinv_get_emails() as $key => $email) {
220
-        $settings[$key] = ! empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : strip_tags( $key );
218
+function wpinv_settings_sections_emails($settings) {
219
+    foreach (wpinv_get_emails() as $key => $email) {
220
+        $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : strip_tags($key);
221 221
     }
222 222
 
223 223
     return $settings;    
224 224
 }
225
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
225
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
226 226
 
227
-function wpinv_email_is_enabled( $email_type ) {
227
+function wpinv_email_is_enabled($email_type) {
228 228
     $emails = wpinv_get_emails();
229
-    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( 'email_'. $email_type . '_active', 0 ) ? true : false;
229
+    $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false;
230 230
 
231
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
231
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
232 232
 }
233 233
 
234
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
235
-    switch ( $email_type ) {
234
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
235
+    switch ($email_type) {
236 236
         case 'new_invoice':
237 237
         case 'cancelled_invoice':
238 238
         case 'failed_invoice':
239 239
             $recipient  = wpinv_get_admin_email();
240 240
         break;
241 241
         default:
242
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
243
-            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
242
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
243
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
244 244
         break;
245 245
     }
246 246
 
247
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
247
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
248 248
 }
249 249
 
250 250
 /**
251 251
  * Returns invoice CC recipients
252 252
  */
253
-function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) {
254
-    switch ( $email_type ) {
253
+function wpinv_email_get_cc_recipients($email_type = '', $invoice_id = 0, $invoice = array()) {
254
+    switch ($email_type) {
255 255
         case 'new_invoice':
256 256
         case 'cancelled_invoice':
257 257
         case 'failed_invoice':
258 258
             return array();
259 259
         break;
260 260
         default:
261
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
262
-            $recipient  = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true );
263
-            if ( empty( $recipient ) ) {
261
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
262
+            $recipient  = empty($invoice) ? '' : get_post_meta($invoice->ID, 'wpinv_email_cc', true);
263
+            if (empty($recipient)) {
264 264
                 return array();
265 265
             }
266
-            return  array_filter( array_map( 'trim', explode( ',', $recipient ) ) );
266
+            return  array_filter(array_map('trim', explode(',', $recipient)));
267 267
         break;
268 268
     }
269 269
 
270 270
 }
271 271
 
272
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
273
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
274
-    $subject    = __( $subject, 'invoicing' );
272
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
273
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
274
+    $subject    = __($subject, 'invoicing');
275 275
 
276
-    $subject    = wpinv_email_format_text( $subject, $invoice );
276
+    $subject    = wpinv_email_format_text($subject, $invoice);
277 277
 
278
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
278
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
279 279
 }
280 280
 
281
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
282
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
283
-    $email_heading = __( $email_heading, 'invoicing' );
281
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
282
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
283
+    $email_heading = __($email_heading, 'invoicing');
284 284
 
285
-    $email_heading = wpinv_email_format_text( $email_heading, $invoice );
285
+    $email_heading = wpinv_email_format_text($email_heading, $invoice);
286 286
 
287
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
287
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
288 288
 }
289 289
 
290
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
291
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
292
-    $content    = __( $content, 'invoicing' );
290
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
291
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
292
+    $content    = __($content, 'invoicing');
293 293
 
294
-    $content    = wpinv_email_format_text( $content, $invoice );
294
+    $content    = wpinv_email_format_text($content, $invoice);
295 295
 
296
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
296
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
297 297
 }
298 298
 
299
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
299
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
300 300
     $from_name = wpinv_mail_get_from_address();
301 301
     $from_email = wpinv_mail_get_from_address();
302 302
     
303
-    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
303
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
304 304
     
305
-    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
306
-    $headers    .= "Reply-To: ". $from_email . "\r\n";
305
+    $headers    = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
306
+    $headers    .= "Reply-To: " . $from_email . "\r\n";
307 307
     $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
308 308
     
309
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
309
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
310 310
 }
311 311
 
312
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
312
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
313 313
     $attachments = array();
314 314
     
315
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
315
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
316 316
 }
317 317
 
318 318
 /**
319 319
  * Searches for and replaces certain placeholders in an email.
320 320
  */
321
-function wpinv_email_format_text( $content, $invoice ) {
321
+function wpinv_email_format_text($content, $invoice) {
322 322
 
323 323
     $replace_array = array(
324 324
         '{site_title}'      => wpinv_get_blogname(),
325
-        '{date}'            => date_i18n( get_option( 'date_format' ), (int) current_time( 'timestamp' ) ),
325
+        '{date}'            => date_i18n(get_option('date_format'), (int) current_time('timestamp')),
326 326
     );
327 327
 
328
-    $invoice = new WPInv_Invoice( $invoice );
328
+    $invoice = new WPInv_Invoice($invoice);
329 329
 
330
-    if ( $invoice->get_id() ) {
330
+    if ($invoice->get_id()) {
331 331
 
332 332
         $replace_array = array_merge(
333 333
             $replace_array, 
334 334
             array(
335
-                '{name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
336
-                '{full_name}'       => sanitize_text_field( $invoice->get_user_full_name() ),
337
-                '{first_name}'      => sanitize_text_field( $invoice->get_first_name() ),
338
-                '{last_name}'       => sanitize_text_field( $invoice->get_last_name() ),
339
-                '{email}'           => sanitize_email( $invoice->get_email() ),
340
-                '{invoice_number}'  => sanitize_text_field( $invoice->get_number() ),
341
-                '{invoice_total}'   => wpinv_price( wpinv_format_amount( $invoice->get_total( true ) ) ),
342
-                '{invoice_link}'    => esc_url( $invoice->get_view_url() ),
343
-                '{invoice_pay_link}'=> esc_url( $invoice->get_checkout_payment_url() ),
344
-                '{invoice_date}'    => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
345
-                '{invoice_due_date}'=> date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ),
346
-                '{invoice_quote}'   => sanitize_text_field( $invoice->get_type() ),
347
-                '{invoice_label}'   => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
348
-                '{is_was}'          => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
335
+                '{name}'            => sanitize_text_field($invoice->get_user_full_name()),
336
+                '{full_name}'       => sanitize_text_field($invoice->get_user_full_name()),
337
+                '{first_name}'      => sanitize_text_field($invoice->get_first_name()),
338
+                '{last_name}'       => sanitize_text_field($invoice->get_last_name()),
339
+                '{email}'           => sanitize_email($invoice->get_email()),
340
+                '{invoice_number}'  => sanitize_text_field($invoice->get_number()),
341
+                '{invoice_total}'   => wpinv_price(wpinv_format_amount($invoice->get_total(true))),
342
+                '{invoice_link}'    => esc_url($invoice->get_view_url()),
343
+                '{invoice_pay_link}'=> esc_url($invoice->get_checkout_payment_url()),
344
+                '{invoice_date}'    => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))),
345
+                '{invoice_due_date}'=> date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))),
346
+                '{invoice_quote}'   => sanitize_text_field($invoice->get_type()),
347
+                '{invoice_label}'   => sanitize_text_field(ucfirst($invoice->get_type())),
348
+                '{is_was}'          => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
349 349
             )
350 350
         );
351 351
 
352 352
     }
353 353
 
354 354
     // Let third party plugins filter the arra.
355
-    $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice );
355
+    $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice);
356 356
 
357
-    foreach ( $replace_array as $key => $value ) {
358
-        $content = str_replace( $key, $value, $content );
357
+    foreach ($replace_array as $key => $value) {
358
+        $content = str_replace($key, $value, $content);
359 359
     }
360 360
 
361
-    return apply_filters( 'wpinv_email_content_replace', $content );
361
+    return apply_filters('wpinv_email_content_replace', $content);
362 362
 }
363 363
 
364 364
 
365
-function wpinv_email_wrap_message( $message ) {
365
+function wpinv_email_wrap_message($message) {
366 366
     // Buffer
367 367
     ob_start();
368 368
 
369
-    do_action( 'wpinv_email_header' );
369
+    do_action('wpinv_email_header');
370 370
 
371
-    echo wpautop( wptexturize( $message ) );
371
+    echo wpautop(wptexturize($message));
372 372
 
373
-    do_action( 'wpinv_email_footer' );
373
+    do_action('wpinv_email_footer');
374 374
 
375 375
     // Get contents
376 376
     $message = ob_get_clean();
@@ -378,21 +378,21 @@  discard block
 block discarded – undo
378 378
     return $message;
379 379
 }
380 380
 
381
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type ) {
382
-    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
383
-        $date_format = get_option( 'date_format' );
384
-        $time_format = get_option( 'time_format' );
381
+function wpinv_add_notes_to_invoice_email($invoice, $email_type) {
382
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) {
383
+        $date_format = get_option('date_format');
384
+        $time_format = get_option('time_format');
385 385
         ?>
386 386
         <div id="wpinv-email-notes">
387
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
387
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
388 388
             <ol class="wpinv-notes-lists">
389 389
         <?php
390
-        foreach ( $invoice_notes as $note ) {
391
-            $note_time = strtotime( $note->comment_date );
390
+        foreach ($invoice_notes as $note) {
391
+            $note_time = strtotime($note->comment_date);
392 392
             ?>
393 393
             <li class="comment wpinv-note">
394
-            <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>
395
-            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
394
+            <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>
395
+            <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div>
396 396
             </li>
397 397
             <?php
398 398
         }
@@ -401,4 +401,4 @@  discard block
 block discarded – undo
401 401
         <?php
402 402
     }
403 403
 }
404
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
404
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +371 added lines, -371 removed lines patch added patch discarded remove patch
@@ -12,423 +12,423 @@
 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'                   => 'new_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_invoice'                   => 'user_invoice',
40
-				'getpaid_new_customer_note'             => 'user_note',
41
-				'getpaid_daily_maintenance'             => 'overdue',
42
-
43
-			)
44
-		);
45
-
46
-		$this->init_hooks();
47
-
48
-	}
49
-
50
-	/**
51
-	 * Registers email hooks.
52
-	 */
53
-	public function init_hooks() {
54
-
55
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
56
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
57
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
58
-
59
-			$email = new GetPaid_Notification_Email( $email_type );
60
-
61
-			if ( ! $email->is_active() ) {
62
-				continue;
63
-			}
64
-
65
-			if ( method_exists( $this, $email_type ) ) {
66
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
67
-				continue;
68
-			}
69
-
70
-			do_action( 'getpaid_invoice_notification_email_register_hook', $email );
71
-
72
-		}
73
-
74
-	}
75
-
76
-	/**
77
-	 * Filters invoice merge tags.
78
-	 *
79
-	 * @param array $merge_tags
80
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
81
-	 */
82
-	public function invoice_merge_tags( $merge_tags, $object ) {
83
-
84
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
85
-			return array_merge(
86
-				$merge_tags,
87
-				$this->get_invoice_merge_tags( $object )
88
-			);
89
-		}
90
-
91
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
92
-			return array_merge(
93
-				$merge_tags,
94
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
95
-			);
96
-		}
97
-
98
-		return $merge_tags;
99
-
100
-	}
101
-
102
-	/**
103
-	 * Generates invoice merge tags.
104
-	 *
105
-	 * @param WPInv_Invoice $invoice
106
-	 * @return array
107
-	 */
108
-	public function get_invoice_merge_tags( $invoice ) {
109
-
110
-		// Abort if it does not exist.
111
-		if ( ! $invoice->get_id() ) {
112
-			return array();
113
-		}
114
-
115
-		return array(
116
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
117
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
118
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
119
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
120
-			'{email}'               => sanitize_email( $invoice->get_email() ),
121
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
122
-			'{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
123
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
124
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
125
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
126
-			'{invoice_date}'        => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
127
-			'{invoice_due_date}'    => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ),
128
-			'{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
129
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
130
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
131
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
132
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
133
-		);
134
-
135
-	}
136
-
137
-	/**
138
-	 * Helper function to send an email.
139
-	 *
140
-	 * @param WPInv_Invoice $invoice
141
-	 * @param GetPaid_Notification_Email $email
142
-	 * @param string $type
143
-	 * @param string|array $recipients
144
-	 * @param array $extra_args Extra template args.
145
-	 */
146
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
147
-
148
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
149
-
150
-		$mailer     = new GetPaid_Notification_Email_Sender();
151
-		$merge_tags = $email->get_merge_tags();
152
-
153
-		$result = $mailer->send(
154
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
155
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
156
-			$email->get_content( $merge_tags, $extra_args ),
157
-			$email->get_attachments()
158
-		);
159
-
160
-		// Maybe send a copy to the admin.
161
-		if ( $email->include_admin_bcc() ) {
162
-			$mailer->send(
163
-				wpinv_get_admin_email(),
164
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
165
-				$email->get_content( $merge_tags ),
166
-				$email->get_attachments()
167
-			);
168
-		}
169
-
170
-		if ( ! $result ) {
171
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
172
-		}
173
-
174
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
175
-
176
-		return $result;
177
-	}
178
-
179
-	/**
180
-	 * Also send emails to any cc users.
181
-	 *
182
-	 * @param array $recipients
183
-	 * @param GetPaid_Notification_Email $email
184
-	 */
185
-	public function filter_email_recipients( $recipients, $email ) {
186
-
187
-		if ( ! $email->is_admin_email() ) {
188
-			$cc = $email->object->get_email_cc();
189
-
190
-			if ( ! empty( $cc ) ) {
191
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
192
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
193
-			}
194
-
195
-		}
196
-
197
-		return $recipients;
198
-
199
-	}
200
-
201
-	/**
202
-	 * Sends a new invoice notification.
203
-	 *
204
-	 * @param WPInv_Invoice $invoice
205
-	 */
206
-	public function new_invoice( $invoice ) {
207
-
208
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
209
-		$recipient = wpinv_get_admin_email();
210
-
211
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
212
-
213
-	}
214
-
215
-	/**
216
-	 * Sends a cancelled invoice notification.
217
-	 *
218
-	 * @param WPInv_Invoice $invoice
219
-	 */
220
-	public function cancelled_invoice( $invoice ) {
221
-
222
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
223
-		$recipient = wpinv_get_admin_email();
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'                   => 'new_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_invoice'                   => 'user_invoice',
40
+                'getpaid_new_customer_note'             => 'user_note',
41
+                'getpaid_daily_maintenance'             => 'overdue',
42
+
43
+            )
44
+        );
45
+
46
+        $this->init_hooks();
47
+
48
+    }
49
+
50
+    /**
51
+     * Registers email hooks.
52
+     */
53
+    public function init_hooks() {
54
+
55
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
56
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
57
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
58
+
59
+            $email = new GetPaid_Notification_Email( $email_type );
60
+
61
+            if ( ! $email->is_active() ) {
62
+                continue;
63
+            }
64
+
65
+            if ( method_exists( $this, $email_type ) ) {
66
+                add_action( $hook, array( $this, $email_type ), 100, 2 );
67
+                continue;
68
+            }
69
+
70
+            do_action( 'getpaid_invoice_notification_email_register_hook', $email );
71
+
72
+        }
73
+
74
+    }
75
+
76
+    /**
77
+     * Filters invoice merge tags.
78
+     *
79
+     * @param array $merge_tags
80
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
81
+     */
82
+    public function invoice_merge_tags( $merge_tags, $object ) {
83
+
84
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
85
+            return array_merge(
86
+                $merge_tags,
87
+                $this->get_invoice_merge_tags( $object )
88
+            );
89
+        }
90
+
91
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
92
+            return array_merge(
93
+                $merge_tags,
94
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
95
+            );
96
+        }
97
+
98
+        return $merge_tags;
99
+
100
+    }
101
+
102
+    /**
103
+     * Generates invoice merge tags.
104
+     *
105
+     * @param WPInv_Invoice $invoice
106
+     * @return array
107
+     */
108
+    public function get_invoice_merge_tags( $invoice ) {
109
+
110
+        // Abort if it does not exist.
111
+        if ( ! $invoice->get_id() ) {
112
+            return array();
113
+        }
114
+
115
+        return array(
116
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
117
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
118
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
119
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
120
+            '{email}'               => sanitize_email( $invoice->get_email() ),
121
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
122
+            '{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
123
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
124
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
125
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
126
+            '{invoice_date}'        => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
127
+            '{invoice_due_date}'    => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ),
128
+            '{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
129
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
130
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
131
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
132
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
133
+        );
134
+
135
+    }
136
+
137
+    /**
138
+     * Helper function to send an email.
139
+     *
140
+     * @param WPInv_Invoice $invoice
141
+     * @param GetPaid_Notification_Email $email
142
+     * @param string $type
143
+     * @param string|array $recipients
144
+     * @param array $extra_args Extra template args.
145
+     */
146
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
147
+
148
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
149
+
150
+        $mailer     = new GetPaid_Notification_Email_Sender();
151
+        $merge_tags = $email->get_merge_tags();
152
+
153
+        $result = $mailer->send(
154
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
155
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
156
+            $email->get_content( $merge_tags, $extra_args ),
157
+            $email->get_attachments()
158
+        );
159
+
160
+        // Maybe send a copy to the admin.
161
+        if ( $email->include_admin_bcc() ) {
162
+            $mailer->send(
163
+                wpinv_get_admin_email(),
164
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
165
+                $email->get_content( $merge_tags ),
166
+                $email->get_attachments()
167
+            );
168
+        }
169
+
170
+        if ( ! $result ) {
171
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
172
+        }
173
+
174
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
175
+
176
+        return $result;
177
+    }
178
+
179
+    /**
180
+     * Also send emails to any cc users.
181
+     *
182
+     * @param array $recipients
183
+     * @param GetPaid_Notification_Email $email
184
+     */
185
+    public function filter_email_recipients( $recipients, $email ) {
186
+
187
+        if ( ! $email->is_admin_email() ) {
188
+            $cc = $email->object->get_email_cc();
189
+
190
+            if ( ! empty( $cc ) ) {
191
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
192
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
193
+            }
194
+
195
+        }
196
+
197
+        return $recipients;
198
+
199
+    }
200
+
201
+    /**
202
+     * Sends a new invoice notification.
203
+     *
204
+     * @param WPInv_Invoice $invoice
205
+     */
206
+    public function new_invoice( $invoice ) {
207
+
208
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
209
+        $recipient = wpinv_get_admin_email();
210
+
211
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
212
+
213
+    }
214
+
215
+    /**
216
+     * Sends a cancelled invoice notification.
217
+     *
218
+     * @param WPInv_Invoice $invoice
219
+     */
220
+    public function cancelled_invoice( $invoice ) {
221
+
222
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
223
+        $recipient = wpinv_get_admin_email();
224 224
 
225
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
225
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
226 226
 
227
-	}
227
+    }
228 228
 
229
-	/**
230
-	 * Sends a failed invoice notification.
231
-	 *
232
-	 * @param WPInv_Invoice $invoice
233
-	 */
234
-	public function failed_invoice( $invoice ) {
229
+    /**
230
+     * Sends a failed invoice notification.
231
+     *
232
+     * @param WPInv_Invoice $invoice
233
+     */
234
+    public function failed_invoice( $invoice ) {
235 235
 
236
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
237
-		$recipient = wpinv_get_admin_email();
238
-
239
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
236
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
237
+        $recipient = wpinv_get_admin_email();
238
+
239
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
240 240
 
241
-	}
241
+    }
242 242
 
243
-	/**
244
-	 * Sends a notification whenever an invoice is put on hold.
245
-	 *
246
-	 * @param WPInv_Invoice $invoice
247
-	 */
248
-	public function onhold_invoice( $invoice ) {
243
+    /**
244
+     * Sends a notification whenever an invoice is put on hold.
245
+     *
246
+     * @param WPInv_Invoice $invoice
247
+     */
248
+    public function onhold_invoice( $invoice ) {
249 249
 
250
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
251
-		$recipient = $invoice->get_email();
250
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
251
+        $recipient = $invoice->get_email();
252 252
 
253
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
253
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
254 254
 
255
-	}
255
+    }
256 256
 
257
-	/**
258
-	 * Sends a notification whenever an invoice is marked as processing payment.
259
-	 *
260
-	 * @param WPInv_Invoice $invoice
261
-	 */
262
-	public function processing_invoice( $invoice ) {
257
+    /**
258
+     * Sends a notification whenever an invoice is marked as processing payment.
259
+     *
260
+     * @param WPInv_Invoice $invoice
261
+     */
262
+    public function processing_invoice( $invoice ) {
263 263
 
264
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
265
-		$recipient = $invoice->get_email();
264
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
265
+        $recipient = $invoice->get_email();
266 266
 
267
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
267
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
268 268
 
269
-	}
269
+    }
270 270
 
271
-	/**
272
-	 * Sends a notification whenever an invoice is paid.
273
-	 *
274
-	 * @param WPInv_Invoice $invoice
275
-	 */
276
-	public function completed_invoice( $invoice ) {
271
+    /**
272
+     * Sends a notification whenever an invoice is paid.
273
+     *
274
+     * @param WPInv_Invoice $invoice
275
+     */
276
+    public function completed_invoice( $invoice ) {
277 277
 
278
-		// (Maybe) abort if it is a renewal invoice.
279
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
280
-			return;
281
-		}
278
+        // (Maybe) abort if it is a renewal invoice.
279
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
280
+            return;
281
+        }
282 282
 
283
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
284
-		$recipient = $invoice->get_email();
283
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
284
+        $recipient = $invoice->get_email();
285 285
 
286
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
286
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
287 287
 
288
-	}
288
+    }
289 289
 
290
-	/**
291
-	 * Sends a notification whenever an invoice is refunded.
292
-	 *
293
-	 * @param WPInv_Invoice $invoice
294
-	 */
295
-	public function refunded_invoice( $invoice ) {
290
+    /**
291
+     * Sends a notification whenever an invoice is refunded.
292
+     *
293
+     * @param WPInv_Invoice $invoice
294
+     */
295
+    public function refunded_invoice( $invoice ) {
296 296
 
297
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
-		$recipient = $invoice->get_email();
297
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
298
+        $recipient = $invoice->get_email();
299 299
 
300
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
300
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
301 301
 
302
-	}
302
+    }
303 303
 
304
-	/**
305
-	 * Notifies a user about new invoices
306
-	 *
307
-	 * @param WPInv_Invoice $invoice
308
-	 */
309
-	public function user_invoice( $invoice ) {
304
+    /**
305
+     * Notifies a user about new invoices
306
+     *
307
+     * @param WPInv_Invoice $invoice
308
+     */
309
+    public function user_invoice( $invoice ) {
310 310
 
311
-		// Only send this email for invoices created via the admin page.
312
-		if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) {
313
-			return;
314
-		}
311
+        // Only send this email for invoices created via the admin page.
312
+        if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) {
313
+            return;
314
+        }
315 315
 
316
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
317
-		$recipient = $invoice->get_email();
316
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
317
+        $recipient = $invoice->get_email();
318 318
 
319
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
319
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
320 320
 
321
-	}
321
+    }
322 322
 
323
-	/**
324
-	 * Checks if an invoice is a payment form invoice.
325
-	 *
326
-	 * @param int $invoice
327
-	 * @return bool
328
-	 */
329
-	public function is_payment_form_invoice( $invoice ) {
330
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
331
-	}
323
+    /**
324
+     * Checks if an invoice is a payment form invoice.
325
+     *
326
+     * @param int $invoice
327
+     * @return bool
328
+     */
329
+    public function is_payment_form_invoice( $invoice ) {
330
+        return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
331
+    }
332 332
 
333
-	/**
334
-	 * Notifies admin about new invoice notes
335
-	 *
336
-	 * @param WPInv_Invoice $invoice
337
-	 * @param string $note
338
-	 */
339
-	public function user_note( $invoice, $note ) {
333
+    /**
334
+     * Notifies admin about new invoice notes
335
+     *
336
+     * @param WPInv_Invoice $invoice
337
+     * @param string $note
338
+     */
339
+    public function user_note( $invoice, $note ) {
340 340
 
341
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
-		$recipient = $invoice->get_email();
343
-
344
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
345
-
346
-	}
341
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
+        $recipient = $invoice->get_email();
343
+
344
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
345
+
346
+    }
347 347
 
348
-	/**
349
-	 * (Force) Sends overdue notices.
350
-	 *
351
-	 * @param WPInv_Invoice $invoice
352
-	 */
353
-	public function force_send_overdue_notice( $invoice ) {
354
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
355
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
356
-	}
357
-
358
-	/**
359
-	 * Sends overdue notices.
360
-	 *
361
-	 * @TODO: Create an invoices query class.
362
-	 */
363
-	public function overdue() {
364
-		global $wpdb;
365
-
366
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
367
-
368
-		// Fetch reminder days.
369
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
370
-
371
-		// Abort if non is set.
372
-		if ( empty( $reminder_days ) ) {
373
-			return;
374
-		}
375
-
376
-		// Retrieve date query.
377
-		$date_query = $this->get_date_query( $reminder_days );
378
-
379
-		// Invoices table.
380
-		$table = $wpdb->prefix . 'getpaid_invoices';
381
-
382
-		// Fetch invoices.
383
-		$invoices  = $wpdb->get_col(
384
-			"SELECT posts.ID FROM $wpdb->posts as posts
348
+    /**
349
+     * (Force) Sends overdue notices.
350
+     *
351
+     * @param WPInv_Invoice $invoice
352
+     */
353
+    public function force_send_overdue_notice( $invoice ) {
354
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
355
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
356
+    }
357
+
358
+    /**
359
+     * Sends overdue notices.
360
+     *
361
+     * @TODO: Create an invoices query class.
362
+     */
363
+    public function overdue() {
364
+        global $wpdb;
365
+
366
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
367
+
368
+        // Fetch reminder days.
369
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
370
+
371
+        // Abort if non is set.
372
+        if ( empty( $reminder_days ) ) {
373
+            return;
374
+        }
375
+
376
+        // Retrieve date query.
377
+        $date_query = $this->get_date_query( $reminder_days );
378
+
379
+        // Invoices table.
380
+        $table = $wpdb->prefix . 'getpaid_invoices';
381
+
382
+        // Fetch invoices.
383
+        $invoices  = $wpdb->get_col(
384
+            "SELECT posts.ID FROM $wpdb->posts as posts
385 385
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
386 386
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
387 387
 
388
-		foreach ( $invoices as $invoice ) {
388
+        foreach ( $invoices as $invoice ) {
389 389
 
390
-			// Only send this email for invoices created via the admin page.
391
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
392
-				$invoice       = new WPInv_Invoice( $invoice );
393
-				$email->object = $invoice;
390
+            // Only send this email for invoices created via the admin page.
391
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
392
+                $invoice       = new WPInv_Invoice( $invoice );
393
+                $email->object = $invoice;
394 394
 
395
-				if ( $invoice->needs_payment() ) {
396
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
397
-				}
395
+                if ( $invoice->needs_payment() ) {
396
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
397
+                }
398 398
 
399
-			}
399
+            }
400 400
 
401
-		}
401
+        }
402 402
 
403
-	}
403
+    }
404 404
 
405
-	/**
406
-	 * Calculates the date query for an invoices query
407
-	 *
408
-	 * @param array $reminder_days
409
-	 * @return string
410
-	 */
411
-	public function get_date_query( $reminder_days ) {
405
+    /**
406
+     * Calculates the date query for an invoices query
407
+     *
408
+     * @param array $reminder_days
409
+     * @return string
410
+     */
411
+    public function get_date_query( $reminder_days ) {
412 412
 
413
-		$date_query = array(
414
-			'relation'  => 'OR'
415
-		);
413
+        $date_query = array(
414
+            'relation'  => 'OR'
415
+        );
416 416
 
417
-		foreach ( $reminder_days as $days ) {
418
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
417
+        foreach ( $reminder_days as $days ) {
418
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
419 419
 
420
-			$date_query[] = array(
421
-				'year'  => $date['year'],
422
-				'month' => $date['month'],
423
-				'day'   => $date['day'],
424
-			);
420
+            $date_query[] = array(
421
+                'year'  => $date['year'],
422
+                'month' => $date['month'],
423
+                'day'   => $date['day'],
424
+            );
425 425
 
426
-		}
426
+        }
427 427
 
428
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
428
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
429 429
 
430
-		return $date_query->get_sql();
430
+        return $date_query->get_sql();
431 431
 
432
-	}
432
+    }
433 433
 
434 434
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 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.
@@ -52,22 +52,22 @@  discard block
 block discarded – undo
52 52
 	 */
53 53
 	public function init_hooks() {
54 54
 
55
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
56
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
57
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
55
+		add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2);
56
+		add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2);
57
+		foreach ($this->invoice_actions as $hook => $email_type) {
58 58
 
59
-			$email = new GetPaid_Notification_Email( $email_type );
59
+			$email = new GetPaid_Notification_Email($email_type);
60 60
 
61
-			if ( ! $email->is_active() ) {
61
+			if (!$email->is_active()) {
62 62
 				continue;
63 63
 			}
64 64
 
65
-			if ( method_exists( $this, $email_type ) ) {
66
-				add_action( $hook, array( $this, $email_type ), 100, 2 );
65
+			if (method_exists($this, $email_type)) {
66
+				add_action($hook, array($this, $email_type), 100, 2);
67 67
 				continue;
68 68
 			}
69 69
 
70
-			do_action( 'getpaid_invoice_notification_email_register_hook', $email );
70
+			do_action('getpaid_invoice_notification_email_register_hook', $email);
71 71
 
72 72
 		}
73 73
 
@@ -79,19 +79,19 @@  discard block
 block discarded – undo
79 79
 	 * @param array $merge_tags
80 80
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
81 81
 	 */
82
-	public function invoice_merge_tags( $merge_tags, $object ) {
82
+	public function invoice_merge_tags($merge_tags, $object) {
83 83
 
84
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
84
+		if (is_a($object, 'WPInv_Invoice')) {
85 85
 			return array_merge(
86 86
 				$merge_tags,
87
-				$this->get_invoice_merge_tags( $object )
87
+				$this->get_invoice_merge_tags($object)
88 88
 			);
89 89
 		}
90 90
 
91
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
91
+		if (is_a($object, 'WPInv_Subscription')) {
92 92
 			return array_merge(
93 93
 				$merge_tags,
94
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
94
+				$this->get_invoice_merge_tags($object->get_parent_payment())
95 95
 			);
96 96
 		}
97 97
 
@@ -105,31 +105,31 @@  discard block
 block discarded – undo
105 105
 	 * @param WPInv_Invoice $invoice
106 106
 	 * @return array
107 107
 	 */
108
-	public function get_invoice_merge_tags( $invoice ) {
108
+	public function get_invoice_merge_tags($invoice) {
109 109
 
110 110
 		// Abort if it does not exist.
111
-		if ( ! $invoice->get_id() ) {
111
+		if (!$invoice->get_id()) {
112 112
 			return array();
113 113
 		}
114 114
 
115 115
 		return array(
116
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
117
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
118
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
119
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
120
-			'{email}'               => sanitize_email( $invoice->get_email() ),
121
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
122
-			'{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
123
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
124
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
125
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
126
-			'{invoice_date}'        => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
127
-			'{invoice_due_date}'    => date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ),
128
-			'{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
129
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
130
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
131
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
132
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
116
+			'{name}'                => sanitize_text_field($invoice->get_user_full_name()),
117
+			'{full_name}'           => sanitize_text_field($invoice->get_user_full_name()),
118
+			'{first_name}'          => sanitize_text_field($invoice->get_first_name()),
119
+			'{last_name}'           => sanitize_text_field($invoice->get_last_name()),
120
+			'{email}'               => sanitize_email($invoice->get_email()),
121
+			'{invoice_number}'      => sanitize_text_field($invoice->get_number()),
122
+			'{invoice_total}'       => wpinv_price(wpinv_format_amount($invoice->get_total())),
123
+			'{invoice_link}'        => esc_url($invoice->get_view_url()),
124
+			'{invoice_pay_link}'    => esc_url($invoice->get_checkout_payment_url()),
125
+			'{invoice_receipt_link}'=> esc_url($invoice->get_receipt_url()),
126
+			'{invoice_date}'        => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))),
127
+			'{invoice_due_date}'    => date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))),
128
+			'{invoice_quote}'       => sanitize_text_field($invoice->get_type()),
129
+			'{invoice_label}'       => sanitize_text_field(ucfirst($invoice->get_type())),
130
+			'{invoice_description}' => wp_kses_post($invoice->get_description()),
131
+			'{subscription_name}'   => wp_kses_post($invoice->get_subscription_name()),
132
+			'{is_was}'              => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
133 133
 		);
134 134
 
135 135
 	}
@@ -143,35 +143,35 @@  discard block
 block discarded – undo
143 143
 	 * @param string|array $recipients
144 144
 	 * @param array $extra_args Extra template args.
145 145
 	 */
146
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
146
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
147 147
 
148
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
148
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
149 149
 
150 150
 		$mailer     = new GetPaid_Notification_Email_Sender();
151 151
 		$merge_tags = $email->get_merge_tags();
152 152
 
153 153
 		$result = $mailer->send(
154
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
155
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
156
-			$email->get_content( $merge_tags, $extra_args ),
154
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
155
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
156
+			$email->get_content($merge_tags, $extra_args),
157 157
 			$email->get_attachments()
158 158
 		);
159 159
 
160 160
 		// Maybe send a copy to the admin.
161
-		if ( $email->include_admin_bcc() ) {
161
+		if ($email->include_admin_bcc()) {
162 162
 			$mailer->send(
163 163
 				wpinv_get_admin_email(),
164
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
165
-				$email->get_content( $merge_tags ),
164
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
165
+				$email->get_content($merge_tags),
166 166
 				$email->get_attachments()
167 167
 			);
168 168
 		}
169 169
 
170
-		if ( ! $result ) {
171
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
170
+		if (!$result) {
171
+			$invoice->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);
172 172
 		}
173 173
 
174
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
174
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
175 175
 
176 176
 		return $result;
177 177
 	}
@@ -182,14 +182,14 @@  discard block
 block discarded – undo
182 182
 	 * @param array $recipients
183 183
 	 * @param GetPaid_Notification_Email $email
184 184
 	 */
185
-	public function filter_email_recipients( $recipients, $email ) {
185
+	public function filter_email_recipients($recipients, $email) {
186 186
 
187
-		if ( ! $email->is_admin_email() ) {
187
+		if (!$email->is_admin_email()) {
188 188
 			$cc = $email->object->get_email_cc();
189 189
 
190
-			if ( ! empty( $cc ) ) {
191
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
192
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
190
+			if (!empty($cc)) {
191
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
192
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
193 193
 			}
194 194
 
195 195
 		}
@@ -203,12 +203,12 @@  discard block
 block discarded – undo
203 203
 	 *
204 204
 	 * @param WPInv_Invoice $invoice
205 205
 	 */
206
-	public function new_invoice( $invoice ) {
206
+	public function new_invoice($invoice) {
207 207
 
208
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
208
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
209 209
 		$recipient = wpinv_get_admin_email();
210 210
 
211
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
211
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
212 212
 
213 213
 	}
214 214
 
@@ -217,12 +217,12 @@  discard block
 block discarded – undo
217 217
 	 *
218 218
 	 * @param WPInv_Invoice $invoice
219 219
 	 */
220
-	public function cancelled_invoice( $invoice ) {
220
+	public function cancelled_invoice($invoice) {
221 221
 
222
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
222
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
223 223
 		$recipient = wpinv_get_admin_email();
224 224
 
225
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
225
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
226 226
 
227 227
 	}
228 228
 
@@ -231,12 +231,12 @@  discard block
 block discarded – undo
231 231
 	 *
232 232
 	 * @param WPInv_Invoice $invoice
233 233
 	 */
234
-	public function failed_invoice( $invoice ) {
234
+	public function failed_invoice($invoice) {
235 235
 
236
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
236
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
237 237
 		$recipient = wpinv_get_admin_email();
238 238
 
239
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
239
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
240 240
 
241 241
 	}
242 242
 
@@ -245,12 +245,12 @@  discard block
 block discarded – undo
245 245
 	 *
246 246
 	 * @param WPInv_Invoice $invoice
247 247
 	 */
248
-	public function onhold_invoice( $invoice ) {
248
+	public function onhold_invoice($invoice) {
249 249
 
250
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
250
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
251 251
 		$recipient = $invoice->get_email();
252 252
 
253
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
253
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
254 254
 
255 255
 	}
256 256
 
@@ -259,12 +259,12 @@  discard block
 block discarded – undo
259 259
 	 *
260 260
 	 * @param WPInv_Invoice $invoice
261 261
 	 */
262
-	public function processing_invoice( $invoice ) {
262
+	public function processing_invoice($invoice) {
263 263
 
264
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
264
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
265 265
 		$recipient = $invoice->get_email();
266 266
 
267
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
267
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
268 268
 
269 269
 	}
270 270
 
@@ -273,17 +273,17 @@  discard block
 block discarded – undo
273 273
 	 *
274 274
 	 * @param WPInv_Invoice $invoice
275 275
 	 */
276
-	public function completed_invoice( $invoice ) {
276
+	public function completed_invoice($invoice) {
277 277
 
278 278
 		// (Maybe) abort if it is a renewal invoice.
279
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
279
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
280 280
 			return;
281 281
 		}
282 282
 
283
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
283
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
284 284
 		$recipient = $invoice->get_email();
285 285
 
286
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
286
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
287 287
 
288 288
 	}
289 289
 
@@ -292,12 +292,12 @@  discard block
 block discarded – undo
292 292
 	 *
293 293
 	 * @param WPInv_Invoice $invoice
294 294
 	 */
295
-	public function refunded_invoice( $invoice ) {
295
+	public function refunded_invoice($invoice) {
296 296
 
297
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
297
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
298 298
 		$recipient = $invoice->get_email();
299 299
 
300
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
300
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
301 301
 
302 302
 	}
303 303
 
@@ -306,17 +306,17 @@  discard block
 block discarded – undo
306 306
 	 *
307 307
 	 * @param WPInv_Invoice $invoice
308 308
 	 */
309
-	public function user_invoice( $invoice ) {
309
+	public function user_invoice($invoice) {
310 310
 
311 311
 		// Only send this email for invoices created via the admin page.
312
-		if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) {
312
+		if ($this->is_payment_form_invoice($invoice->get_id())) {
313 313
 			return;
314 314
 		}
315 315
 
316
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
316
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
317 317
 		$recipient = $invoice->get_email();
318 318
 
319
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
319
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
320 320
 
321 321
 	}
322 322
 
@@ -326,8 +326,8 @@  discard block
 block discarded – undo
326 326
 	 * @param int $invoice
327 327
 	 * @return bool
328 328
 	 */
329
-	public function is_payment_form_invoice( $invoice ) {
330
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
329
+	public function is_payment_form_invoice($invoice) {
330
+		return empty($_GET['getpaid-admin-action']) && 'payment_form' == get_post_meta($invoice, 'wpinv_created_via', true);
331 331
 	}
332 332
 
333 333
 	/**
@@ -336,12 +336,12 @@  discard block
 block discarded – undo
336 336
 	 * @param WPInv_Invoice $invoice
337 337
 	 * @param string $note
338 338
 	 */
339
-	public function user_note( $invoice, $note ) {
339
+	public function user_note($invoice, $note) {
340 340
 
341
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
341
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
342 342
 		$recipient = $invoice->get_email();
343 343
 
344
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
344
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
345 345
 
346 346
 	}
347 347
 
@@ -350,9 +350,9 @@  discard block
 block discarded – undo
350 350
 	 *
351 351
 	 * @param WPInv_Invoice $invoice
352 352
 	 */
353
-	public function force_send_overdue_notice( $invoice ) {
354
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
355
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
353
+	public function force_send_overdue_notice($invoice) {
354
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
355
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
356 356
 	}
357 357
 
358 358
 	/**
@@ -363,37 +363,37 @@  discard block
 block discarded – undo
363 363
 	public function overdue() {
364 364
 		global $wpdb;
365 365
 
366
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
366
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
367 367
 
368 368
 		// Fetch reminder days.
369
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
369
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
370 370
 
371 371
 		// Abort if non is set.
372
-		if ( empty( $reminder_days ) ) {
372
+		if (empty($reminder_days)) {
373 373
 			return;
374 374
 		}
375 375
 
376 376
 		// Retrieve date query.
377
-		$date_query = $this->get_date_query( $reminder_days );
377
+		$date_query = $this->get_date_query($reminder_days);
378 378
 
379 379
 		// Invoices table.
380 380
 		$table = $wpdb->prefix . 'getpaid_invoices';
381 381
 
382 382
 		// Fetch invoices.
383
-		$invoices  = $wpdb->get_col(
383
+		$invoices = $wpdb->get_col(
384 384
 			"SELECT posts.ID FROM $wpdb->posts as posts
385 385
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
386 386
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
387 387
 
388
-		foreach ( $invoices as $invoice ) {
388
+		foreach ($invoices as $invoice) {
389 389
 
390 390
 			// Only send this email for invoices created via the admin page.
391
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
392
-				$invoice       = new WPInv_Invoice( $invoice );
391
+			if (!$this->is_payment_form_invoice($invoice)) {
392
+				$invoice       = new WPInv_Invoice($invoice);
393 393
 				$email->object = $invoice;
394 394
 
395
-				if ( $invoice->needs_payment() ) {
396
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
395
+				if ($invoice->needs_payment()) {
396
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
397 397
 				}
398 398
 
399 399
 			}
@@ -408,14 +408,14 @@  discard block
 block discarded – undo
408 408
 	 * @param array $reminder_days
409 409
 	 * @return string
410 410
 	 */
411
-	public function get_date_query( $reminder_days ) {
411
+	public function get_date_query($reminder_days) {
412 412
 
413 413
 		$date_query = array(
414 414
 			'relation'  => 'OR'
415 415
 		);
416 416
 
417
-		foreach ( $reminder_days as $days ) {
418
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
417
+		foreach ($reminder_days as $days) {
418
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
419 419
 
420 420
 			$date_query[] = array(
421 421
 				'year'  => $date['year'],
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 
426 426
 		}
427 427
 
428
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
428
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
429 429
 
430 430
 		return $date_query->get_sql();
431 431
 
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 );
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}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ),
108
-			'{subscription_initial_amount}'   => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ),
109
-			'{subscription_recurring_period}' => strtolower( sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ) ),
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 );
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}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ),
108
+            '{subscription_initial_amount}'   => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ),
109
+            '{subscription_recurring_period}' => strtolower( sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ) ),
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 );
62
+			do_action('getpaid_subscription_notification_email_register_hook', $email);
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}' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ),
108
-			'{subscription_initial_amount}'   => wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $invoice->get_currency() ),
109
-			'{subscription_recurring_period}' => strtolower( sanitize_text_field( WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->get_period(), $subscription->get_frequency(), true ) ) ),
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}' => wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $invoice->get_currency()),
108
+			'{subscription_initial_amount}'   => wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $invoice->get_currency()),
109
+			'{subscription_recurring_period}' => strtolower(sanitize_text_field(WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->get_period(), $subscription->get_frequency(), true))),
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-daily-maintenance.php 2 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Daily_Maintenance {
14 14
 
15 15
     /**
16
-	 * Class constructor.
17
-	 */
16
+     * Class constructor.
17
+     */
18 18
     public function __construct(){
19 19
 
20 20
         // Clear deprecated events.
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
     }
31 31
 
32 32
     /**
33
-	 * Schedules a cron to run every day at 7 a.m
33
+     * Schedules a cron to run every day at 7 a.m
34 34
      *
35
-	 */
35
+     */
36 36
     public function maybe_create_scheduled_event() {
37 37
 
38 38
         if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
     }
44 44
 
45 45
     /**
46
-	 * Clears deprecated events.
46
+     * Clears deprecated events.
47 47
      *
48
-	 */
48
+     */
49 49
     public function maybe_clear_deprecated_events() {
50 50
 
51 51
         if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
@@ -57,24 +57,24 @@  discard block
 block discarded – undo
57 57
     }
58 58
 
59 59
     /**
60
-	 * Fires the old hook for backwards compatibility.
60
+     * Fires the old hook for backwards compatibility.
61 61
      *
62
-	 */
62
+     */
63 63
     public function backwards_compat() {
64 64
         do_action( 'wpinv_register_schedule_event_daily' );
65 65
     }
66 66
 
67 67
     /**
68
-	 * Expires expired subscriptions.
68
+     * Expires expired subscriptions.
69 69
      *
70
-	 */
70
+     */
71 71
     public function maybe_expire_subscriptions() {
72 72
 
73 73
         // Fetch expired subscriptions (skips those that expire today).
74 74
         $args  = array(
75 75
             'number'             => -1,
76
-			'count_total'        => false,
77
-			'status'             => 'trialling active failing cancelled',
76
+            'count_total'        => false,
77
+            'status'             => 'trialling active failing cancelled',
78 78
             'date_expires_query' => array(
79 79
                 'before'    => 'today',
80 80
                 'inclusive' => false,
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 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
  * Daily maintenance class.
@@ -15,17 +15,17 @@  discard block
 block discarded – undo
15 15
     /**
16 16
 	 * Class constructor.
17 17
 	 */
18
-    public function __construct(){
18
+    public function __construct() {
19 19
 
20 20
         // Clear deprecated events.
21
-        add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
21
+        add_action('wp', array($this, 'maybe_clear_deprecated_events'));
22 22
 
23 23
         // (Maybe) schedule a cron that runs daily.
24
-        add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
24
+        add_action('wp', array($this, 'maybe_create_scheduled_event'));
25 25
 
26 26
         // Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
-        add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
28
-        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
27
+        add_action('getpaid_daily_maintenance', array($this, 'backwards_compat'));
28
+        add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions'));
29 29
 
30 30
     }
31 31
 
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 	 */
36 36
     public function maybe_create_scheduled_event() {
37 37
 
38
-        if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
39
-            $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
40
-            wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
38
+        if (!wp_next_scheduled('getpaid_daily_maintenance')) {
39
+            $timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp'));
40
+            wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance');
41 41
         }
42 42
 
43 43
     }
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
 	 */
49 49
     public function maybe_clear_deprecated_events() {
50 50
 
51
-        if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
52
-            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
53
-            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
54
-            update_option( 'wpinv_cleared_old_events', 1 );
51
+        if (!get_option('wpinv_cleared_old_events')) {
52
+            wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily');
53
+            wp_clear_scheduled_hook('wpinv_register_schedule_event_daily');
54
+            update_option('wpinv_cleared_old_events', 1);
55 55
         }
56 56
         
57 57
     }
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      *
62 62
 	 */
63 63
     public function backwards_compat() {
64
-        do_action( 'wpinv_register_schedule_event_daily' );
64
+        do_action('wpinv_register_schedule_event_daily');
65 65
     }
66 66
 
67 67
     /**
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
     public function maybe_expire_subscriptions() {
72 72
 
73 73
         // Fetch expired subscriptions (skips those that expire today).
74
-        $args  = array(
74
+        $args = array(
75 75
             'number'             => -1,
76 76
 			'count_total'        => false,
77 77
 			'status'             => 'trialling active failing cancelled',
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
             ),
82 82
         );
83 83
 
84
-        $subscriptions = new GetPaid_Subscriptions_Query( $args );
84
+        $subscriptions = new GetPaid_Subscriptions_Query($args);
85 85
 
86
-        foreach ( $subscriptions as $subscription ) {
87
-            $subscription->set_status( 'expired' );
86
+        foreach ($subscriptions as $subscription) {
87
+            $subscription->set_status('expired');
88 88
             $subscription->save();
89 89
         }
90 90
 
Please login to merge, or discard this patch.
includes/class-getpaid-notification-email.php 1 patch
Spacing   +30 added lines, -30 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
  * Represents a single email type.
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      * @param string $id Email Type.
33 33
      * @param mixed $object Optional. Associated object.
34 34
 	 */
35
-	public function __construct( $id, $object = false ) {
35
+	public function __construct($id, $object = false) {
36 36
         $this->id     = $id;
37 37
         $this->object = $object;
38 38
     }
@@ -42,19 +42,19 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
      * @return mixed
44 44
 	 */
45
-	public function get_option( $key ) {
45
+	public function get_option($key) {
46 46
 
47 47
         $key   = "email_{$this->id}_$key";
48
-        $value = wpinv_get_option( $key, null );
48
+        $value = wpinv_get_option($key, null);
49 49
 
50
-        if ( is_null( $value ) ) {
50
+        if (is_null($value)) {
51 51
             $options = wpinv_get_emails();
52 52
 
53
-            if ( ! isset( $options[ $this->id ] ) || ! isset( $options[ $this->id ][ $key ] ) ) {
53
+            if (!isset($options[$this->id]) || !isset($options[$this->id][$key])) {
54 54
                 return '';
55 55
             }
56 56
 
57
-            $value = isset( $options[ $this->id ][ $key ]['std'] ) ? $options[ $this->id ][ $key ]['std'] : '';
57
+            $value = isset($options[$this->id][$key]['std']) ? $options[$this->id][$key]['std'] : '';
58 58
         }
59 59
 
60 60
         return $value;
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
      * @return string
67 67
 	 */
68 68
 	public function get_body() {
69
-        $body = $this->get_option( 'body' );
70
-        return apply_filters( 'getpaid_get_email_body', $body, $this->id, $this->object );
69
+        $body = $this->get_option('body');
70
+        return apply_filters('getpaid_get_email_body', $body, $this->id, $this->object);
71 71
     }
72 72
 
73 73
     /**
@@ -76,8 +76,8 @@  discard block
 block discarded – undo
76 76
      * @return string
77 77
 	 */
78 78
 	public function get_subject() {
79
-        $subject = $this->get_option( 'subject' );
80
-        return apply_filters( 'getpaid_get_email_subject', $subject, $this->id, $this->object );
79
+        $subject = $this->get_option('subject');
80
+        return apply_filters('getpaid_get_email_subject', $subject, $this->id, $this->object);
81 81
     }
82 82
 
83 83
     /**
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
      * @return string
87 87
 	 */
88 88
 	public function get_heading() {
89
-        $heading = $this->get_option( 'heading' );
90
-        return apply_filters( 'getpaid_get_email_heading', $heading, $this->id, $this->object );
89
+        $heading = $this->get_option('heading');
90
+        return apply_filters('getpaid_get_email_heading', $heading, $this->id, $this->object);
91 91
     }
92 92
 
93 93
     /**
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
      * @return bool
97 97
 	 */
98 98
 	public function is_active() {
99
-        $is_active = ! empty( $this->get_option( 'is_active' ) );
100
-        return apply_filters( 'getpaid_email_type_is_active', $is_active, $this->id, $this->object );
99
+        $is_active = !empty($this->get_option('is_active'));
100
+        return apply_filters('getpaid_email_type_is_active', $is_active, $this->id, $this->object);
101 101
     }
102 102
 
103 103
     /**
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
      * @return bool
107 107
 	 */
108 108
 	public function include_admin_bcc() {
109
-        $include_admin_bcc = ! empty( $this->get_option( 'admin_bcc' ) );
110
-        return apply_filters( 'getpaid_email_type_include_admin_bcc', $include_admin_bcc, $this->id, $this->object );
109
+        $include_admin_bcc = !empty($this->get_option('admin_bcc'));
110
+        return apply_filters('getpaid_email_type_include_admin_bcc', $include_admin_bcc, $this->id, $this->object);
111 111
     }
112 112
 
113 113
     /**
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
      * @return bool
117 117
 	 */
118 118
 	public function is_admin_email() {
119
-        $is_admin_email = in_array( $this->id, array( 'new_invoice', 'cancelled_invoice', 'failed_invoice' ) );
120
-        return apply_filters( 'getpaid_email_type_is_admin_email', $is_admin_email, $this->id, $this->object );
119
+        $is_admin_email = in_array($this->id, array('new_invoice', 'cancelled_invoice', 'failed_invoice'));
120
+        return apply_filters('getpaid_email_type_is_admin_email', $is_admin_email, $this->id, $this->object);
121 121
     }
122 122
 
123 123
     /**
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
      * @return array
127 127
 	 */
128 128
 	public function get_attachments() {
129
-        return apply_filters( 'getpaid_get_email_attachments', array(), $this->id, $this->object );
129
+        return apply_filters('getpaid_get_email_attachments', array(), $this->id, $this->object);
130 130
     }
131 131
 
132 132
     /**
@@ -138,10 +138,10 @@  discard block
 block discarded – undo
138 138
 
139 139
         $merge_tags = array(
140 140
             '{site_title}' => wpinv_get_blogname(),
141
-            '{date}'       => date_i18n( get_option( 'date_format' ), current_time( 'timestamp' ) ),
141
+            '{date}'       => date_i18n(get_option('date_format'), current_time('timestamp')),
142 142
         );
143 143
 
144
-        return apply_filters( 'getpaid_get_email_merge_tags', $merge_tags, $this->object, $this->id );
144
+        return apply_filters('getpaid_get_email_merge_tags', $merge_tags, $this->object, $this->id);
145 145
     }
146 146
 
147 147
     /**
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
      * @param array $merge_tags
152 152
      * @return string
153 153
 	 */
154
-	public function add_merge_tags( $text, $merge_tags = array() ) {
154
+	public function add_merge_tags($text, $merge_tags = array()) {
155 155
 
156
-        foreach ( $merge_tags as $key => $value ) {
157
-            $text = str_replace( $key, $value, $text );
156
+        foreach ($merge_tags as $key => $value) {
157
+            $text = str_replace($key, $value, $text);
158 158
         }
159 159
 
160
-        return wptexturize( $text );
160
+        return wptexturize($text);
161 161
     }
162 162
 
163 163
     /**
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
      * @param array $extra_args Extra template args
168 168
      * @return string
169 169
 	 */
170
-	public function get_content( $merge_tags = array(), $extra_args = array() ) {
170
+	public function get_content($merge_tags = array(), $extra_args = array()) {
171 171
 
172 172
         $content = wpinv_get_template_html(
173 173
             "emails/wpinv-email-{$this->id}.php",
@@ -177,15 +177,15 @@  discard block
 block discarded – undo
177 177
                     'invoice'       => $this->object, // Backwards compat.
178 178
                     'object'        => $this->object,
179 179
                     'email_type'    => $this->id,
180
-                    'email_heading' => $this->add_merge_tags( $this->get_heading(), $merge_tags ),
180
+                    'email_heading' => $this->add_merge_tags($this->get_heading(), $merge_tags),
181 181
                     'sent_to_admin' => $this->is_admin_email(),
182 182
                     'plain_text'    => false,
183
-                    'message_body'  => wpautop( $this->add_merge_tags( $this->get_body(), $merge_tags ) ),
183
+                    'message_body'  => wpautop($this->add_merge_tags($this->get_body(), $merge_tags)),
184 184
                 )
185 185
             )
186 186
         );
187 187
 
188
-        return wpinv_email_style_body( $content );
188
+        return wpinv_email_style_body($content);
189 189
     }
190 190
 
191 191
 }
Please login to merge, or discard this patch.