Passed
Push — master ( 1ce22f...41fbb9 )
by Brian
09:44 queued 04:28
created
includes/wpinv-helper-functions.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
  */
82 82
 function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
83 83
 
84
-	$invoice_statuses = array(
85
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
84
+    $invoice_statuses = array(
85
+        'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
86 86
         'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
87 87
         'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
88
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
89
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
90
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
88
+        'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
89
+        'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
90
+        'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
91 91
         'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
92 92
         'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
93 93
     );
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
         $invoice = $invoice->get_post_type();
105 105
     }
106 106
 
107
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
107
+    return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
108 108
 }
109 109
 
110 110
 /**
@@ -222,25 +222,25 @@  discard block
 block discarded – undo
222 222
  * @return string
223 223
  */
224 224
 function getpaid_get_price_format() {
225
-	$currency_pos = wpinv_currency_position();
226
-	$format       = '%1$s%2$s';
225
+    $currency_pos = wpinv_currency_position();
226
+    $format       = '%1$s%2$s';
227 227
 
228
-	switch ( $currency_pos ) {
229
-		case 'left':
230
-			$format = '%1$s%2$s';
231
-			break;
232
-		case 'right':
233
-			$format = '%2$s%1$s';
234
-			break;
235
-		case 'left_space':
236
-			$format = '%1$s %2$s';
237
-			break;
238
-		case 'right_space':
239
-			$format = '%2$s %1$s';
240
-			break;
241
-	}
228
+    switch ( $currency_pos ) {
229
+        case 'left':
230
+            $format = '%1$s%2$s';
231
+            break;
232
+        case 'right':
233
+            $format = '%2$s%1$s';
234
+            break;
235
+        case 'left_space':
236
+            $format = '%1$s %2$s';
237
+            break;
238
+        case 'right_space':
239
+            $format = '%2$s %1$s';
240
+            break;
241
+    }
242 242
 
243
-	return apply_filters( 'getpaid_price_format', $format, $currency_pos );
243
+    return apply_filters( 'getpaid_price_format', $format, $currency_pos );
244 244
 }
245 245
 
246 246
 /**
@@ -343,13 +343,13 @@  discard block
 block discarded – undo
343 343
  * @param mixed  $value Value.
344 344
  */
345 345
 function getpaid_maybe_define_constant( $name, $value ) {
346
-	if ( ! defined( $name ) ) {
347
-		define( $name, $value );
348
-	}
346
+    if ( ! defined( $name ) ) {
347
+        define( $name, $value );
348
+    }
349 349
 }
350 350
 
351 351
 function wpinv_get_php_arg_separator_output() {
352
-	return ini_get( 'arg_separator.output' );
352
+    return ini_get( 'arg_separator.output' );
353 353
 }
354 354
 
355 355
 function wpinv_rgb_from_hex( $color ) {
@@ -700,11 +700,11 @@  discard block
 block discarded – undo
700 700
         $list = array();
701 701
     }
702 702
 
703
-	if ( ! is_array( $list ) ) {
704
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
705
-	}
703
+    if ( ! is_array( $list ) ) {
704
+        return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
705
+    }
706 706
 
707
-	return $list;
707
+    return $list;
708 708
 }
709 709
 
710 710
 /**
@@ -724,9 +724,9 @@  discard block
 block discarded – undo
724 724
     }
725 725
 
726 726
     $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
727
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
727
+    wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
728 728
 
729
-	return $data;
729
+    return $data;
730 730
 }
731 731
 
732 732
 /**
@@ -755,17 +755,17 @@  discard block
 block discarded – undo
755 755
  */
756 756
 function wpinv_clean( $var ) {
757 757
 
758
-	if ( is_array( $var ) ) {
759
-		return array_map( 'wpinv_clean', $var );
758
+    if ( is_array( $var ) ) {
759
+        return array_map( 'wpinv_clean', $var );
760 760
     }
761 761
 
762 762
     if ( is_object( $var ) ) {
763
-		$object_vars = get_object_vars( $var );
764
-		foreach ( $object_vars as $property_name => $property_value ) {
765
-			$var->$property_name = wpinv_clean( $property_value );
763
+        $object_vars = get_object_vars( $var );
764
+        foreach ( $object_vars as $property_name => $property_value ) {
765
+            $var->$property_name = wpinv_clean( $property_value );
766 766
         }
767 767
         return $var;
768
-	}
768
+    }
769 769
     
770 770
     return is_string( $var ) ? sanitize_text_field( $var ) : $var;
771 771
 }
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
  */
779 779
 function getpaid_convert_price_string_to_options( $str ) {
780 780
 
781
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
781
+    $raw_options = array_map( 'trim', explode( ',', $str ) );
782 782
     $options     = array();
783 783
 
784 784
     foreach ( $raw_options as $option ) {
@@ -856,7 +856,7 @@  discard block
 block discarded – undo
856 856
  * @return string
857 857
  */
858 858
 function getpaid_date_format() {
859
-	return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
859
+    return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
860 860
 }
861 861
 
862 862
 /**
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
  * @return string
866 866
  */
867 867
 function getpaid_time_format() {
868
-	return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
868
+    return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
869 869
 }
870 870
 
871 871
 /**
@@ -878,15 +878,15 @@  discard block
 block discarded – undo
878 878
 function getpaid_limit_length( $string, $limit ) {
879 879
     $str_limit = $limit - 3;
880 880
 
881
-	if ( function_exists( 'mb_strimwidth' ) ) {
882
-		if ( mb_strlen( $string ) > $limit ) {
883
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
884
-		}
885
-	} else {
886
-		if ( strlen( $string ) > $limit ) {
887
-			$string = substr( $string, 0, $str_limit ) . '...';
888
-		}
889
-	}
881
+    if ( function_exists( 'mb_strimwidth' ) ) {
882
+        if ( mb_strlen( $string ) > $limit ) {
883
+            $string = mb_strimwidth( $string, 0, $str_limit ) . '...';
884
+        }
885
+    } else {
886
+        if ( strlen( $string ) > $limit ) {
887
+            $string = substr( $string, 0, $str_limit ) . '...';
888
+        }
889
+    }
890 890
     return $string;
891 891
 
892 892
 }
Please login to merge, or discard this patch.
Spacing   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Are we supporting item quantities?
@@ -20,35 +20,35 @@  discard block
 block discarded – undo
20 20
  */
21 21
 function wpinv_get_ip() {
22 22
 
23
-    if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) {
24
-        return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) );
23
+    if (isset($_SERVER['HTTP_X_REAL_IP'])) {
24
+        return sanitize_text_field(wp_unslash($_SERVER['HTTP_X_REAL_IP']));
25 25
     }
26 26
 
27
-    if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
27
+    if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
28 28
         // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2
29 29
         // Make sure we always only send through the first IP in the list which should always be the client IP.
30
-        return (string) rest_is_ip_address( trim( current( preg_split( '/,/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) );
30
+        return (string) rest_is_ip_address(trim(current(preg_split('/,/', sanitize_text_field(wp_unslash($_SERVER['HTTP_X_FORWARDED_FOR']))))));
31 31
     }
32 32
 
33
-    if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
34
-        return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) );
33
+    if (isset($_SERVER['HTTP_CLIENT_IP'])) {
34
+        return sanitize_text_field(wp_unslash($_SERVER['HTTP_CLIENT_IP']));
35 35
     }
36 36
 
37
-    if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
38
-        return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) );
37
+    if (isset($_SERVER['REMOTE_ADDR'])) {
38
+        return sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR']));
39 39
     }
40 40
 
41 41
     return '';
42 42
 }
43 43
 
44 44
 function wpinv_get_user_agent() {
45
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
46
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
45
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
46
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
47 47
     } else {
48 48
         $user_agent = '';
49 49
     }
50 50
 
51
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
51
+    return apply_filters('wpinv_get_user_agent', $user_agent);
52 52
 }
53 53
 
54 54
 /**
@@ -56,27 +56,27 @@  discard block
 block discarded – undo
56 56
  * 
57 57
  * @param string $amount The amount to sanitize.
58 58
  */
59
-function wpinv_sanitize_amount( $amount ) {
59
+function wpinv_sanitize_amount($amount) {
60 60
 
61 61
     // Format decimals.
62
-    $amount = str_replace( wpinv_decimal_separator(), '.', $amount );
62
+    $amount = str_replace(wpinv_decimal_separator(), '.', $amount);
63 63
 
64 64
     // Remove thousands.
65
-    $amount = str_replace( wpinv_thousands_separator(), '', $amount );
65
+    $amount = str_replace(wpinv_thousands_separator(), '', $amount);
66 66
 
67 67
     // Cast the remaining to a float.
68
-    return (float) preg_replace( '/[^0-9\.\-]/', '', $amount );
68
+    return (float) preg_replace('/[^0-9\.\-]/', '', $amount);
69 69
 
70 70
 }
71 71
 
72
-function wpinv_round_amount( $amount, $decimals = NULL ) {
73
-    if ( $decimals === NULL ) {
72
+function wpinv_round_amount($amount, $decimals = NULL) {
73
+    if ($decimals === NULL) {
74 74
         $decimals = wpinv_decimals();
75 75
     }
76 76
     
77
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
77
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
78 78
 
79
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
79
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
80 80
 }
81 81
 
82 82
 /**
@@ -88,32 +88,32 @@  discard block
 block discarded – undo
88 88
  * @param string|WPInv_Invoice $invoice The invoice object|post type|type
89 89
  * @return array
90 90
  */
91
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
91
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
92 92
 
93 93
 	$invoice_statuses = array(
94
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
95
-        'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
96
-        'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
97
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
98
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
99
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
100
-        'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
101
-        'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
94
+		'wpi-pending'    => _x('Pending payment', 'Invoice status', 'invoicing'),
95
+        'publish'        => _x('Paid', 'Invoice status', 'invoicing'),
96
+        'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'),
97
+		'wpi-onhold'     => _x('On hold', 'Invoice status', 'invoicing'),
98
+		'wpi-cancelled'  => _x('Cancelled', 'Invoice status', 'invoicing'),
99
+		'wpi-refunded'   => _x('Refunded', 'Invoice status', 'invoicing'),
100
+        'wpi-failed'     => _x('Failed', 'Invoice status', 'invoicing'),
101
+        'wpi-renewal'    => _x('Renewal Payment', 'Invoice status', 'invoicing'),
102 102
     );
103 103
 
104
-    if ( $draft ) {
105
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
104
+    if ($draft) {
105
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
106 106
     }
107 107
 
108
-    if ( $trashed ) {
109
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
108
+    if ($trashed) {
109
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
110 110
     }
111 111
 
112
-    if ( $invoice instanceof WPInv_Invoice ) {
112
+    if ($invoice instanceof WPInv_Invoice) {
113 113
         $invoice = $invoice->get_post_type();
114 114
     }
115 115
 
116
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
116
+	return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
117 117
 }
118 118
 
119 119
 /**
@@ -122,11 +122,11 @@  discard block
 block discarded – undo
122 122
  * @param string $status The raw status
123 123
  * @param string|WPInv_Invoice $invoice The invoice object|post type|type
124 124
  */
125
-function wpinv_status_nicename( $status, $invoice = false ) {
126
-    $statuses = wpinv_get_invoice_statuses( true, true, $invoice );
127
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : $status;
125
+function wpinv_status_nicename($status, $invoice = false) {
126
+    $statuses = wpinv_get_invoice_statuses(true, true, $invoice);
127
+    $status   = isset($statuses[$status]) ? $statuses[$status] : $status;
128 128
 
129
-    return sanitize_text_field( $status );
129
+    return sanitize_text_field($status);
130 130
 }
131 131
 
132 132
 /**
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
  * 
135 135
  * @param string $current
136 136
  */
137
-function wpinv_get_currency( $current = '' ) {
137
+function wpinv_get_currency($current = '') {
138 138
 
139
-    if ( empty( $current ) ) {
140
-        $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) );
139
+    if (empty($current)) {
140
+        $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD'));
141 141
     }
142 142
 
143
-    return trim( strtoupper( $current ) );
143
+    return trim(strtoupper($current));
144 144
 }
145 145
 
146 146
 /**
@@ -148,25 +148,25 @@  discard block
 block discarded – undo
148 148
  * 
149 149
  * @param string|null $currency The currency code. Defaults to the default currency.
150 150
  */
151
-function wpinv_currency_symbol( $currency = null ) {
151
+function wpinv_currency_symbol($currency = null) {
152 152
 
153 153
     // Prepare the currency.
154
-    $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency );
154
+    $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency);
155 155
 
156 156
     // Fetch all symbols.
157 157
     $symbols = wpinv_get_currency_symbols();
158 158
 
159 159
     // Fetch this currencies symbol.
160
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
160
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
161 161
 
162 162
     // Filter the symbol.
163
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
163
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
164 164
 }
165 165
 
166 166
 function wpinv_currency_position() {
167
-    $position = wpinv_get_option( 'currency_position', 'left' );
167
+    $position = wpinv_get_option('currency_position', 'left');
168 168
     
169
-    return apply_filters( 'wpinv_currency_position', $position );
169
+    return apply_filters('wpinv_currency_position', $position);
170 170
 }
171 171
 
172 172
 /**
@@ -174,13 +174,13 @@  discard block
 block discarded – undo
174 174
  * 
175 175
  * @param $string|null $current
176 176
  */
177
-function wpinv_thousands_separator( $current = null ) {
177
+function wpinv_thousands_separator($current = null) {
178 178
 
179
-    if ( null == $current ) {
180
-        $current = wpinv_get_option( 'thousands_separator', '.' );
179
+    if (null == $current) {
180
+        $current = wpinv_get_option('thousands_separator', '.');
181 181
     }
182 182
 
183
-    return trim( $current );
183
+    return trim($current);
184 184
 }
185 185
 
186 186
 /**
@@ -188,13 +188,13 @@  discard block
 block discarded – undo
188 188
  * 
189 189
  * @param $string|null $current
190 190
  */
191
-function wpinv_decimal_separator( $current = null ) {
191
+function wpinv_decimal_separator($current = null) {
192 192
 
193
-    if ( null == $current ) {
194
-        $current = wpinv_get_option( 'decimal_separator', '.' );
193
+    if (null == $current) {
194
+        $current = wpinv_get_option('decimal_separator', '.');
195 195
     }
196 196
     
197
-    return trim( $current );
197
+    return trim($current);
198 198
 }
199 199
 
200 200
 /**
@@ -202,27 +202,27 @@  discard block
 block discarded – undo
202 202
  * 
203 203
  * @param $string|null $current
204 204
  */
205
-function wpinv_decimals( $current = null ) {
205
+function wpinv_decimals($current = null) {
206 206
 
207
-    if ( null == $current ) {
208
-        $current = wpinv_get_option( 'decimals', 2 );
207
+    if (null == $current) {
208
+        $current = wpinv_get_option('decimals', 2);
209 209
     }
210 210
     
211
-    return absint( $current );
211
+    return absint($current);
212 212
 }
213 213
 
214 214
 /**
215 215
  * Retrieves a list of all supported currencies.
216 216
  */
217 217
 function wpinv_get_currencies() {
218
-    return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) );
218
+    return apply_filters('wpinv_currencies', wpinv_get_data('currencies'));
219 219
 }
220 220
 
221 221
 /**
222 222
  * Retrieves a list of all currency symbols.
223 223
  */
224 224
 function wpinv_get_currency_symbols() {
225
-    return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) );
225
+    return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols'));
226 226
 }
227 227
 
228 228
 /**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 	$currency_pos = wpinv_currency_position();
235 235
 	$format       = '%1$s%2$s';
236 236
 
237
-	switch ( $currency_pos ) {
237
+	switch ($currency_pos) {
238 238
 		case 'left':
239 239
 			$format = '%1$s%2$s';
240 240
 			break;
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 			break;
250 250
 	}
251 251
 
252
-	return apply_filters( 'getpaid_price_format', $format, $currency_pos );
252
+	return apply_filters('getpaid_price_format', $format, $currency_pos);
253 253
 }
254 254
 
255 255
 /**
@@ -259,25 +259,25 @@  discard block
 block discarded – undo
259 259
  * @param  string $currency Currency.
260 260
  * @return string
261 261
  */
262
-function wpinv_price( $amount = 0, $currency = '' ) {
262
+function wpinv_price($amount = 0, $currency = '') {
263 263
 
264 264
     // Backwards compatibility.
265
-    $amount             = floatval( wpinv_sanitize_amount( $amount ) );
265
+    $amount             = floatval(wpinv_sanitize_amount($amount));
266 266
 
267 267
     // Prepare variables.
268
-    $currency           = wpinv_get_currency( $currency );
268
+    $currency           = wpinv_get_currency($currency);
269 269
     $amount             = (float) $amount;
270 270
     $unformatted_amount = $amount;
271 271
     $negative           = $amount < 0;
272
-    $amount             = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) );
273
-    $amount             = wpinv_format_amount( $amount );
272
+    $amount             = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount));
273
+    $amount             = wpinv_format_amount($amount);
274 274
 
275 275
     // Format the amount.
276 276
     $format             = getpaid_get_price_format();
277
-    $formatted_amount   = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount );
277
+    $formatted_amount   = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount);
278 278
 
279 279
     // Filter the formatting.
280
-    return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount );
280
+    return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount);
281 281
 }
282 282
 
283 283
 /**
@@ -288,33 +288,33 @@  discard block
 block discarded – undo
288 288
  * @param  bool     $calculate Whether or not to apply separators.
289 289
  * @return string
290 290
  */
291
-function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) {
291
+function wpinv_format_amount($amount, $decimals = null, $calculate = false) {
292 292
     $thousands_sep = wpinv_thousands_separator();
293 293
     $decimal_sep   = wpinv_decimal_separator();
294
-    $decimals      = wpinv_decimals( $decimals );
294
+    $decimals      = wpinv_decimals($decimals);
295 295
 
296 296
     // Format decimals.
297
-    $amount = str_replace( $decimal_sep, '.', $amount );
297
+    $amount = str_replace($decimal_sep, '.', $amount);
298 298
 
299 299
     // Remove thousands.
300
-    $amount = str_replace( $thousands_sep, '', $amount );
300
+    $amount = str_replace($thousands_sep, '', $amount);
301 301
 
302 302
     // Cast the remaining to a float.
303
-    $amount = floatval( $amount );
303
+    $amount = floatval($amount);
304 304
 
305
-    if ( $calculate ) {
305
+    if ($calculate) {
306 306
         return $amount;
307 307
     }
308 308
 
309 309
     // Fomart the amount.
310
-    return number_format( $amount, $decimals, $decimal_sep, $thousands_sep );
310
+    return number_format($amount, $decimals, $decimal_sep, $thousands_sep);
311 311
 }
312 312
 
313
-function wpinv_sanitize_key( $key ) {
313
+function wpinv_sanitize_key($key) {
314 314
     $raw_key = $key;
315
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
315
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
316 316
 
317
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
317
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
318 318
 }
319 319
 
320 320
 /**
@@ -322,8 +322,8 @@  discard block
 block discarded – undo
322 322
  * 
323 323
  * @param $str the file whose extension should be retrieved.
324 324
  */
325
-function wpinv_get_file_extension( $str ) {
326
-    $filetype = wp_check_filetype( $str );
325
+function wpinv_get_file_extension($str) {
326
+    $filetype = wp_check_filetype($str);
327 327
     return $filetype['ext'];
328 328
 }
329 329
 
@@ -332,16 +332,16 @@  discard block
 block discarded – undo
332 332
  * 
333 333
  * @param string $string
334 334
  */
335
-function wpinv_string_is_image_url( $string ) {
336
-    $extension = strtolower( wpinv_get_file_extension( $string ) );
337
-    return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true );
335
+function wpinv_string_is_image_url($string) {
336
+    $extension = strtolower(wpinv_get_file_extension($string));
337
+    return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true);
338 338
 }
339 339
 
340 340
 /**
341 341
  * Returns the current URL.
342 342
  */
343 343
 function wpinv_get_current_page_url() {
344
-    return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
344
+    return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
345 345
 }
346 346
 
347 347
 /**
@@ -351,46 +351,46 @@  discard block
 block discarded – undo
351 351
  * @param string $name  Constant name.
352 352
  * @param mixed  $value Value.
353 353
  */
354
-function getpaid_maybe_define_constant( $name, $value ) {
355
-	if ( ! defined( $name ) ) {
356
-		define( $name, $value );
354
+function getpaid_maybe_define_constant($name, $value) {
355
+	if (!defined($name)) {
356
+		define($name, $value);
357 357
 	}
358 358
 }
359 359
 
360 360
 function wpinv_get_php_arg_separator_output() {
361
-	return ini_get( 'arg_separator.output' );
361
+	return ini_get('arg_separator.output');
362 362
 }
363 363
 
364
-function wpinv_rgb_from_hex( $color ) {
365
-    $color = str_replace( '#', '', $color );
364
+function wpinv_rgb_from_hex($color) {
365
+    $color = str_replace('#', '', $color);
366 366
 
367 367
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
368
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
369
-    if ( empty( $color ) ) {
368
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
369
+    if (empty($color)) {
370 370
         return NULL;
371 371
     }
372 372
 
373
-    $color = str_split( $color );
373
+    $color = str_split($color);
374 374
 
375 375
     $rgb      = array();
376
-    $rgb['R'] = hexdec( $color[0] . $color[1] );
377
-    $rgb['G'] = hexdec( $color[2] . $color[3] );
378
-    $rgb['B'] = hexdec( $color[4] . $color[5] );
376
+    $rgb['R'] = hexdec($color[0] . $color[1]);
377
+    $rgb['G'] = hexdec($color[2] . $color[3]);
378
+    $rgb['B'] = hexdec($color[4] . $color[5]);
379 379
 
380 380
     return $rgb;
381 381
 }
382 382
 
383
-function wpinv_hex_darker( $color, $factor = 30 ) {
384
-    $base  = wpinv_rgb_from_hex( $color );
383
+function wpinv_hex_darker($color, $factor = 30) {
384
+    $base  = wpinv_rgb_from_hex($color);
385 385
     $color = '#';
386 386
 
387
-    foreach ( $base as $k => $v ) {
387
+    foreach ($base as $k => $v) {
388 388
         $amount      = $v / 100;
389
-        $amount      = round( $amount * $factor );
389
+        $amount      = round($amount * $factor);
390 390
         $new_decimal = $v - $amount;
391 391
 
392
-        $new_hex_component = dechex( $new_decimal );
393
-        if ( strlen( $new_hex_component ) < 2 ) {
392
+        $new_hex_component = dechex($new_decimal);
393
+        if (strlen($new_hex_component) < 2) {
394 394
             $new_hex_component = "0" . $new_hex_component;
395 395
         }
396 396
         $color .= $new_hex_component;
@@ -399,18 +399,18 @@  discard block
 block discarded – undo
399 399
     return $color;
400 400
 }
401 401
 
402
-function wpinv_hex_lighter( $color, $factor = 30 ) {
403
-    $base  = wpinv_rgb_from_hex( $color );
402
+function wpinv_hex_lighter($color, $factor = 30) {
403
+    $base  = wpinv_rgb_from_hex($color);
404 404
     $color = '#';
405 405
 
406
-    foreach ( $base as $k => $v ) {
406
+    foreach ($base as $k => $v) {
407 407
         $amount      = 255 - $v;
408 408
         $amount      = $amount / 100;
409
-        $amount      = round( $amount * $factor );
409
+        $amount      = round($amount * $factor);
410 410
         $new_decimal = $v + $amount;
411 411
 
412
-        $new_hex_component = dechex( $new_decimal );
413
-        if ( strlen( $new_hex_component ) < 2 ) {
412
+        $new_hex_component = dechex($new_decimal);
413
+        if (strlen($new_hex_component) < 2) {
414 414
             $new_hex_component = "0" . $new_hex_component;
415 415
         }
416 416
         $color .= $new_hex_component;
@@ -419,22 +419,22 @@  discard block
 block discarded – undo
419 419
     return $color;
420 420
 }
421 421
 
422
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
423
-    $hex = str_replace( '#', '', $color );
422
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
423
+    $hex = str_replace('#', '', $color);
424 424
 
425
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
426
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
427
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
425
+    $c_r = hexdec(substr($hex, 0, 2));
426
+    $c_g = hexdec(substr($hex, 2, 2));
427
+    $c_b = hexdec(substr($hex, 4, 2));
428 428
 
429
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
429
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
430 430
 
431 431
     return $brightness > 155 ? $dark : $light;
432 432
 }
433 433
 
434
-function wpinv_format_hex( $hex ) {
435
-    $hex = trim( str_replace( '#', '', $hex ) );
434
+function wpinv_format_hex($hex) {
435
+    $hex = trim(str_replace('#', '', $hex));
436 436
 
437
-    if ( strlen( $hex ) == 3 ) {
437
+    if (strlen($hex) == 3) {
438 438
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
439 439
     }
440 440
 
@@ -454,12 +454,12 @@  discard block
 block discarded – undo
454 454
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
455 455
  * @return string
456 456
  */
457
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
458
-    if ( function_exists( 'mb_strimwidth' ) ) {
459
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
457
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
458
+    if (function_exists('mb_strimwidth')) {
459
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
460 460
     }
461 461
     
462
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
462
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
463 463
 }
464 464
 
465 465
 /**
@@ -471,28 +471,28 @@  discard block
 block discarded – undo
471 471
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
472 472
  * @return int Returns the number of characters in string.
473 473
  */
474
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
475
-    if ( function_exists( 'mb_strlen' ) ) {
476
-        return mb_strlen( $str, $encoding );
474
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
475
+    if (function_exists('mb_strlen')) {
476
+        return mb_strlen($str, $encoding);
477 477
     }
478 478
         
479
-    return strlen( $str );
479
+    return strlen($str);
480 480
 }
481 481
 
482
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
483
-    if ( function_exists( 'mb_strtolower' ) ) {
484
-        return mb_strtolower( $str, $encoding );
482
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
483
+    if (function_exists('mb_strtolower')) {
484
+        return mb_strtolower($str, $encoding);
485 485
     }
486 486
     
487
-    return strtolower( $str );
487
+    return strtolower($str);
488 488
 }
489 489
 
490
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
491
-    if ( function_exists( 'mb_strtoupper' ) ) {
492
-        return mb_strtoupper( $str, $encoding );
490
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
491
+    if (function_exists('mb_strtoupper')) {
492
+        return mb_strtoupper($str, $encoding);
493 493
     }
494 494
     
495
-    return strtoupper( $str );
495
+    return strtoupper($str);
496 496
 }
497 497
 
498 498
 /**
@@ -506,12 +506,12 @@  discard block
 block discarded – undo
506 506
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
507 507
  * @return int Returns the position of the first occurrence of search in the string.
508 508
  */
509
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
510
-    if ( function_exists( 'mb_strpos' ) ) {
511
-        return mb_strpos( $str, $find, $offset, $encoding );
509
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
510
+    if (function_exists('mb_strpos')) {
511
+        return mb_strpos($str, $find, $offset, $encoding);
512 512
     }
513 513
         
514
-    return strpos( $str, $find, $offset );
514
+    return strpos($str, $find, $offset);
515 515
 }
516 516
 
517 517
 /**
@@ -525,12 +525,12 @@  discard block
 block discarded – undo
525 525
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
526 526
  * @return int Returns the position of the last occurrence of search.
527 527
  */
528
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
529
-    if ( function_exists( 'mb_strrpos' ) ) {
530
-        return mb_strrpos( $str, $find, $offset, $encoding );
528
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
529
+    if (function_exists('mb_strrpos')) {
530
+        return mb_strrpos($str, $find, $offset, $encoding);
531 531
     }
532 532
         
533
-    return strrpos( $str, $find, $offset );
533
+    return strrpos($str, $find, $offset);
534 534
 }
535 535
 
536 536
 /**
@@ -545,16 +545,16 @@  discard block
 block discarded – undo
545 545
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
546 546
  * @return string
547 547
  */
548
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
549
-    if ( function_exists( 'mb_substr' ) ) {
550
-        if ( $length === null ) {
551
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
548
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
549
+    if (function_exists('mb_substr')) {
550
+        if ($length === null) {
551
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
552 552
         } else {
553
-            return mb_substr( $str, $start, $length, $encoding );
553
+            return mb_substr($str, $start, $length, $encoding);
554 554
         }
555 555
     }
556 556
         
557
-    return substr( $str, $start, $length );
557
+    return substr($str, $start, $length);
558 558
 }
559 559
 
560 560
 /**
@@ -566,48 +566,48 @@  discard block
 block discarded – undo
566 566
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
567 567
  * @return string The width of string.
568 568
  */
569
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
570
-    if ( function_exists( 'mb_strwidth' ) ) {
571
-        return mb_strwidth( $str, $encoding );
569
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
570
+    if (function_exists('mb_strwidth')) {
571
+        return mb_strwidth($str, $encoding);
572 572
     }
573 573
     
574
-    return wpinv_utf8_strlen( $str, $encoding );
574
+    return wpinv_utf8_strlen($str, $encoding);
575 575
 }
576 576
 
577
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
578
-    if ( function_exists( 'mb_strlen' ) ) {
579
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
577
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
578
+    if (function_exists('mb_strlen')) {
579
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
580 580
         $str_end = "";
581 581
         
582
-        if ( $lower_str_end ) {
583
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
582
+        if ($lower_str_end) {
583
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
584 584
         } else {
585
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
585
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
586 586
         }
587 587
 
588 588
         return $first_letter . $str_end;
589 589
     }
590 590
     
591
-    return ucfirst( $str );
591
+    return ucfirst($str);
592 592
 }
593 593
 
594
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
595
-    if ( function_exists( 'mb_convert_case' ) ) {
596
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
594
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
595
+    if (function_exists('mb_convert_case')) {
596
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
597 597
     }
598 598
     
599
-    return ucwords( $str );
599
+    return ucwords($str);
600 600
 }
601 601
 
602
-function wpinv_period_in_days( $period, $unit ) {
603
-    $period = absint( $period );
602
+function wpinv_period_in_days($period, $unit) {
603
+    $period = absint($period);
604 604
     
605
-    if ( $period > 0 ) {
606
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
605
+    if ($period > 0) {
606
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
607 607
             $period = $period * 7;
608
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
608
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
609 609
             $period = $period * 30;
610
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
610
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
611 611
             $period = $period * 365;
612 612
         }
613 613
     }
@@ -615,14 +615,14 @@  discard block
 block discarded – undo
615 615
     return $period;
616 616
 }
617 617
 
618
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
619
-    if ( function_exists( 'cal_days_in_month' ) ) {
620
-        return cal_days_in_month( $calendar, $month, $year );
618
+function wpinv_cal_days_in_month($calendar, $month, $year) {
619
+    if (function_exists('cal_days_in_month')) {
620
+        return cal_days_in_month($calendar, $month, $year);
621 621
     }
622 622
 
623 623
     // Fallback in case the calendar extension is not loaded in PHP
624 624
     // Only supports Gregorian calendar
625
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
625
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
626 626
 }
627 627
 
628 628
 /**
@@ -633,12 +633,12 @@  discard block
 block discarded – undo
633 633
  *
634 634
  * @return string
635 635
  */
636
-function wpi_help_tip( $tip, $allow_html = false ) {
636
+function wpi_help_tip($tip, $allow_html = false) {
637 637
 
638
-    if ( $allow_html ) {
639
-        $tip = wpi_sanitize_tooltip( $tip );
638
+    if ($allow_html) {
639
+        $tip = wpi_sanitize_tooltip($tip);
640 640
     } else {
641
-        $tip = esc_attr( $tip );
641
+        $tip = esc_attr($tip);
642 642
     }
643 643
 
644 644
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -652,8 +652,8 @@  discard block
 block discarded – undo
652 652
  * @param string $var
653 653
  * @return string
654 654
  */
655
-function wpi_sanitize_tooltip( $var ) {
656
-    return wp_kses( html_entity_decode( $var ), array(
655
+function wpi_sanitize_tooltip($var) {
656
+    return wp_kses(html_entity_decode($var), array(
657 657
         'br'     => array(),
658 658
         'em'     => array(),
659 659
         'strong' => array(),
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
         'li'     => array(),
665 665
         'ol'     => array(),
666 666
         'p'      => array(),
667
-    ) );
667
+    ));
668 668
 }
669 669
 
670 670
 /**
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
  */
675 675
 function wpinv_get_screen_ids() {
676 676
 
677
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
677
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
678 678
 
679 679
     $screen_ids = array(
680 680
         'toplevel_page_' . $screen_id,
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
         'invoicing_page_wpi-addons',
693 693
     );
694 694
 
695
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
695
+    return apply_filters('wpinv_screen_ids', $screen_ids);
696 696
 }
697 697
 
698 698
 /**
@@ -703,14 +703,14 @@  discard block
 block discarded – undo
703 703
  * @param array|string $list List of values.
704 704
  * @return array Sanitized array of values.
705 705
  */
706
-function wpinv_parse_list( $list ) {
706
+function wpinv_parse_list($list) {
707 707
 
708
-    if ( empty( $list ) ) {
708
+    if (empty($list)) {
709 709
         $list = array();
710 710
     }
711 711
 
712
-	if ( ! is_array( $list ) ) {
713
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
712
+	if (!is_array($list)) {
713
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
714 714
 	}
715 715
 
716 716
 	return $list;
@@ -724,16 +724,16 @@  discard block
 block discarded – undo
724 724
  * @param string $key Type of data to fetch.
725 725
  * @return mixed Fetched data.
726 726
  */
727
-function wpinv_get_data( $key ) {
727
+function wpinv_get_data($key) {
728 728
 
729 729
     // Try fetching it from the cache.
730
-    $data = wp_cache_get( "wpinv-data-$key", 'wpinv' );
731
-    if( $data ) {
730
+    $data = wp_cache_get("wpinv-data-$key", 'wpinv');
731
+    if ($data) {
732 732
         return $data;
733 733
     }
734 734
 
735
-    $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
736
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
735
+    $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php");
736
+	wp_cache_set("wpinv-data-$key", $data, 'wpinv');
737 737
 
738 738
 	return $data;
739 739
 }
@@ -747,10 +747,10 @@  discard block
 block discarded – undo
747 747
  * @param bool $first_empty Whether or not the first item in the list should be empty
748 748
  * @return mixed Fetched data.
749 749
  */
750
-function wpinv_maybe_add_empty_option( $options, $first_empty ) {
750
+function wpinv_maybe_add_empty_option($options, $first_empty) {
751 751
 
752
-    if ( ! empty( $options ) && $first_empty ) {
753
-        return array_merge( array( '' => '' ), $options );
752
+    if (!empty($options) && $first_empty) {
753
+        return array_merge(array('' => ''), $options);
754 754
     }
755 755
     return $options;
756 756
 
@@ -762,21 +762,21 @@  discard block
 block discarded – undo
762 762
  * @param mixed $var Data to sanitize.
763 763
  * @return string|array
764 764
  */
765
-function wpinv_clean( $var ) {
765
+function wpinv_clean($var) {
766 766
 
767
-	if ( is_array( $var ) ) {
768
-		return array_map( 'wpinv_clean', $var );
767
+	if (is_array($var)) {
768
+		return array_map('wpinv_clean', $var);
769 769
     }
770 770
 
771
-    if ( is_object( $var ) ) {
772
-		$object_vars = get_object_vars( $var );
773
-		foreach ( $object_vars as $property_name => $property_value ) {
774
-			$var->$property_name = wpinv_clean( $property_value );
771
+    if (is_object($var)) {
772
+		$object_vars = get_object_vars($var);
773
+		foreach ($object_vars as $property_name => $property_value) {
774
+			$var->$property_name = wpinv_clean($property_value);
775 775
         }
776 776
         return $var;
777 777
 	}
778 778
     
779
-    return is_string( $var ) ? sanitize_text_field( $var ) : $var;
779
+    return is_string($var) ? sanitize_text_field($var) : $var;
780 780
 }
781 781
 
782 782
 /**
@@ -785,43 +785,43 @@  discard block
 block discarded – undo
785 785
  * @param string $str Data to convert.
786 786
  * @return string|array
787 787
  */
788
-function getpaid_convert_price_string_to_options( $str ) {
788
+function getpaid_convert_price_string_to_options($str) {
789 789
 
790
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
791
-    $options     = array();
790
+	$raw_options = array_map('trim', explode(',', $str));
791
+    $options = array();
792 792
 
793
-    foreach ( $raw_options as $option ) {
793
+    foreach ($raw_options as $option) {
794 794
 
795
-        if ( '' == $option ) {
795
+        if ('' == $option) {
796 796
             continue;
797 797
         }
798 798
 
799
-        $option = array_map( 'trim', explode( '|', $option ) );
799
+        $option = array_map('trim', explode('|', $option));
800 800
 
801 801
         $price = null;
802 802
         $label = null;
803 803
 
804
-        if ( isset( $option[0] ) && '' !=  $option[0] ) {
805
-            $label  = $option[0];
804
+        if (isset($option[0]) && '' != $option[0]) {
805
+            $label = $option[0];
806 806
         }
807 807
 
808
-        if ( isset( $option[1] ) && '' !=  $option[1] ) {
808
+        if (isset($option[1]) && '' != $option[1]) {
809 809
             $price = $option[1];
810 810
         }
811 811
 
812
-        if ( ! isset( $price ) ) {
812
+        if (!isset($price)) {
813 813
             $price = $label;
814 814
         }
815 815
 
816
-        if ( ! isset( $price ) || ! is_numeric( $price ) ) {
816
+        if (!isset($price) || !is_numeric($price)) {
817 817
             continue;
818 818
         }
819 819
 
820
-        if ( ! isset( $label ) ) {
820
+        if (!isset($label)) {
821 821
             $label = $price;
822 822
         }
823 823
 
824
-        $options[ $price ] = $label;
824
+        $options[$price] = $label;
825 825
     }
826 826
 
827 827
     return $options;
@@ -830,22 +830,22 @@  discard block
 block discarded – undo
830 830
 /**
831 831
  * Returns the help tip.
832 832
  */
833
-function getpaid_get_help_tip( $tip, $additional_classes = '' ) {
834
-    $additional_classes = sanitize_html_class( $additional_classes );
835
-    $tip                = esc_attr__( $tip );
833
+function getpaid_get_help_tip($tip, $additional_classes = '') {
834
+    $additional_classes = sanitize_html_class($additional_classes);
835
+    $tip                = esc_attr__($tip);
836 836
     return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>";
837 837
 }
838 838
 
839 839
 /**
840 840
  * Formats a date
841 841
  */
842
-function getpaid_format_date( $date ) {
842
+function getpaid_format_date($date) {
843 843
 
844
-    if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) {
844
+    if (empty($date) || $date == '0000-00-00 00:00:00') {
845 845
         return '';
846 846
     }
847 847
 
848
-    return date_i18n( getpaid_date_format(), strtotime( $date ) );
848
+    return date_i18n(getpaid_date_format(), strtotime($date));
849 849
 
850 850
 }
851 851
 
@@ -854,9 +854,9 @@  discard block
 block discarded – undo
854 854
  *
855 855
  * @return string
856 856
  */
857
-function getpaid_format_date_value( $date, $default = "&mdash;" ) {
858
-    $date = getpaid_format_date( $date );
859
-    return empty( $date ) ? $default : $date;
857
+function getpaid_format_date_value($date, $default = "&mdash;") {
858
+    $date = getpaid_format_date($date);
859
+    return empty($date) ? $default : $date;
860 860
 }
861 861
 
862 862
 /**
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
  * @return string
866 866
  */
867 867
 function getpaid_date_format() {
868
-	return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
868
+	return apply_filters('getpaid_date_format', get_option('date_format'));
869 869
 }
870 870
 
871 871
 /**
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
  * @return string
875 875
  */
876 876
 function getpaid_time_format() {
877
-	return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
877
+	return apply_filters('getpaid_time_format', get_option('time_format'));
878 878
 }
879 879
 
880 880
 /**
@@ -884,16 +884,16 @@  discard block
 block discarded – undo
884 884
  * @param  integer $limit Limit size in characters.
885 885
  * @return string
886 886
  */
887
-function getpaid_limit_length( $string, $limit ) {
887
+function getpaid_limit_length($string, $limit) {
888 888
     $str_limit = $limit - 3;
889 889
 
890
-	if ( function_exists( 'mb_strimwidth' ) ) {
891
-		if ( mb_strlen( $string ) > $limit ) {
892
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
890
+	if (function_exists('mb_strimwidth')) {
891
+		if (mb_strlen($string) > $limit) {
892
+			$string = mb_strimwidth($string, 0, $str_limit) . '...';
893 893
 		}
894 894
 	} else {
895
-		if ( strlen( $string ) > $limit ) {
896
-			$string = substr( $string, 0, $str_limit ) . '...';
895
+		if (strlen($string) > $limit) {
896
+			$string = substr($string, 0, $str_limit) . '...';
897 897
 		}
898 898
 	}
899 899
     return $string;
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
  * @since 1.0.19
908 908
  */
909 909
 function getpaid_api() {
910
-    return getpaid()->get( 'api' );
910
+    return getpaid()->get('api');
911 911
 }
912 912
 
913 913
 /**
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
  * @since 1.0.19
918 918
  */
919 919
 function getpaid_post_types() {
920
-    return getpaid()->get( 'post_types' );
920
+    return getpaid()->get('post_types');
921 921
 }
922 922
 
923 923
 /**
@@ -927,7 +927,7 @@  discard block
 block discarded – undo
927 927
  * @since 1.0.19
928 928
  */
929 929
 function getpaid_session() {
930
-    return getpaid()->get( 'session' );
930
+    return getpaid()->get('session');
931 931
 }
932 932
 
933 933
 /**
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
  * @since 1.0.19
938 938
  */
939 939
 function getpaid_notes() {
940
-    return getpaid()->get( 'notes' );
940
+    return getpaid()->get('notes');
941 941
 }
942 942
 
943 943
 /**
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
  * @return GetPaid_Admin
947 947
  */
948 948
 function getpaid_admin() {
949
-    return getpaid()->get( 'admin' );
949
+    return getpaid()->get('admin');
950 950
 }
951 951
 
952 952
 /**
@@ -956,8 +956,8 @@  discard block
 block discarded – undo
956 956
  * @param string $base the base url
957 957
  * @return string
958 958
  */
959
-function getpaid_get_authenticated_action_url( $action, $base = false ) {
960
-    return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' );
959
+function getpaid_get_authenticated_action_url($action, $base = false) {
960
+    return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce');
961 961
 }
962 962
 
963 963
 /**
@@ -965,11 +965,11 @@  discard block
 block discarded – undo
965 965
  *
966 966
  * @return string
967 967
  */
968
-function getpaid_get_post_type_label( $post_type, $plural = true ) {
968
+function getpaid_get_post_type_label($post_type, $plural = true) {
969 969
 
970
-    $post_type = get_post_type_object( $post_type );
970
+    $post_type = get_post_type_object($post_type);
971 971
 
972
-    if ( ! is_object( $post_type ) ) {
972
+    if (!is_object($post_type)) {
973 973
         return null;
974 974
     }
975 975
 
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +389 added lines, -389 removed lines patch added patch discarded remove patch
@@ -12,443 +12,443 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 * 
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		return array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-	}
151
-
152
-	/**
153
-	 * Helper function to send an email.
154
-	 *
155
-	 * @param WPInv_Invoice $invoice
156
-	 * @param GetPaid_Notification_Email $email
157
-	 * @param string $type
158
-	 * @param string|array $recipients
159
-	 * @param array $extra_args Extra template args.
160
-	 */
161
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
162
-
163
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
164
-
165
-		$mailer     = new GetPaid_Notification_Email_Sender();
166
-		$merge_tags = $email->get_merge_tags();
167
-
168
-		$result = $mailer->send(
169
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
170
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
171
-			$email->get_content( $merge_tags, $extra_args ),
172
-			$email->get_attachments()
173
-		);
174
-
175
-		// Maybe send a copy to the admin.
176
-		if ( $email->include_admin_bcc() ) {
177
-			$mailer->send(
178
-				wpinv_get_admin_email(),
179
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
180
-				$email->get_content( $merge_tags ),
181
-				$email->get_attachments()
182
-			);
183
-		}
184
-
185
-		if ( ! $result ) {
186
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
187
-		}
188
-
189
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
190
-
191
-		return $result;
192
-	}
193
-
194
-	/**
195
-	 * Also send emails to any cc users.
196
-	 *
197
-	 * @param array $recipients
198
-	 * @param GetPaid_Notification_Email $email
199
-	 */
200
-	public function filter_email_recipients( $recipients, $email ) {
201
-
202
-		if ( ! $email->is_admin_email() ) {
203
-			$cc = $email->object->get_email_cc();
204
-
205
-			if ( ! empty( $cc ) ) {
206
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
207
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
208
-			}
209
-
210
-		}
211
-
212
-		return $recipients;
213
-
214
-	}
215
-
216
-	/**
217
-	 * Sends a new invoice notification.
218
-	 *
219
-	 * @param WPInv_Invoice $invoice
220
-	 */
221
-	public function new_invoice( $invoice ) {
222
-
223
-		// Only send this email for invoices created via the admin page.
224
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
225
-			return;
226
-		}
227
-
228
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
229
-		$recipient = wpinv_get_admin_email();
230
-
231
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
232
-
233
-	}
234
-
235
-	/**
236
-	 * Sends a cancelled invoice notification.
237
-	 *
238
-	 * @param WPInv_Invoice $invoice
239
-	 */
240
-	public function cancelled_invoice( $invoice ) {
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     * 
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        return array(
130
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'               => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
138
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
145
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+    }
151
+
152
+    /**
153
+     * Helper function to send an email.
154
+     *
155
+     * @param WPInv_Invoice $invoice
156
+     * @param GetPaid_Notification_Email $email
157
+     * @param string $type
158
+     * @param string|array $recipients
159
+     * @param array $extra_args Extra template args.
160
+     */
161
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
162
+
163
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
164
+
165
+        $mailer     = new GetPaid_Notification_Email_Sender();
166
+        $merge_tags = $email->get_merge_tags();
167
+
168
+        $result = $mailer->send(
169
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
170
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
171
+            $email->get_content( $merge_tags, $extra_args ),
172
+            $email->get_attachments()
173
+        );
174
+
175
+        // Maybe send a copy to the admin.
176
+        if ( $email->include_admin_bcc() ) {
177
+            $mailer->send(
178
+                wpinv_get_admin_email(),
179
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
180
+                $email->get_content( $merge_tags ),
181
+                $email->get_attachments()
182
+            );
183
+        }
184
+
185
+        if ( ! $result ) {
186
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
187
+        }
188
+
189
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
190
+
191
+        return $result;
192
+    }
193
+
194
+    /**
195
+     * Also send emails to any cc users.
196
+     *
197
+     * @param array $recipients
198
+     * @param GetPaid_Notification_Email $email
199
+     */
200
+    public function filter_email_recipients( $recipients, $email ) {
201
+
202
+        if ( ! $email->is_admin_email() ) {
203
+            $cc = $email->object->get_email_cc();
204
+
205
+            if ( ! empty( $cc ) ) {
206
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
207
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
208
+            }
209
+
210
+        }
211
+
212
+        return $recipients;
213
+
214
+    }
215
+
216
+    /**
217
+     * Sends a new invoice notification.
218
+     *
219
+     * @param WPInv_Invoice $invoice
220
+     */
221
+    public function new_invoice( $invoice ) {
222
+
223
+        // Only send this email for invoices created via the admin page.
224
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
225
+            return;
226
+        }
227
+
228
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
229
+        $recipient = wpinv_get_admin_email();
230
+
231
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
232
+
233
+    }
234
+
235
+    /**
236
+     * Sends a cancelled invoice notification.
237
+     *
238
+     * @param WPInv_Invoice $invoice
239
+     */
240
+    public function cancelled_invoice( $invoice ) {
241 241
 
242
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
243
-		$recipient = wpinv_get_admin_email();
242
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
243
+        $recipient = wpinv_get_admin_email();
244 244
 
245
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
245
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
246 246
 
247
-	}
247
+    }
248 248
 
249
-	/**
250
-	 * Sends a failed invoice notification.
251
-	 *
252
-	 * @param WPInv_Invoice $invoice
253
-	 */
254
-	public function failed_invoice( $invoice ) {
249
+    /**
250
+     * Sends a failed invoice notification.
251
+     *
252
+     * @param WPInv_Invoice $invoice
253
+     */
254
+    public function failed_invoice( $invoice ) {
255 255
 
256
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
257
-		$recipient = wpinv_get_admin_email();
256
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
257
+        $recipient = wpinv_get_admin_email();
258 258
 
259
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
259
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
260 260
 
261
-	}
261
+    }
262 262
 
263
-	/**
264
-	 * Sends a notification whenever an invoice is put on hold.
265
-	 *
266
-	 * @param WPInv_Invoice $invoice
267
-	 */
268
-	public function onhold_invoice( $invoice ) {
263
+    /**
264
+     * Sends a notification whenever an invoice is put on hold.
265
+     *
266
+     * @param WPInv_Invoice $invoice
267
+     */
268
+    public function onhold_invoice( $invoice ) {
269 269
 
270
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
-		$recipient = $invoice->get_email();
270
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
271
+        $recipient = $invoice->get_email();
272 272
 
273
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
273
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
274 274
 
275
-	}
275
+    }
276 276
 
277
-	/**
278
-	 * Sends a notification whenever an invoice is marked as processing payment.
279
-	 *
280
-	 * @param WPInv_Invoice $invoice
281
-	 */
282
-	public function processing_invoice( $invoice ) {
277
+    /**
278
+     * Sends a notification whenever an invoice is marked as processing payment.
279
+     *
280
+     * @param WPInv_Invoice $invoice
281
+     */
282
+    public function processing_invoice( $invoice ) {
283 283
 
284
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
-		$recipient = $invoice->get_email();
284
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
285
+        $recipient = $invoice->get_email();
286 286
 
287
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
287
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
288 288
 
289
-	}
289
+    }
290 290
 
291
-	/**
292
-	 * Sends a notification whenever an invoice is paid.
293
-	 *
294
-	 * @param WPInv_Invoice $invoice
295
-	 */
296
-	public function completed_invoice( $invoice ) {
291
+    /**
292
+     * Sends a notification whenever an invoice is paid.
293
+     *
294
+     * @param WPInv_Invoice $invoice
295
+     */
296
+    public function completed_invoice( $invoice ) {
297 297
 
298
-		// (Maybe) abort if it is a renewal invoice.
299
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
300
-			return;
301
-		}
298
+        // (Maybe) abort if it is a renewal invoice.
299
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
300
+            return;
301
+        }
302 302
 
303
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
304
-		$recipient = $invoice->get_email();
303
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
304
+        $recipient = $invoice->get_email();
305 305
 
306
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
306
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
307 307
 
308
-	}
308
+    }
309 309
 
310
-	/**
311
-	 * Sends a notification whenever an invoice is refunded.
312
-	 *
313
-	 * @param WPInv_Invoice $invoice
314
-	 */
315
-	public function refunded_invoice( $invoice ) {
310
+    /**
311
+     * Sends a notification whenever an invoice is refunded.
312
+     *
313
+     * @param WPInv_Invoice $invoice
314
+     */
315
+    public function refunded_invoice( $invoice ) {
316 316
 
317
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
318
-		$recipient = $invoice->get_email();
317
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
318
+        $recipient = $invoice->get_email();
319 319
 
320
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
320
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
321 321
 
322
-	}
322
+    }
323 323
 
324
-	/**
325
-	 * Notifies a user about new invoices
326
-	 *
327
-	 * @param WPInv_Invoice $invoice
328
-	 */
329
-	public function user_invoice( $invoice ) {
324
+    /**
325
+     * Notifies a user about new invoices
326
+     *
327
+     * @param WPInv_Invoice $invoice
328
+     */
329
+    public function user_invoice( $invoice ) {
330 330
 
331
-		// Only send this email for invoices created via the admin page.
332
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
333
-			return;
334
-		}
331
+        // Only send this email for invoices created via the admin page.
332
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
333
+            return;
334
+        }
335 335
 
336
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
337
-		$recipient = $invoice->get_email();
336
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
337
+        $recipient = $invoice->get_email();
338 338
 
339
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
339
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
340 340
 
341
-	}
341
+    }
342 342
 
343
-	/**
344
-	 * Checks if an invoice is a payment form invoice.
345
-	 *
346
-	 * @param int $invoice
347
-	 * @return bool
348
-	 */
349
-	public function is_payment_form_invoice( $invoice ) {
350
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
351
-	}
343
+    /**
344
+     * Checks if an invoice is a payment form invoice.
345
+     *
346
+     * @param int $invoice
347
+     * @return bool
348
+     */
349
+    public function is_payment_form_invoice( $invoice ) {
350
+        return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
351
+    }
352 352
 
353
-	/**
354
-	 * Notifies admin about new invoice notes
355
-	 *
356
-	 * @param WPInv_Invoice $invoice
357
-	 * @param string $note
358
-	 */
359
-	public function user_note( $invoice, $note ) {
353
+    /**
354
+     * Notifies admin about new invoice notes
355
+     *
356
+     * @param WPInv_Invoice $invoice
357
+     * @param string $note
358
+     */
359
+    public function user_note( $invoice, $note ) {
360 360
 
361
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
362
-		$recipient = $invoice->get_email();
363
-
364
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
365
-
366
-	}
361
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
362
+        $recipient = $invoice->get_email();
363
+
364
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
365
+
366
+    }
367 367
 
368
-	/**
369
-	 * (Force) Sends overdue notices.
370
-	 *
371
-	 * @param WPInv_Invoice $invoice
372
-	 */
373
-	public function force_send_overdue_notice( $invoice ) {
374
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
375
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
376
-	}
377
-
378
-	/**
379
-	 * Sends overdue notices.
380
-	 *
381
-	 * @TODO: Create an invoices query class.
382
-	 */
383
-	public function overdue() {
384
-		global $wpdb;
385
-
386
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
387
-
388
-		// Fetch reminder days.
389
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
390
-
391
-		// Abort if non is set.
392
-		if ( empty( $reminder_days ) ) {
393
-			return;
394
-		}
395
-
396
-		// Retrieve date query.
397
-		$date_query = $this->get_date_query( $reminder_days );
398
-
399
-		// Invoices table.
400
-		$table = $wpdb->prefix . 'getpaid_invoices';
401
-
402
-		// Fetch invoices.
403
-		$invoices  = $wpdb->get_col(
404
-			"SELECT posts.ID FROM $wpdb->posts as posts
368
+    /**
369
+     * (Force) Sends overdue notices.
370
+     *
371
+     * @param WPInv_Invoice $invoice
372
+     */
373
+    public function force_send_overdue_notice( $invoice ) {
374
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
375
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
376
+    }
377
+
378
+    /**
379
+     * Sends overdue notices.
380
+     *
381
+     * @TODO: Create an invoices query class.
382
+     */
383
+    public function overdue() {
384
+        global $wpdb;
385
+
386
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
387
+
388
+        // Fetch reminder days.
389
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
390
+
391
+        // Abort if non is set.
392
+        if ( empty( $reminder_days ) ) {
393
+            return;
394
+        }
395
+
396
+        // Retrieve date query.
397
+        $date_query = $this->get_date_query( $reminder_days );
398
+
399
+        // Invoices table.
400
+        $table = $wpdb->prefix . 'getpaid_invoices';
401
+
402
+        // Fetch invoices.
403
+        $invoices  = $wpdb->get_col(
404
+            "SELECT posts.ID FROM $wpdb->posts as posts
405 405
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
406 406
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
407 407
 
408
-		foreach ( $invoices as $invoice ) {
408
+        foreach ( $invoices as $invoice ) {
409 409
 
410
-			// Only send this email for invoices created via the admin page.
411
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
412
-				$invoice       = new WPInv_Invoice( $invoice );
413
-				$email->object = $invoice;
410
+            // Only send this email for invoices created via the admin page.
411
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
412
+                $invoice       = new WPInv_Invoice( $invoice );
413
+                $email->object = $invoice;
414 414
 
415
-				if ( $invoice->needs_payment() ) {
416
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
417
-				}
415
+                if ( $invoice->needs_payment() ) {
416
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
417
+                }
418 418
 
419
-			}
419
+            }
420 420
 
421
-		}
421
+        }
422 422
 
423
-	}
423
+    }
424 424
 
425
-	/**
426
-	 * Calculates the date query for an invoices query
427
-	 *
428
-	 * @param array $reminder_days
429
-	 * @return string
430
-	 */
431
-	public function get_date_query( $reminder_days ) {
425
+    /**
426
+     * Calculates the date query for an invoices query
427
+     *
428
+     * @param array $reminder_days
429
+     * @return string
430
+     */
431
+    public function get_date_query( $reminder_days ) {
432 432
 
433
-		$date_query = array(
434
-			'relation'  => 'OR'
435
-		);
433
+        $date_query = array(
434
+            'relation'  => 'OR'
435
+        );
436 436
 
437
-		foreach ( $reminder_days as $days ) {
438
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
437
+        foreach ( $reminder_days as $days ) {
438
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
439 439
 
440
-			$date_query[] = array(
441
-				'year'  => $date['year'],
442
-				'month' => $date['month'],
443
-				'day'   => $date['day'],
444
-			);
440
+            $date_query[] = array(
441
+                'year'  => $date['year'],
442
+                'month' => $date['month'],
443
+                'day'   => $date['day'],
444
+            );
445 445
 
446
-		}
446
+        }
447 447
 
448
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
448
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
449 449
 
450
-		return $date_query->get_sql();
450
+        return $date_query->get_sql();
451 451
 
452
-	}
452
+    }
453 453
 
454 454
 }
Please login to merge, or discard this patch.
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This class handles invoice notificaiton emails.
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		$this->invoice_actions = apply_filters(
29 29
 			'getpaid_notification_email_invoice_triggers',
30 30
 			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
31
+				'getpaid_new_invoice'                   => array('new_invoice', 'user_invoice'),
32 32
 				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33 33
 				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34 34
 				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function init_hooks() {
52 52
 
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
53
+		add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2);
54
+		add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2);
55 55
 
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
56
+		foreach ($this->invoice_actions as $hook => $email_type) {
57
+			$this->init_email_type_hook($hook, $email_type);
58 58
 		}
59 59
 	}
60 60
 
@@ -64,25 +64,25 @@  discard block
 block discarded – undo
64 64
 	 * @param string $hook
65 65
 	 * @param string|array $email_type
66 66
 	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
67
+	public function init_email_type_hook($hook, $email_type) {
68 68
 
69
-		$email_type = wpinv_parse_list( $email_type );
69
+		$email_type = wpinv_parse_list($email_type);
70 70
 
71
-		foreach ( $email_type as $type ) {
71
+		foreach ($email_type as $type) {
72 72
 
73
-			$email = new GetPaid_Notification_Email( $type );
73
+			$email = new GetPaid_Notification_Email($type);
74 74
 
75 75
 			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
76
+			if (!$email->is_active()) {
77 77
 				continue;
78 78
 			}
79 79
 
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
80
+			if (method_exists($this, $type)) {
81
+				add_action($hook, array($this, $type), 100, 2);
82 82
 				continue;
83 83
 			}
84 84
 
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
85
+			do_action('getpaid_invoice_init_email_type_hook', $type, $hook);
86 86
 		}
87 87
 
88 88
 	}
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
 	 * @param array $merge_tags
94 94
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95 95
 	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
96
+	public function invoice_merge_tags($merge_tags, $object) {
97 97
 
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
98
+		if (is_a($object, 'WPInv_Invoice')) {
99 99
 			return array_merge(
100 100
 				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
101
+				$this->get_invoice_merge_tags($object)
102 102
 			);
103 103
 		}
104 104
 
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
105
+		if (is_a($object, 'WPInv_Subscription')) {
106 106
 			return array_merge(
107 107
 				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
108
+				$this->get_invoice_merge_tags($object->get_parent_payment())
109 109
 			);
110 110
 		}
111 111
 
@@ -119,32 +119,32 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return array
121 121
 	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
122
+	public function get_invoice_merge_tags($invoice) {
123 123
 
124 124
 		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
125
+		if (!$invoice->get_id()) {
126 126
 			return array();
127 127
 		}
128 128
 
129 129
 		return array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( $invoice->get_type() ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
130
+			'{name}'                => sanitize_text_field($invoice->get_user_full_name()),
131
+			'{full_name}'           => sanitize_text_field($invoice->get_user_full_name()),
132
+			'{first_name}'          => sanitize_text_field($invoice->get_first_name()),
133
+			'{last_name}'           => sanitize_text_field($invoice->get_last_name()),
134
+			'{email}'               => sanitize_email($invoice->get_email()),
135
+			'{invoice_number}'      => sanitize_text_field($invoice->get_number()),
136
+			'{invoice_currency}'    => sanitize_text_field($invoice->get_currency()),
137
+			'{invoice_total}'       => wpinv_price(wpinv_format_amount($invoice->get_total())),
138
+			'{invoice_link}'        => esc_url($invoice->get_view_url()),
139
+			'{invoice_pay_link}'    => esc_url($invoice->get_checkout_payment_url()),
140
+			'{invoice_receipt_link}'=> esc_url($invoice->get_receipt_url()),
141
+			'{invoice_date}'        => getpaid_format_date_value($invoice->get_date_created()),
142
+			'{invoice_due_date}'    => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')),
143
+			'{invoice_quote}'       => sanitize_text_field($invoice->get_type()),
144
+			'{invoice_label}'       => sanitize_text_field(ucfirst($invoice->get_type())),
145
+			'{invoice_description}' => wp_kses_post($invoice->get_description()),
146
+			'{subscription_name}'   => wp_kses_post($invoice->get_subscription_name()),
147
+			'{is_was}'              => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
148 148
 		);
149 149
 
150 150
 	}
@@ -158,35 +158,35 @@  discard block
 block discarded – undo
158 158
 	 * @param string|array $recipients
159 159
 	 * @param array $extra_args Extra template args.
160 160
 	 */
161
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
161
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
162 162
 
163
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
163
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
164 164
 
165 165
 		$mailer     = new GetPaid_Notification_Email_Sender();
166 166
 		$merge_tags = $email->get_merge_tags();
167 167
 
168 168
 		$result = $mailer->send(
169
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
170
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
171
-			$email->get_content( $merge_tags, $extra_args ),
169
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
170
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
171
+			$email->get_content($merge_tags, $extra_args),
172 172
 			$email->get_attachments()
173 173
 		);
174 174
 
175 175
 		// Maybe send a copy to the admin.
176
-		if ( $email->include_admin_bcc() ) {
176
+		if ($email->include_admin_bcc()) {
177 177
 			$mailer->send(
178 178
 				wpinv_get_admin_email(),
179
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
180
-				$email->get_content( $merge_tags ),
179
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
180
+				$email->get_content($merge_tags),
181 181
 				$email->get_attachments()
182 182
 			);
183 183
 		}
184 184
 
185
-		if ( ! $result ) {
186
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
185
+		if (!$result) {
186
+			$invoice->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);
187 187
 		}
188 188
 
189
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
189
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
190 190
 
191 191
 		return $result;
192 192
 	}
@@ -197,14 +197,14 @@  discard block
 block discarded – undo
197 197
 	 * @param array $recipients
198 198
 	 * @param GetPaid_Notification_Email $email
199 199
 	 */
200
-	public function filter_email_recipients( $recipients, $email ) {
200
+	public function filter_email_recipients($recipients, $email) {
201 201
 
202
-		if ( ! $email->is_admin_email() ) {
202
+		if (!$email->is_admin_email()) {
203 203
 			$cc = $email->object->get_email_cc();
204 204
 
205
-			if ( ! empty( $cc ) ) {
206
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
207
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
205
+			if (!empty($cc)) {
206
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
207
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
208 208
 			}
209 209
 
210 210
 		}
@@ -218,17 +218,17 @@  discard block
 block discarded – undo
218 218
 	 *
219 219
 	 * @param WPInv_Invoice $invoice
220 220
 	 */
221
-	public function new_invoice( $invoice ) {
221
+	public function new_invoice($invoice) {
222 222
 
223 223
 		// Only send this email for invoices created via the admin page.
224
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
224
+		if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) {
225 225
 			return;
226 226
 		}
227 227
 
228
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
228
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
229 229
 		$recipient = wpinv_get_admin_email();
230 230
 
231
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
231
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
232 232
 
233 233
 	}
234 234
 
@@ -237,12 +237,12 @@  discard block
 block discarded – undo
237 237
 	 *
238 238
 	 * @param WPInv_Invoice $invoice
239 239
 	 */
240
-	public function cancelled_invoice( $invoice ) {
240
+	public function cancelled_invoice($invoice) {
241 241
 
242
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
242
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
243 243
 		$recipient = wpinv_get_admin_email();
244 244
 
245
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
245
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
246 246
 
247 247
 	}
248 248
 
@@ -251,12 +251,12 @@  discard block
 block discarded – undo
251 251
 	 *
252 252
 	 * @param WPInv_Invoice $invoice
253 253
 	 */
254
-	public function failed_invoice( $invoice ) {
254
+	public function failed_invoice($invoice) {
255 255
 
256
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
256
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
257 257
 		$recipient = wpinv_get_admin_email();
258 258
 
259
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
259
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
260 260
 
261 261
 	}
262 262
 
@@ -265,12 +265,12 @@  discard block
 block discarded – undo
265 265
 	 *
266 266
 	 * @param WPInv_Invoice $invoice
267 267
 	 */
268
-	public function onhold_invoice( $invoice ) {
268
+	public function onhold_invoice($invoice) {
269 269
 
270
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
270
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
271 271
 		$recipient = $invoice->get_email();
272 272
 
273
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
273
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
274 274
 
275 275
 	}
276 276
 
@@ -279,12 +279,12 @@  discard block
 block discarded – undo
279 279
 	 *
280 280
 	 * @param WPInv_Invoice $invoice
281 281
 	 */
282
-	public function processing_invoice( $invoice ) {
282
+	public function processing_invoice($invoice) {
283 283
 
284
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
284
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
285 285
 		$recipient = $invoice->get_email();
286 286
 
287
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
287
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
288 288
 
289 289
 	}
290 290
 
@@ -293,17 +293,17 @@  discard block
 block discarded – undo
293 293
 	 *
294 294
 	 * @param WPInv_Invoice $invoice
295 295
 	 */
296
-	public function completed_invoice( $invoice ) {
296
+	public function completed_invoice($invoice) {
297 297
 
298 298
 		// (Maybe) abort if it is a renewal invoice.
299
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
299
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
300 300
 			return;
301 301
 		}
302 302
 
303
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
303
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
304 304
 		$recipient = $invoice->get_email();
305 305
 
306
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
306
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
307 307
 
308 308
 	}
309 309
 
@@ -312,12 +312,12 @@  discard block
 block discarded – undo
312 312
 	 *
313 313
 	 * @param WPInv_Invoice $invoice
314 314
 	 */
315
-	public function refunded_invoice( $invoice ) {
315
+	public function refunded_invoice($invoice) {
316 316
 
317
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
317
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
318 318
 		$recipient = $invoice->get_email();
319 319
 
320
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
320
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
321 321
 
322 322
 	}
323 323
 
@@ -326,17 +326,17 @@  discard block
 block discarded – undo
326 326
 	 *
327 327
 	 * @param WPInv_Invoice $invoice
328 328
 	 */
329
-	public function user_invoice( $invoice ) {
329
+	public function user_invoice($invoice) {
330 330
 
331 331
 		// Only send this email for invoices created via the admin page.
332
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
332
+		if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) {
333 333
 			return;
334 334
 		}
335 335
 
336
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
336
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
337 337
 		$recipient = $invoice->get_email();
338 338
 
339
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
339
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
340 340
 
341 341
 	}
342 342
 
@@ -346,8 +346,8 @@  discard block
 block discarded – undo
346 346
 	 * @param int $invoice
347 347
 	 * @return bool
348 348
 	 */
349
-	public function is_payment_form_invoice( $invoice ) {
350
-		return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true );
349
+	public function is_payment_form_invoice($invoice) {
350
+		return empty($_GET['getpaid-admin-action']) && 'payment_form' == get_post_meta($invoice, 'wpinv_created_via', true);
351 351
 	}
352 352
 
353 353
 	/**
@@ -356,12 +356,12 @@  discard block
 block discarded – undo
356 356
 	 * @param WPInv_Invoice $invoice
357 357
 	 * @param string $note
358 358
 	 */
359
-	public function user_note( $invoice, $note ) {
359
+	public function user_note($invoice, $note) {
360 360
 
361
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
361
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
362 362
 		$recipient = $invoice->get_email();
363 363
 
364
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
364
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
365 365
 
366 366
 	}
367 367
 
@@ -370,9 +370,9 @@  discard block
 block discarded – undo
370 370
 	 *
371 371
 	 * @param WPInv_Invoice $invoice
372 372
 	 */
373
-	public function force_send_overdue_notice( $invoice ) {
374
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
375
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
373
+	public function force_send_overdue_notice($invoice) {
374
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
375
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
376 376
 	}
377 377
 
378 378
 	/**
@@ -383,37 +383,37 @@  discard block
 block discarded – undo
383 383
 	public function overdue() {
384 384
 		global $wpdb;
385 385
 
386
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
386
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
387 387
 
388 388
 		// Fetch reminder days.
389
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
389
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
390 390
 
391 391
 		// Abort if non is set.
392
-		if ( empty( $reminder_days ) ) {
392
+		if (empty($reminder_days)) {
393 393
 			return;
394 394
 		}
395 395
 
396 396
 		// Retrieve date query.
397
-		$date_query = $this->get_date_query( $reminder_days );
397
+		$date_query = $this->get_date_query($reminder_days);
398 398
 
399 399
 		// Invoices table.
400 400
 		$table = $wpdb->prefix . 'getpaid_invoices';
401 401
 
402 402
 		// Fetch invoices.
403
-		$invoices  = $wpdb->get_col(
403
+		$invoices = $wpdb->get_col(
404 404
 			"SELECT posts.ID FROM $wpdb->posts as posts
405 405
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
406 406
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
407 407
 
408
-		foreach ( $invoices as $invoice ) {
408
+		foreach ($invoices as $invoice) {
409 409
 
410 410
 			// Only send this email for invoices created via the admin page.
411
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
412
-				$invoice       = new WPInv_Invoice( $invoice );
411
+			if (!$this->is_payment_form_invoice($invoice)) {
412
+				$invoice       = new WPInv_Invoice($invoice);
413 413
 				$email->object = $invoice;
414 414
 
415
-				if ( $invoice->needs_payment() ) {
416
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
415
+				if ($invoice->needs_payment()) {
416
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
417 417
 				}
418 418
 
419 419
 			}
@@ -428,14 +428,14 @@  discard block
 block discarded – undo
428 428
 	 * @param array $reminder_days
429 429
 	 * @return string
430 430
 	 */
431
-	public function get_date_query( $reminder_days ) {
431
+	public function get_date_query($reminder_days) {
432 432
 
433 433
 		$date_query = array(
434 434
 			'relation'  => 'OR'
435 435
 		);
436 436
 
437
-		foreach ( $reminder_days as $days ) {
438
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
437
+		foreach ($reminder_days as $days) {
438
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
439 439
 
440 440
 			$date_query[] = array(
441 441
 				'year'  => $date['year'],
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 
446 446
 		}
447 447
 
448
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
448
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
449 449
 
450 450
 		return $date_query->get_sql();
451 451
 
Please login to merge, or discard this patch.
includes/admin/wpinv-upgrade-functions.php 1 patch
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -11,55 +11,55 @@  discard block
 block discarded – undo
11 11
  * @since 1.0.0
12 12
 */
13 13
 function wpinv_automatic_upgrade() {
14
-    $wpi_version = get_option( 'wpinv_version' );
14
+    $wpi_version = get_option('wpinv_version');
15 15
 
16 16
     // Update tables.
17
-    if ( ! get_option( 'getpaid_created_invoice_tables' ) ) {
17
+    if (!get_option('getpaid_created_invoice_tables')) {
18 18
         wpinv_v119_upgrades();
19
-        update_option( 'getpaid_created_invoice_tables', true );
19
+        update_option('getpaid_created_invoice_tables', true);
20 20
     }
21 21
 
22
-    if ( $wpi_version == WPINV_VERSION ) {
22
+    if ($wpi_version == WPINV_VERSION) {
23 23
         return;
24 24
     }
25 25
 
26
-    if ( version_compare( $wpi_version, '0.0.5', '<' ) ) {
26
+    if (version_compare($wpi_version, '0.0.5', '<')) {
27 27
         wpinv_v005_upgrades();
28 28
     }
29 29
 
30
-    if ( version_compare( $wpi_version, '1.0.3', '<' ) ) {
30
+    if (version_compare($wpi_version, '1.0.3', '<')) {
31 31
         wpinv_v110_upgrades();
32 32
     }
33 33
 
34
-    update_option( 'wpinv_version', WPINV_VERSION );
34
+    update_option('wpinv_version', WPINV_VERSION);
35 35
 }
36
-add_action( 'admin_init', 'wpinv_automatic_upgrade' );
36
+add_action('admin_init', 'wpinv_automatic_upgrade');
37 37
 
38 38
 function wpinv_v005_upgrades() {
39 39
     global $wpdb;
40 40
 
41 41
     // Invoices status
42
-    $results = $wpdb->get_results( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
43
-    if ( !empty( $results ) ) {
44
-        $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
42
+    $results = $wpdb->get_results("SELECT ID FROM " . $wpdb->posts . " WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
43
+    if (!empty($results)) {
44
+        $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
45 45
 
46 46
         // Clean post cache
47
-        foreach ( $results as $row ) {
48
-            clean_post_cache( $row->ID );
47
+        foreach ($results as $row) {
48
+            clean_post_cache($row->ID);
49 49
         }
50 50
     }
51 51
 
52 52
     // Item meta key changes
53 53
     $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
54
-    $results = $wpdb->get_results( $query );
54
+    $results = $wpdb->get_results($query);
55 55
 
56
-    if ( !empty( $results ) ) {
57
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
58
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
59
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
56
+    if (!empty($results)) {
57
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
58
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
59
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
60 60
         
61
-        foreach ( $results as $row ) {
62
-            clean_post_cache( $row->post_id );
61
+        foreach ($results as $row) {
62
+            clean_post_cache($row->post_id);
63 63
         }
64 64
     }
65 65
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 function wpinv_create_invoices_table() {
89 89
     global $wpdb;
90 90
 
91
-    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
91
+    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
92 92
 
93 93
     // Create invoices table.
94 94
     $table = $wpdb->prefix . 'getpaid_invoices';
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
             KEY `key` ( `key` )
133 133
             ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
134 134
 
135
-    dbDelta( $sql );
135
+    dbDelta($sql);
136 136
 
137 137
     // Create invoice items table.
138 138
     $table = $wpdb->prefix . 'getpaid_invoice_items';
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
             KEY post_id ( post_id )
161 161
             ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
162 162
 
163
-    dbDelta( $sql );
163
+    dbDelta($sql);
164 164
 }
165 165
 
166 166
 /**
@@ -172,10 +172,10 @@  discard block
 block discarded – undo
172 172
     $invoices = array_unique(
173 173
         get_posts(
174 174
             array(
175
-                'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
175
+                'post_type'      => array('wpi_invoice', 'wpi_quote'),
176 176
                 'posts_per_page' => -1,
177 177
                 'fields'         => 'ids',
178
-                'post_status'    => array_keys( get_post_stati() ),
178
+                'post_status'    => array_keys(get_post_stati()),
179 179
             )
180 180
         )
181 181
     );
@@ -183,19 +183,19 @@  discard block
 block discarded – undo
183 183
     $invoices_table = $wpdb->prefix . 'getpaid_invoices';
184 184
     $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
185 185
 
186
-    if ( ! class_exists( 'WPInv_Legacy_Invoice' ) ) {
187
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
186
+    if (!class_exists('WPInv_Legacy_Invoice')) {
187
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php');
188 188
     }
189 189
 
190 190
     $invoice_rows = array();
191
-    foreach ( $invoices as $invoice ) {
191
+    foreach ($invoices as $invoice) {
192 192
 
193
-        $invoice = new WPInv_Legacy_Invoice( $invoice );
194
-        $fields = array (
193
+        $invoice = new WPInv_Legacy_Invoice($invoice);
194
+        $fields = array(
195 195
             'post_id'        => $invoice->ID,
196 196
             'number'         => $invoice->get_number(),
197 197
             'key'            => $invoice->get_key(),
198
-            'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
198
+            'type'           => str_replace('wpi_', '', $invoice->post_type),
199 199
             'mode'           => $invoice->mode,
200 200
             'user_ip'        => $invoice->get_ip(),
201 201
             'first_name'     => $invoice->get_first_name(),
@@ -224,27 +224,27 @@  discard block
 block discarded – undo
224 224
             'custom_meta'    => $invoice->payment_meta
225 225
         );
226 226
 
227
-        foreach ( $fields as $key => $val ) {
228
-            if ( is_null( $val ) ) {
227
+        foreach ($fields as $key => $val) {
228
+            if (is_null($val)) {
229 229
                 $val = '';
230 230
             }
231
-            $val = maybe_serialize( $val );
232
-            $fields[ $key ] = $wpdb->prepare( '%s', $val );
231
+            $val = maybe_serialize($val);
232
+            $fields[$key] = $wpdb->prepare('%s', $val);
233 233
         }
234 234
 
235
-        $fields = implode( ', ', $fields );
235
+        $fields = implode(', ', $fields);
236 236
         $invoice_rows[] = "($fields)";
237 237
 
238 238
         $item_rows    = array();
239 239
         $item_columns = array();
240
-        foreach ( $invoice->get_cart_details() as $details ) {
240
+        foreach ($invoice->get_cart_details() as $details) {
241 241
             $fields = array(
242 242
                 'post_id'          => $invoice->ID,
243 243
                 'item_id'          => $details['id'],
244 244
                 'item_name'        => $details['name'],
245
-                'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
245
+                'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'],
246 246
                 'vat_rate'         => $details['vat_rate'],
247
-                'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
247
+                'vat_class'        => empty($details['vat_class']) ? '_standard' : $details['vat_class'],
248 248
                 'tax'              => $details['tax'],
249 249
                 'item_price'       => $details['item_price'],
250 250
                 'custom_price'     => $details['custom_price'],
@@ -256,26 +256,26 @@  discard block
 block discarded – undo
256 256
                 'fees'             => $details['fees'],
257 257
             );
258 258
 
259
-            $item_columns = array_keys ( $fields );
259
+            $item_columns = array_keys($fields);
260 260
 
261
-            foreach ( $fields as $key => $val ) {
262
-                if ( is_null( $val ) ) {
261
+            foreach ($fields as $key => $val) {
262
+                if (is_null($val)) {
263 263
                     $val = '';
264 264
                 }
265
-                $val = maybe_serialize( $val );
266
-                $fields[ $key ] = $wpdb->prepare( '%s', $val );
265
+                $val = maybe_serialize($val);
266
+                $fields[$key] = $wpdb->prepare('%s', $val);
267 267
             }
268 268
 
269
-            $fields = implode( ', ', $fields );
269
+            $fields = implode(', ', $fields);
270 270
             $item_rows[] = "($fields)";
271 271
         }
272 272
 
273
-        $item_rows    = implode( ', ', $item_rows );
274
-        $item_columns = implode( ', ', $item_columns );
275
-        $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
273
+        $item_rows    = implode(', ', $item_rows);
274
+        $item_columns = implode(', ', $item_columns);
275
+        $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows");
276 276
     }
277 277
 
278
-    $invoice_rows = implode( ', ', $invoice_rows );
279
-    $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
278
+    $invoice_rows = implode(', ', $invoice_rows);
279
+    $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows");
280 280
 
281 281
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 2 patches
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -12,234 +12,234 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
15
+    /**
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
21 21
 
22 22
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
26
-
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
-
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
-
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
-
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
39
-
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
44
-		global $wpinv_euvat;
45
-
46
-		// For invoices...
47
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
48
-			$invoice = new WPInv_Invoice( $post );
49
-
50
-			// Resend invoice.
51
-			if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
52
-
53
-				add_meta_box(
54
-					'wpinv-mb-resend-invoice',
55
-					sprintf(
56
-						__( 'Resend %s', 'invoicing' ),
57
-						ucfirst( $invoice->get_type() )
58
-					),
59
-					'GetPaid_Meta_Box_Resend_Invoice::output',
60
-					$post_type,
61
-					'side',
62
-					'low'
63
-				);
64
-
65
-			}
66
-
67
-			// Subscriptions.
68
-			$subscription = getpaid_get_invoice_subscription( $invoice );
69
-			if ( ! empty( $subscription ) ) {
70
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
71
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
72
-			}
73
-
74
-			// Invoice details.
75
-			add_meta_box(
76
-				'wpinv-details',
77
-				sprintf(
78
-					__( '%s Details', 'invoicing' ),
79
-					ucfirst( $invoice->get_type() )
80
-				),
81
-				'GetPaid_Meta_Box_Invoice_Details::output',
82
-				$post_type,
83
-				'side'
84
-			);
85
-
86
-			// Payment details.
87
-			if ( ! $invoice->is_draft() ) {
88
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
89
-			}
90
-
91
-			// Billing details.
92
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
26
+
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
+
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
+
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
+
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
39
+
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
44
+        global $wpinv_euvat;
45
+
46
+        // For invoices...
47
+        if ( getpaid_is_invoice_post_type( $post_type ) ) {
48
+            $invoice = new WPInv_Invoice( $post );
49
+
50
+            // Resend invoice.
51
+            if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
52
+
53
+                add_meta_box(
54
+                    'wpinv-mb-resend-invoice',
55
+                    sprintf(
56
+                        __( 'Resend %s', 'invoicing' ),
57
+                        ucfirst( $invoice->get_type() )
58
+                    ),
59
+                    'GetPaid_Meta_Box_Resend_Invoice::output',
60
+                    $post_type,
61
+                    'side',
62
+                    'low'
63
+                );
64
+
65
+            }
66
+
67
+            // Subscriptions.
68
+            $subscription = getpaid_get_invoice_subscription( $invoice );
69
+            if ( ! empty( $subscription ) ) {
70
+                add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
71
+                add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
72
+            }
73
+
74
+            // Invoice details.
75
+            add_meta_box(
76
+                'wpinv-details',
77
+                sprintf(
78
+                    __( '%s Details', 'invoicing' ),
79
+                    ucfirst( $invoice->get_type() )
80
+                ),
81
+                'GetPaid_Meta_Box_Invoice_Details::output',
82
+                $post_type,
83
+                'side'
84
+            );
85
+
86
+            // Payment details.
87
+            if ( ! $invoice->is_draft() ) {
88
+                add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
89
+            }
90
+
91
+            // Billing details.
92
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
93 93
 			
94
-			// Invoice items.
95
-			add_meta_box(
96
-				'wpinv-items',
97
-				sprintf(
98
-					__( '%s Items', 'invoicing' ),
99
-					ucfirst( $invoice->get_type() )
100
-				),
101
-				'GetPaid_Meta_Box_Invoice_Items::output',
102
-				$post_type,
103
-				'normal',
104
-				'high'
105
-			);
94
+            // Invoice items.
95
+            add_meta_box(
96
+                'wpinv-items',
97
+                sprintf(
98
+                    __( '%s Items', 'invoicing' ),
99
+                    ucfirst( $invoice->get_type() )
100
+                ),
101
+                'GetPaid_Meta_Box_Invoice_Items::output',
102
+                $post_type,
103
+                'normal',
104
+                'high'
105
+            );
106 106
 			
107
-			// Invoice notes.
108
-			add_meta_box(
109
-				'wpinv-notes',
110
-				sprintf(
111
-					__( '%s Notes', 'invoicing' ),
112
-					ucfirst( $invoice->get_type() )
113
-				),
114
-				'WPInv_Meta_Box_Notes::output',
115
-				$post_type,
116
-				'side',
117
-				'low'
118
-			);
119
-
120
-			// Payment form information.
121
-			if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
122
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
123
-			}
124
-		}
125
-
126
-		// For payment forms.
127
-		if ( $post_type == 'wpi_payment_form' ) {
128
-
129
-			// Design payment form.
130
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
131
-
132
-			// Payment form information.
133
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
134
-
135
-		}
136
-
137
-		// For invoice items.
138
-		if ( $post_type == 'wpi_item' ) {
139
-
140
-			// Item details.
141
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
142
-
143
-			// If taxes are enabled, register the tax metabox.
144
-			if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
145
-				add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
146
-			}
147
-
148
-			// Item info.
149
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
150
-
151
-		}
152
-
153
-		// For invoice discounts.
154
-		if ( $post_type == 'wpi_discount' ) {
155
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
156
-		}
107
+            // Invoice notes.
108
+            add_meta_box(
109
+                'wpinv-notes',
110
+                sprintf(
111
+                    __( '%s Notes', 'invoicing' ),
112
+                    ucfirst( $invoice->get_type() )
113
+                ),
114
+                'WPInv_Meta_Box_Notes::output',
115
+                $post_type,
116
+                'side',
117
+                'low'
118
+            );
119
+
120
+            // Payment form information.
121
+            if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
122
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
123
+            }
124
+        }
125
+
126
+        // For payment forms.
127
+        if ( $post_type == 'wpi_payment_form' ) {
128
+
129
+            // Design payment form.
130
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
131
+
132
+            // Payment form information.
133
+            add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
134
+
135
+        }
136
+
137
+        // For invoice items.
138
+        if ( $post_type == 'wpi_item' ) {
139
+
140
+            // Item details.
141
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
142
+
143
+            // If taxes are enabled, register the tax metabox.
144
+            if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
145
+                add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
146
+            }
147
+
148
+            // Item info.
149
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
150
+
151
+        }
152
+
153
+        // For invoice discounts.
154
+        if ( $post_type == 'wpi_discount' ) {
155
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
156
+        }
157 157
 		
158 158
 
159
-	}
159
+    }
160 160
 
161
-	/**
162
-	 * Remove some metaboxes.
163
-	 */
164
-	public static function remove_meta_boxes() {
165
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
166
-	}
161
+    /**
162
+     * Remove some metaboxes.
163
+     */
164
+    public static function remove_meta_boxes() {
165
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
166
+    }
167 167
 
168
-	/**
169
-	 * Rename other metaboxes.
170
-	 */
171
-	public static function rename_meta_boxes() {
168
+    /**
169
+     * Rename other metaboxes.
170
+     */
171
+    public static function rename_meta_boxes() {
172 172
 		
173
-	}
174
-
175
-	/**
176
-	 * Check if we're saving, then trigger an action based on the post type.
177
-	 *
178
-	 * @param  int    $post_id Post ID.
179
-	 * @param  object $post Post object.
180
-	 */
181
-	public static function save_meta_boxes( $post_id, $post ) {
182
-		$post_id = absint( $post_id );
183
-		$data    = wp_unslash( $_POST );
184
-
185
-		// Do not save for ajax requests.
186
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
187
-			return;
188
-		}
189
-
190
-		// $post_id and $post are required
191
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
192
-			return;
193
-		}
194
-
195
-		// Dont' save meta boxes for revisions or autosaves.
196
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
197
-			return;
198
-		}
199
-
200
-		// Check the nonce.
201
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
202
-			return;
203
-		}
204
-
205
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
206
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
207
-			return;
208
-		}
209
-
210
-		// Check user has permission to edit.
211
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
212
-			return;
213
-		}
214
-
215
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
216
-
217
-			// We need this save event to run once to avoid potential endless loops.
218
-			self::$saved_meta_boxes = true;
219
-
220
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
221
-
222
-		}
223
-
224
-		// Ensure this is our post type.
225
-		$post_types_map = array(
226
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
227
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
228
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
229
-		);
230
-
231
-		// Is this our post type?
232
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
233
-			return;
234
-		}
235
-
236
-		// We need this save event to run once to avoid potential endless loops.
237
-		self::$saved_meta_boxes = true;
173
+    }
174
+
175
+    /**
176
+     * Check if we're saving, then trigger an action based on the post type.
177
+     *
178
+     * @param  int    $post_id Post ID.
179
+     * @param  object $post Post object.
180
+     */
181
+    public static function save_meta_boxes( $post_id, $post ) {
182
+        $post_id = absint( $post_id );
183
+        $data    = wp_unslash( $_POST );
184
+
185
+        // Do not save for ajax requests.
186
+        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
187
+            return;
188
+        }
189
+
190
+        // $post_id and $post are required
191
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
192
+            return;
193
+        }
194
+
195
+        // Dont' save meta boxes for revisions or autosaves.
196
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
197
+            return;
198
+        }
199
+
200
+        // Check the nonce.
201
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
202
+            return;
203
+        }
204
+
205
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
206
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
207
+            return;
208
+        }
209
+
210
+        // Check user has permission to edit.
211
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
212
+            return;
213
+        }
214
+
215
+        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
216
+
217
+            // We need this save event to run once to avoid potential endless loops.
218
+            self::$saved_meta_boxes = true;
219
+
220
+            return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
221
+
222
+        }
223
+
224
+        // Ensure this is our post type.
225
+        $post_types_map = array(
226
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
227
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
228
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
229
+        );
230
+
231
+        // Is this our post type?
232
+        if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
233
+            return;
234
+        }
235
+
236
+        // We need this save event to run once to avoid potential endless loops.
237
+        self::$saved_meta_boxes = true;
238 238
 		
239
-		// Save the post.
240
-		$class = $post_types_map[ $post->post_type ];
241
-		$class::save( $post_id, $_POST, $post );
239
+        // Save the post.
240
+        $class = $post_types_map[ $post->post_type ];
241
+        $class::save( $post_id, $_POST, $post );
242 242
 
243
-	}
243
+    }
244 244
 
245 245
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 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
  * Metaboxes Admin Class
@@ -25,36 +25,36 @@  discard block
 block discarded – undo
25 25
 	public static function init() {
26 26
 
27 27
 		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
28
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2);
29 29
 
30 30
 		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
31
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30);
32 32
 
33 33
 		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
34
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45);
35 35
 
36 36
 		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
37
+		add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2);
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * Register core metaboxes.
42 42
 	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
43
+	public static function add_meta_boxes($post_type, $post) {
44 44
 		global $wpinv_euvat;
45 45
 
46 46
 		// For invoices...
47
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
48
-			$invoice = new WPInv_Invoice( $post );
47
+		if (getpaid_is_invoice_post_type($post_type)) {
48
+			$invoice = new WPInv_Invoice($post);
49 49
 
50 50
 			// Resend invoice.
51
-			if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
51
+			if (!$invoice->is_draft() && !$invoice->is_paid()) {
52 52
 
53 53
 				add_meta_box(
54 54
 					'wpinv-mb-resend-invoice',
55 55
 					sprintf(
56
-						__( 'Resend %s', 'invoicing' ),
57
-						ucfirst( $invoice->get_type() )
56
+						__('Resend %s', 'invoicing'),
57
+						ucfirst($invoice->get_type())
58 58
 					),
59 59
 					'GetPaid_Meta_Box_Resend_Invoice::output',
60 60
 					$post_type,
@@ -65,18 +65,18 @@  discard block
 block discarded – undo
65 65
 			}
66 66
 
67 67
 			// Subscriptions.
68
-			$subscription = getpaid_get_invoice_subscription( $invoice );
69
-			if ( ! empty( $subscription ) ) {
70
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
71
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
68
+			$subscription = getpaid_get_invoice_subscription($invoice);
69
+			if (!empty($subscription)) {
70
+				add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced');
71
+				add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced');
72 72
 			}
73 73
 
74 74
 			// Invoice details.
75 75
 			add_meta_box(
76 76
 				'wpinv-details',
77 77
 				sprintf(
78
-					__( '%s Details', 'invoicing' ),
79
-					ucfirst( $invoice->get_type() )
78
+					__('%s Details', 'invoicing'),
79
+					ucfirst($invoice->get_type())
80 80
 				),
81 81
 				'GetPaid_Meta_Box_Invoice_Details::output',
82 82
 				$post_type,
@@ -84,19 +84,19 @@  discard block
 block discarded – undo
84 84
 			);
85 85
 
86 86
 			// Payment details.
87
-			if ( ! $invoice->is_draft() ) {
88
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
87
+			if (!$invoice->is_draft()) {
88
+				add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default');
89 89
 			}
90 90
 
91 91
 			// Billing details.
92
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
92
+			add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high');
93 93
 			
94 94
 			// Invoice items.
95 95
 			add_meta_box(
96 96
 				'wpinv-items',
97 97
 				sprintf(
98
-					__( '%s Items', 'invoicing' ),
99
-					ucfirst( $invoice->get_type() )
98
+					__('%s Items', 'invoicing'),
99
+					ucfirst($invoice->get_type())
100 100
 				),
101 101
 				'GetPaid_Meta_Box_Invoice_Items::output',
102 102
 				$post_type,
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 			add_meta_box(
109 109
 				'wpinv-notes',
110 110
 				sprintf(
111
-					__( '%s Notes', 'invoicing' ),
112
-					ucfirst( $invoice->get_type() )
111
+					__('%s Notes', 'invoicing'),
112
+					ucfirst($invoice->get_type())
113 113
 				),
114 114
 				'WPInv_Meta_Box_Notes::output',
115 115
 				$post_type,
@@ -118,41 +118,41 @@  discard block
 block discarded – undo
118 118
 			);
119 119
 
120 120
 			// Payment form information.
121
-			if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
122
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
121
+			if (!empty($post->ID) && get_post_meta($post->ID, 'payment_form_data', true)) {
122
+				add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high');
123 123
 			}
124 124
 		}
125 125
 
126 126
 		// For payment forms.
127
-		if ( $post_type == 'wpi_payment_form' ) {
127
+		if ($post_type == 'wpi_payment_form') {
128 128
 
129 129
 			// Design payment form.
130
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
130
+			add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal');
131 131
 
132 132
 			// Payment form information.
133
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
133
+			add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side');
134 134
 
135 135
 		}
136 136
 
137 137
 		// For invoice items.
138
-		if ( $post_type == 'wpi_item' ) {
138
+		if ($post_type == 'wpi_item') {
139 139
 
140 140
 			// Item details.
141
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
141
+			add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high');
142 142
 
143 143
 			// If taxes are enabled, register the tax metabox.
144
-			if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
145
-				add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
144
+			if ($wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes()) {
145
+				add_meta_box('wpinv_item_vat', __('VAT / Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high');
146 146
 			}
147 147
 
148 148
 			// Item info.
149
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
149
+			add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core');
150 150
 
151 151
 		}
152 152
 
153 153
 		// For invoice discounts.
154
-		if ( $post_type == 'wpi_discount' ) {
155
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
154
+		if ($post_type == 'wpi_discount') {
155
+			add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high');
156 156
 		}
157 157
 		
158 158
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 * Remove some metaboxes.
163 163
 	 */
164 164
 	public static function remove_meta_boxes() {
165
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
165
+		remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
166 166
 	}
167 167
 
168 168
 	/**
@@ -178,46 +178,46 @@  discard block
 block discarded – undo
178 178
 	 * @param  int    $post_id Post ID.
179 179
 	 * @param  object $post Post object.
180 180
 	 */
181
-	public static function save_meta_boxes( $post_id, $post ) {
182
-		$post_id = absint( $post_id );
183
-		$data    = wp_unslash( $_POST );
181
+	public static function save_meta_boxes($post_id, $post) {
182
+		$post_id = absint($post_id);
183
+		$data    = wp_unslash($_POST);
184 184
 
185 185
 		// Do not save for ajax requests.
186
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
186
+		if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
187 187
 			return;
188 188
 		}
189 189
 
190 190
 		// $post_id and $post are required
191
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
191
+		if (empty($post_id) || empty($post) || self::$saved_meta_boxes) {
192 192
 			return;
193 193
 		}
194 194
 
195 195
 		// Dont' save meta boxes for revisions or autosaves.
196
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
196
+		if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
197 197
 			return;
198 198
 		}
199 199
 
200 200
 		// Check the nonce.
201
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
201
+		if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) {
202 202
 			return;
203 203
 		}
204 204
 
205 205
 		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
206
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
206
+		if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) {
207 207
 			return;
208 208
 		}
209 209
 
210 210
 		// Check user has permission to edit.
211
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
211
+		if (!current_user_can('edit_post', $post_id)) {
212 212
 			return;
213 213
 		}
214 214
 
215
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
215
+		if (getpaid_is_invoice_post_type($post->post_type)) {
216 216
 
217 217
 			// We need this save event to run once to avoid potential endless loops.
218 218
 			self::$saved_meta_boxes = true;
219 219
 
220
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
220
+			return GetPaid_Meta_Box_Invoice_Address::save($post_id);
221 221
 
222 222
 		}
223 223
 
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		);
230 230
 
231 231
 		// Is this our post type?
232
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
232
+		if (!isset($post_types_map[$post->post_type])) {
233 233
 			return;
234 234
 		}
235 235
 
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 		self::$saved_meta_boxes = true;
238 238
 		
239 239
 		// Save the post.
240
-		$class = $post_types_map[ $post->post_type ];
241
-		$class::save( $post_id, $_POST, $post );
240
+		$class = $post_types_map[$post->post_type];
241
+		$class::save($post_id, $_POST, $post);
242 242
 
243 243
 	}
244 244
 
Please login to merge, or discard this patch.
templates/invoice/invoice.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
@@ -18,16 +18,16 @@  discard block
 block discarded – undo
18 18
         <?php
19 19
 
20 20
             // Fires when printing the header.
21
-            do_action( 'getpaid_invoice_header', $invoice );
21
+            do_action('getpaid_invoice_header', $invoice);
22 22
 
23 23
             // Print the opening wrapper.
24 24
             echo '<div class="container bg-white border mt-4 mb-4 p-4 position-relative flex-grow-1">';
25 25
 
26 26
             // Fires when printing the invoice details.
27
-            do_action( 'getpaid_invoice_details', $invoice );
27
+            do_action('getpaid_invoice_details', $invoice);
28 28
 
29 29
             // Fires when printing the invoice line items.
30
-            do_action( 'getpaid_invoice_line_items', $invoice );
30
+            do_action('getpaid_invoice_line_items', $invoice);
31 31
 
32 32
             // Print notifications.
33 33
             wpinv_print_errors();
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
             echo '</div>';
37 37
 
38 38
             // Fires when printing the invoice footer.
39
-            do_action( 'getpaid_invoice_footer', $invoice );
39
+            do_action('getpaid_invoice_footer', $invoice);
40 40
 
41 41
         ?>
42 42
 
Please login to merge, or discard this patch.
templates/invoice/header-right-actions.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @var WPInv_Invoice $invoice
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 ?>
14 14
 
@@ -21,43 +21,43 @@  discard block
 block discarded – undo
21 21
             $actions[] = sprintf(
22 22
                 '<a href="javascript:void(0)" class="btn btn-sm btn-secondary invoice-action-print" onclick="window.print();">%s</a>',
23 23
                 sprintf(
24
-                    __( 'Print %s', 'invoicing' ),
25
-                    ucfirst( $invoice->get_type() )
24
+                    __('Print %s', 'invoicing'),
25
+                    ucfirst($invoice->get_type())
26 26
                 )
27 27
             );
28 28
 
29
-            if ( is_user_logged_in() ) {
29
+            if (is_user_logged_in()) {
30 30
 
31 31
                 $actions[] = sprintf(
32 32
                     '<a href="%s" class="btn btn-sm btn-secondary invoice-action-history">%s</a>',
33
-                    esc_url( wpinv_get_history_page_uri( $invoice->get_post_type() ) ),
33
+                    esc_url(wpinv_get_history_page_uri($invoice->get_post_type())),
34 34
                     sprintf(
35
-                        __( '%s History', 'invoicing' ),
36
-                        ucfirst( $invoice->get_type() )
35
+                        __('%s History', 'invoicing'),
36
+                        ucfirst($invoice->get_type())
37 37
                     )
38 38
                 );
39 39
 
40 40
             }
41 41
 
42
-            if ( wpinv_current_user_can_manage_invoicing() ) {
42
+            if (wpinv_current_user_can_manage_invoicing()) {
43 43
 
44 44
                 $actions[] = sprintf(
45 45
                     '<a href="%s" class="btn btn-sm btn-secondary invoice-action-edit">%s</a>',
46
-                    esc_url( get_edit_post_link( $invoice->get_id() ) ),
46
+                    esc_url(get_edit_post_link($invoice->get_id())),
47 47
                     sprintf(
48
-                        __( 'Edit %s', 'invoicing' ),
49
-                        ucfirst( $invoice->get_type() )
48
+                        __('Edit %s', 'invoicing'),
49
+                        ucfirst($invoice->get_type())
50 50
                     )
51 51
                 );
52 52
 
53 53
             }
54 54
 
55
-            $actions = apply_filters( 'getpaid_invoice_header_right_actions_array', $actions, $invoice );
56
-            echo implode( "&nbsp;&nbsp;", $actions );
55
+            $actions = apply_filters('getpaid_invoice_header_right_actions_array', $actions, $invoice);
56
+            echo implode("&nbsp;&nbsp;", $actions);
57 57
 
58 58
         ?>
59 59
 
60
-        <?php do_action('wpinv_invoice_display_right_actions', $invoice ); ?>
60
+        <?php do_action('wpinv_invoice_display_right_actions', $invoice); ?>
61 61
     </div>
62 62
 
63 63
 <?php
Please login to merge, or discard this patch.
templates/invoice/header-left-actions.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,19 +7,19 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 ?>
13 13
 
14 14
         <div class="getpaid-header-left-actions">
15 15
 
16
-            <?php if ( $invoice->is_type( 'invoice' ) && $invoice->needs_payment() && ! $invoice->is_held() ): ?>
17
-                <a class="btn btn-sm btn-primary invoice-action-pay" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>">
18
-                    <?php _e( 'Pay For Invoice', 'invoicing' ); ?>
16
+            <?php if ($invoice->is_type('invoice') && $invoice->needs_payment() && !$invoice->is_held()): ?>
17
+                <a class="btn btn-sm btn-primary invoice-action-pay" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>">
18
+                    <?php _e('Pay For Invoice', 'invoicing'); ?>
19 19
                 </a>
20 20
             <?php endif; ?>
21 21
 
22
-            <?php do_action( 'wpinv_invoice_display_left_actions', $invoice ); ?>
22
+            <?php do_action('wpinv_invoice_display_left_actions', $invoice); ?>
23 23
 
24 24
         </div>
25 25
 
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 3 patches
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
141 141
  */
142 142
 function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
-	return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
143
+    return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
144 144
 }
145 145
 
146 146
 /**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @return string
159 159
  */
160 160
 function wpinv_get_theme_template_dir_name() {
161
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
161
+    return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
162 162
 }
163 163
 
164 164
 /**
@@ -175,122 +175,122 @@  discard block
 block discarded – undo
175 175
 }
176 176
 
177 177
 function wpinv_get_template_part( $slug, $name = null, $load = true ) {
178
-	do_action( 'get_template_part_' . $slug, $slug, $name );
178
+    do_action( 'get_template_part_' . $slug, $slug, $name );
179 179
 
180
-	// Setup possible parts
181
-	$templates = array();
182
-	if ( isset( $name ) )
183
-		$templates[] = $slug . '-' . $name . '.php';
184
-	$templates[] = $slug . '.php';
180
+    // Setup possible parts
181
+    $templates = array();
182
+    if ( isset( $name ) )
183
+        $templates[] = $slug . '-' . $name . '.php';
184
+    $templates[] = $slug . '.php';
185 185
 
186
-	// Allow template parts to be filtered
187
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
186
+    // Allow template parts to be filtered
187
+    $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
188 188
 
189
-	// Return the part that is found
190
-	return wpinv_locate_tmpl( $templates, $load, false );
189
+    // Return the part that is found
190
+    return wpinv_locate_tmpl( $templates, $load, false );
191 191
 }
192 192
 
193 193
 function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
194
-	// No file found yet
195
-	$located = false;
194
+    // No file found yet
195
+    $located = false;
196 196
 
197
-	// Try to find a template file
198
-	foreach ( (array)$template_names as $template_name ) {
197
+    // Try to find a template file
198
+    foreach ( (array)$template_names as $template_name ) {
199 199
 
200
-		// Continue if template is empty
201
-		if ( empty( $template_name ) )
202
-			continue;
200
+        // Continue if template is empty
201
+        if ( empty( $template_name ) )
202
+            continue;
203 203
 
204
-		// Trim off any slashes from the template name
205
-		$template_name = ltrim( $template_name, '/' );
204
+        // Trim off any slashes from the template name
205
+        $template_name = ltrim( $template_name, '/' );
206 206
 
207
-		// try locating this template file by looping through the template paths
208
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
207
+        // try locating this template file by looping through the template paths
208
+        foreach( wpinv_get_theme_template_paths() as $template_path ) {
209 209
 
210
-			if( file_exists( $template_path . $template_name ) ) {
211
-				$located = $template_path . $template_name;
212
-				break;
213
-			}
214
-		}
210
+            if( file_exists( $template_path . $template_name ) ) {
211
+                $located = $template_path . $template_name;
212
+                break;
213
+            }
214
+        }
215 215
 
216
-		if( !empty( $located ) ) {
217
-			break;
218
-		}
219
-	}
216
+        if( !empty( $located ) ) {
217
+            break;
218
+        }
219
+    }
220 220
 
221
-	if ( ( true == $load ) && ! empty( $located ) )
222
-		load_template( $located, $require_once );
221
+    if ( ( true == $load ) && ! empty( $located ) )
222
+        load_template( $located, $require_once );
223 223
 
224
-	return $located;
224
+    return $located;
225 225
 }
226 226
 
227 227
 function wpinv_get_theme_template_paths() {
228
-	$template_dir = wpinv_get_theme_template_dir_name();
228
+    $template_dir = wpinv_get_theme_template_dir_name();
229 229
 
230
-	$file_paths = array(
231
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
232
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
233
-		100 => wpinv_get_templates_dir()
234
-	);
230
+    $file_paths = array(
231
+        1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
232
+        10 => trailingslashit( get_template_directory() ) . $template_dir,
233
+        100 => wpinv_get_templates_dir()
234
+    );
235 235
 
236
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
236
+    $file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
237 237
 
238
-	// sort the file paths based on priority
239
-	ksort( $file_paths, SORT_NUMERIC );
238
+    // sort the file paths based on priority
239
+    ksort( $file_paths, SORT_NUMERIC );
240 240
 
241
-	return array_map( 'trailingslashit', $file_paths );
241
+    return array_map( 'trailingslashit', $file_paths );
242 242
 }
243 243
 
244 244
 function wpinv_checkout_meta_tags() {
245 245
 
246
-	$pages   = array();
247
-	$pages[] = wpinv_get_option( 'success_page' );
248
-	$pages[] = wpinv_get_option( 'failure_page' );
249
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
250
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
246
+    $pages   = array();
247
+    $pages[] = wpinv_get_option( 'success_page' );
248
+    $pages[] = wpinv_get_option( 'failure_page' );
249
+    $pages[] = wpinv_get_option( 'invoice_history_page' );
250
+    $pages[] = wpinv_get_option( 'invoice_subscription_page' );
251 251
 
252
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
253
-		return;
254
-	}
252
+    if( !wpinv_is_checkout() && !is_page( $pages ) ) {
253
+        return;
254
+    }
255 255
 
256
-	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
256
+    echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
257 257
 }
258 258
 add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
259 259
 
260 260
 function wpinv_add_body_classes( $class ) {
261
-	$classes = (array)$class;
261
+    $classes = (array)$class;
262 262
 
263
-	if( wpinv_is_checkout() ) {
264
-		$classes[] = 'wpinv-checkout';
265
-		$classes[] = 'wpinv-page';
266
-	}
263
+    if( wpinv_is_checkout() ) {
264
+        $classes[] = 'wpinv-checkout';
265
+        $classes[] = 'wpinv-page';
266
+    }
267 267
 
268
-	if( wpinv_is_success_page() ) {
269
-		$classes[] = 'wpinv-success';
270
-		$classes[] = 'wpinv-page';
271
-	}
268
+    if( wpinv_is_success_page() ) {
269
+        $classes[] = 'wpinv-success';
270
+        $classes[] = 'wpinv-page';
271
+    }
272 272
 
273
-	if( wpinv_is_failed_transaction_page() ) {
274
-		$classes[] = 'wpinv-failed-transaction';
275
-		$classes[] = 'wpinv-page';
276
-	}
273
+    if( wpinv_is_failed_transaction_page() ) {
274
+        $classes[] = 'wpinv-failed-transaction';
275
+        $classes[] = 'wpinv-page';
276
+    }
277 277
 
278
-	if( wpinv_is_invoice_history_page() ) {
279
-		$classes[] = 'wpinv-history';
280
-		$classes[] = 'wpinv-page';
281
-	}
278
+    if( wpinv_is_invoice_history_page() ) {
279
+        $classes[] = 'wpinv-history';
280
+        $classes[] = 'wpinv-page';
281
+    }
282 282
 
283
-	if( wpinv_is_subscriptions_history_page() ) {
284
-		$classes[] = 'wpinv-subscription';
285
-		$classes[] = 'wpinv-page';
286
-	}
283
+    if( wpinv_is_subscriptions_history_page() ) {
284
+        $classes[] = 'wpinv-subscription';
285
+        $classes[] = 'wpinv-page';
286
+    }
287 287
 
288
-	if( wpinv_is_test_mode() ) {
289
-		$classes[] = 'wpinv-test-mode';
290
-		$classes[] = 'wpinv-page';
291
-	}
288
+    if( wpinv_is_test_mode() ) {
289
+        $classes[] = 'wpinv-test-mode';
290
+        $classes[] = 'wpinv-page';
291
+    }
292 292
 
293
-	return array_unique( $classes );
293
+    return array_unique( $classes );
294 294
 }
295 295
 add_filter( 'body_class', 'wpinv_add_body_classes' );
296 296
 
@@ -859,21 +859,21 @@  discard block
 block discarded – undo
859 859
 
860 860
     $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
861 861
     
862
-	// Remove unavailable tags.
862
+    // Remove unavailable tags.
863 863
     $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
864 864
 
865 865
     // Clean up white space.
866
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
866
+    $formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
867 867
     $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
868 868
     
869 869
     // Break newlines apart and remove empty lines/trim commas and white space.
870
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
870
+    $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
871 871
 
872 872
     // Add html breaks.
873
-	$formatted_address = implode( $separator, $formatted_address );
873
+    $formatted_address = implode( $separator, $formatted_address );
874 874
 
875
-	// We're done!
876
-	return $formatted_address;
875
+    // We're done!
876
+    return $formatted_address;
877 877
     
878 878
 }
879 879
 
@@ -1075,7 +1075,7 @@  discard block
 block discarded – undo
1075 1075
 }
1076 1076
 
1077 1077
 function wpinv_empty_cart_message() {
1078
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1078
+    return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1079 1079
 }
1080 1080
 
1081 1081
 /**
@@ -1343,10 +1343,10 @@  discard block
 block discarded – undo
1343 1343
 
1344 1344
     if ( 0 == count( $form->get_items() ) ) {
1345 1345
         echo aui()->alert(
1346
-			array(
1347
-				'type'    => 'warning',
1348
-				'content' => __( 'No published items found', 'invoicing' ),
1349
-			)
1346
+            array(
1347
+                'type'    => 'warning',
1348
+                'content' => __( 'No published items found', 'invoicing' ),
1349
+            )
1350 1350
         );
1351 1351
         return;
1352 1352
     }
@@ -1364,21 +1364,21 @@  discard block
 block discarded – undo
1364 1364
     $invoice = wpinv_get_invoice( $invoice_id );
1365 1365
 
1366 1366
     if ( empty( $invoice ) ) {
1367
-		echo aui()->alert(
1368
-			array(
1369
-				'type'    => 'warning',
1370
-				'content' => __( 'Invoice not found', 'invoicing' ),
1371
-			)
1367
+        echo aui()->alert(
1368
+            array(
1369
+                'type'    => 'warning',
1370
+                'content' => __( 'Invoice not found', 'invoicing' ),
1371
+            )
1372 1372
         );
1373 1373
         return;
1374 1374
     }
1375 1375
 
1376 1376
     if ( $invoice->is_paid() ) {
1377
-		echo aui()->alert(
1378
-			array(
1379
-				'type'    => 'warning',
1380
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1381
-			)
1377
+        echo aui()->alert(
1378
+            array(
1379
+                'type'    => 'warning',
1380
+                'content' => __( 'Invoice has already been paid', 'invoicing' ),
1381
+            )
1382 1382
         );
1383 1383
         return;
1384 1384
     }
@@ -1440,7 +1440,7 @@  discard block
 block discarded – undo
1440 1440
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; 
1441 1441
     }
1442 1442
 	
1443
-	if ( ! empty( $items ) ) {
1443
+    if ( ! empty( $items ) ) {
1444 1444
         $items  = esc_attr( $items );
1445 1445
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; 
1446 1446
     }
Please login to merge, or discard this patch.
Spacing   +469 added lines, -469 removed lines patch added patch discarded remove patch
@@ -4,99 +4,99 @@  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
  * Displays an invoice.
11 11
  * 
12 12
  * @param WPInv_Invoice $invoice.
13 13
  */
14
-function getpaid_invoice( $invoice ) {
15
-    if ( ! empty( $invoice ) ) {
16
-        wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) );
14
+function getpaid_invoice($invoice) {
15
+    if (!empty($invoice)) {
16
+        wpinv_get_template('invoice/invoice.php', compact('invoice'));
17 17
     }
18 18
 }
19
-add_action( 'getpaid_invoice', 'getpaid_invoice', 10 );
19
+add_action('getpaid_invoice', 'getpaid_invoice', 10);
20 20
 
21 21
 /**
22 22
  * Displays the invoice footer.
23 23
  */
24
-function getpaid_invoice_footer( $invoice ) {
25
-    if ( ! empty( $invoice ) ) {
26
-        wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) );
24
+function getpaid_invoice_footer($invoice) {
25
+    if (!empty($invoice)) {
26
+        wpinv_get_template('invoice/footer.php', compact('invoice'));
27 27
     }
28 28
 }
29
-add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 );
29
+add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10);
30 30
 
31 31
 /**
32 32
  * Displays the invoice top bar.
33 33
  */
34
-function getpaid_invoice_header( $invoice ) {
35
-    if ( ! empty( $invoice ) ) {
36
-        wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) );
34
+function getpaid_invoice_header($invoice) {
35
+    if (!empty($invoice)) {
36
+        wpinv_get_template('invoice/header.php', compact('invoice'));
37 37
     }
38 38
 }
39
-add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 );
39
+add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10);
40 40
 
41 41
 /**
42 42
  * Displays actions on the left side of the header.
43 43
  */
44
-function getpaid_invoice_header_left_actions( $invoice ) {
45
-    if ( ! empty( $invoice ) ) {
46
-        wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) );
44
+function getpaid_invoice_header_left_actions($invoice) {
45
+    if (!empty($invoice)) {
46
+        wpinv_get_template('invoice/header-left-actions.php', compact('invoice'));
47 47
     }
48 48
 }
49
-add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 );
49
+add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10);
50 50
 
51 51
 /**
52 52
  * Displays actions on the right side of the invoice top bar.
53 53
  */
54
-function getpaid_invoice_header_right_actions( $invoice ) {
55
-    if ( ! empty( $invoice ) ) {
56
-        wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) );
54
+function getpaid_invoice_header_right_actions($invoice) {
55
+    if (!empty($invoice)) {
56
+        wpinv_get_template('invoice/header-right-actions.php', compact('invoice'));
57 57
     }
58 58
 }
59
-add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 );
59
+add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10);
60 60
 
61 61
 /**
62 62
  * Displays the invoice title, watermark, logo etc.
63 63
  */
64
-function getpaid_invoice_details_top( $invoice ) {
65
-    if ( ! empty( $invoice ) ) {
66
-        wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) );
64
+function getpaid_invoice_details_top($invoice) {
65
+    if (!empty($invoice)) {
66
+        wpinv_get_template('invoice/details-top.php', compact('invoice'));
67 67
     }
68 68
 }
69
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 );
69
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10);
70 70
 
71 71
 /**
72 72
  * Displays the company logo.
73 73
  */
74
-function getpaid_invoice_logo( $invoice ) {
75
-    if ( ! empty( $invoice ) ) {
76
-        wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) );
74
+function getpaid_invoice_logo($invoice) {
75
+    if (!empty($invoice)) {
76
+        wpinv_get_template('invoice/invoice-logo.php', compact('invoice'));
77 77
     }
78 78
 }
79
-add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' );
79
+add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo');
80 80
 
81 81
 /**
82 82
  * Displays the type of invoice.
83 83
  */
84
-function getpaid_invoice_type( $invoice ) {
85
-    if ( ! empty( $invoice ) ) {
86
-        wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) );
84
+function getpaid_invoice_type($invoice) {
85
+    if (!empty($invoice)) {
86
+        wpinv_get_template('invoice/invoice-type.php', compact('invoice'));
87 87
     }
88 88
 }
89
-add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' );
89
+add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type');
90 90
 
91 91
 /**
92 92
  * Displays the invoice details.
93 93
  */
94
-function getpaid_invoice_details_main( $invoice ) {
95
-    if ( ! empty( $invoice ) ) {
96
-        wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) );
94
+function getpaid_invoice_details_main($invoice) {
95
+    if (!empty($invoice)) {
96
+        wpinv_get_template('invoice/details.php', compact('invoice'));
97 97
     }
98 98
 }
99
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 );
99
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50);
100 100
 
101 101
 /**
102 102
  * Returns a path to the templates directory.
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
126 126
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
127 127
  */
128
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
129
-    return getpaid_template()->display_template( $template_name, $args, $template_path, $default_path );
128
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
129
+    return getpaid_template()->display_template($template_name, $args, $template_path, $default_path);
130 130
 }
131 131
 
132 132
 /**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
140 140
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
141 141
  */
142
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
-	return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
142
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
143
+	return getpaid_template()->get_template($template_name, $args, $template_path, $default_path);
144 144
 }
145 145
 
146 146
 /**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
  * @return string
150 150
  */
151 151
 function wpinv_template_path() {
152
-    return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() );
152
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
153 153
 }
154 154
 
155 155
 /**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @return string
159 159
  */
160 160
 function wpinv_get_theme_template_dir_name() {
161
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
161
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
162 162
 }
163 163
 
164 164
 /**
@@ -170,56 +170,56 @@  discard block
 block discarded – undo
170 170
  * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'.
171 171
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
172 172
  */
173
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
174
-    return getpaid_template()->locate_template( $template_name, $template_path, $default_path );
173
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
174
+    return getpaid_template()->locate_template($template_name, $template_path, $default_path);
175 175
 }
176 176
 
177
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
178
-	do_action( 'get_template_part_' . $slug, $slug, $name );
177
+function wpinv_get_template_part($slug, $name = null, $load = true) {
178
+	do_action('get_template_part_' . $slug, $slug, $name);
179 179
 
180 180
 	// Setup possible parts
181 181
 	$templates = array();
182
-	if ( isset( $name ) )
182
+	if (isset($name))
183 183
 		$templates[] = $slug . '-' . $name . '.php';
184 184
 	$templates[] = $slug . '.php';
185 185
 
186 186
 	// Allow template parts to be filtered
187
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
187
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
188 188
 
189 189
 	// Return the part that is found
190
-	return wpinv_locate_tmpl( $templates, $load, false );
190
+	return wpinv_locate_tmpl($templates, $load, false);
191 191
 }
192 192
 
193
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
193
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
194 194
 	// No file found yet
195 195
 	$located = false;
196 196
 
197 197
 	// Try to find a template file
198
-	foreach ( (array)$template_names as $template_name ) {
198
+	foreach ((array) $template_names as $template_name) {
199 199
 
200 200
 		// Continue if template is empty
201
-		if ( empty( $template_name ) )
201
+		if (empty($template_name))
202 202
 			continue;
203 203
 
204 204
 		// Trim off any slashes from the template name
205
-		$template_name = ltrim( $template_name, '/' );
205
+		$template_name = ltrim($template_name, '/');
206 206
 
207 207
 		// try locating this template file by looping through the template paths
208
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
208
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
209 209
 
210
-			if( file_exists( $template_path . $template_name ) ) {
210
+			if (file_exists($template_path . $template_name)) {
211 211
 				$located = $template_path . $template_name;
212 212
 				break;
213 213
 			}
214 214
 		}
215 215
 
216
-		if( !empty( $located ) ) {
216
+		if (!empty($located)) {
217 217
 			break;
218 218
 		}
219 219
 	}
220 220
 
221
-	if ( ( true == $load ) && ! empty( $located ) )
222
-		load_template( $located, $require_once );
221
+	if ((true == $load) && !empty($located))
222
+		load_template($located, $require_once);
223 223
 
224 224
 	return $located;
225 225
 }
@@ -228,127 +228,127 @@  discard block
 block discarded – undo
228 228
 	$template_dir = wpinv_get_theme_template_dir_name();
229 229
 
230 230
 	$file_paths = array(
231
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
232
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
231
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
232
+		10 => trailingslashit(get_template_directory()) . $template_dir,
233 233
 		100 => wpinv_get_templates_dir()
234 234
 	);
235 235
 
236
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
236
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
237 237
 
238 238
 	// sort the file paths based on priority
239
-	ksort( $file_paths, SORT_NUMERIC );
239
+	ksort($file_paths, SORT_NUMERIC);
240 240
 
241
-	return array_map( 'trailingslashit', $file_paths );
241
+	return array_map('trailingslashit', $file_paths);
242 242
 }
243 243
 
244 244
 function wpinv_checkout_meta_tags() {
245 245
 
246 246
 	$pages   = array();
247
-	$pages[] = wpinv_get_option( 'success_page' );
248
-	$pages[] = wpinv_get_option( 'failure_page' );
249
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
250
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
247
+	$pages[] = wpinv_get_option('success_page');
248
+	$pages[] = wpinv_get_option('failure_page');
249
+	$pages[] = wpinv_get_option('invoice_history_page');
250
+	$pages[] = wpinv_get_option('invoice_subscription_page');
251 251
 
252
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
252
+	if (!wpinv_is_checkout() && !is_page($pages)) {
253 253
 		return;
254 254
 	}
255 255
 
256 256
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
257 257
 }
258
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
258
+add_action('wp_head', 'wpinv_checkout_meta_tags');
259 259
 
260
-function wpinv_add_body_classes( $class ) {
261
-	$classes = (array)$class;
260
+function wpinv_add_body_classes($class) {
261
+	$classes = (array) $class;
262 262
 
263
-	if( wpinv_is_checkout() ) {
263
+	if (wpinv_is_checkout()) {
264 264
 		$classes[] = 'wpinv-checkout';
265 265
 		$classes[] = 'wpinv-page';
266 266
 	}
267 267
 
268
-	if( wpinv_is_success_page() ) {
268
+	if (wpinv_is_success_page()) {
269 269
 		$classes[] = 'wpinv-success';
270 270
 		$classes[] = 'wpinv-page';
271 271
 	}
272 272
 
273
-	if( wpinv_is_failed_transaction_page() ) {
273
+	if (wpinv_is_failed_transaction_page()) {
274 274
 		$classes[] = 'wpinv-failed-transaction';
275 275
 		$classes[] = 'wpinv-page';
276 276
 	}
277 277
 
278
-	if( wpinv_is_invoice_history_page() ) {
278
+	if (wpinv_is_invoice_history_page()) {
279 279
 		$classes[] = 'wpinv-history';
280 280
 		$classes[] = 'wpinv-page';
281 281
 	}
282 282
 
283
-	if( wpinv_is_subscriptions_history_page() ) {
283
+	if (wpinv_is_subscriptions_history_page()) {
284 284
 		$classes[] = 'wpinv-subscription';
285 285
 		$classes[] = 'wpinv-page';
286 286
 	}
287 287
 
288
-	if( wpinv_is_test_mode() ) {
288
+	if (wpinv_is_test_mode()) {
289 289
 		$classes[] = 'wpinv-test-mode';
290 290
 		$classes[] = 'wpinv-page';
291 291
 	}
292 292
 
293
-	return array_unique( $classes );
293
+	return array_unique($classes);
294 294
 }
295
-add_filter( 'body_class', 'wpinv_add_body_classes' );
295
+add_filter('body_class', 'wpinv_add_body_classes');
296 296
 
297
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
298
-    $current     = date( 'Y' );
299
-    $start_year  = $current - absint( $years_before );
300
-    $end_year    = $current + absint( $years_after );
301
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
297
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
298
+    $current     = date('Y');
299
+    $start_year  = $current - absint($years_before);
300
+    $end_year    = $current + absint($years_after);
301
+    $selected    = empty($selected) ? date('Y') : $selected;
302 302
     $options     = array();
303 303
 
304
-    while ( $start_year <= $end_year ) {
305
-        $options[ absint( $start_year ) ] = $start_year;
304
+    while ($start_year <= $end_year) {
305
+        $options[absint($start_year)] = $start_year;
306 306
         $start_year++;
307 307
     }
308 308
 
309
-    $output = wpinv_html_select( array(
309
+    $output = wpinv_html_select(array(
310 310
         'name'             => $name,
311 311
         'selected'         => $selected,
312 312
         'options'          => $options,
313 313
         'show_option_all'  => false,
314 314
         'show_option_none' => false
315
-    ) );
315
+    ));
316 316
 
317 317
     return $output;
318 318
 }
319 319
 
320
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
320
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
321 321
 
322 322
     $options = array(
323
-        '1'  => __( 'January', 'invoicing' ),
324
-        '2'  => __( 'February', 'invoicing' ),
325
-        '3'  => __( 'March', 'invoicing' ),
326
-        '4'  => __( 'April', 'invoicing' ),
327
-        '5'  => __( 'May', 'invoicing' ),
328
-        '6'  => __( 'June', 'invoicing' ),
329
-        '7'  => __( 'July', 'invoicing' ),
330
-        '8'  => __( 'August', 'invoicing' ),
331
-        '9'  => __( 'September', 'invoicing' ),
332
-        '10' => __( 'October', 'invoicing' ),
333
-        '11' => __( 'November', 'invoicing' ),
334
-        '12' => __( 'December', 'invoicing' ),
323
+        '1'  => __('January', 'invoicing'),
324
+        '2'  => __('February', 'invoicing'),
325
+        '3'  => __('March', 'invoicing'),
326
+        '4'  => __('April', 'invoicing'),
327
+        '5'  => __('May', 'invoicing'),
328
+        '6'  => __('June', 'invoicing'),
329
+        '7'  => __('July', 'invoicing'),
330
+        '8'  => __('August', 'invoicing'),
331
+        '9'  => __('September', 'invoicing'),
332
+        '10' => __('October', 'invoicing'),
333
+        '11' => __('November', 'invoicing'),
334
+        '12' => __('December', 'invoicing'),
335 335
     );
336 336
 
337 337
     // If no month is selected, default to the current month
338
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
338
+    $selected = empty($selected) ? date('n') : $selected;
339 339
 
340
-    $output = wpinv_html_select( array(
340
+    $output = wpinv_html_select(array(
341 341
         'name'             => $name,
342 342
         'selected'         => $selected,
343 343
         'options'          => $options,
344 344
         'show_option_all'  => false,
345 345
         'show_option_none' => false
346
-    ) );
346
+    ));
347 347
 
348 348
     return $output;
349 349
 }
350 350
 
351
-function wpinv_html_select( $args = array() ) {
351
+function wpinv_html_select($args = array()) {
352 352
     $defaults = array(
353 353
         'options'          => array(),
354 354
         'name'             => null,
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
         'selected'         => 0,
358 358
         'placeholder'      => null,
359 359
         'multiple'         => false,
360
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
361
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
360
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
361
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
362 362
         'data'             => array(),
363 363
         'onchange'         => null,
364 364
         'required'         => false,
@@ -366,74 +366,74 @@  discard block
 block discarded – undo
366 366
         'readonly'         => false,
367 367
     );
368 368
 
369
-    $args = wp_parse_args( $args, $defaults );
369
+    $args = wp_parse_args($args, $defaults);
370 370
 
371 371
     $data_elements = '';
372
-    foreach ( $args['data'] as $key => $value ) {
373
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
372
+    foreach ($args['data'] as $key => $value) {
373
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
374 374
     }
375 375
 
376
-    if( $args['multiple'] ) {
376
+    if ($args['multiple']) {
377 377
         $multiple = ' MULTIPLE';
378 378
     } else {
379 379
         $multiple = '';
380 380
     }
381 381
 
382
-    if( $args['placeholder'] ) {
382
+    if ($args['placeholder']) {
383 383
         $placeholder = $args['placeholder'];
384 384
     } else {
385 385
         $placeholder = '';
386 386
     }
387 387
     
388 388
     $options = '';
389
-    if( !empty( $args['onchange'] ) ) {
390
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
389
+    if (!empty($args['onchange'])) {
390
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
391 391
     }
392 392
     
393
-    if( !empty( $args['required'] ) ) {
393
+    if (!empty($args['required'])) {
394 394
         $options .= ' required="required"';
395 395
     }
396 396
     
397
-    if( !empty( $args['disabled'] ) ) {
397
+    if (!empty($args['disabled'])) {
398 398
         $options .= ' disabled';
399 399
     }
400 400
     
401
-    if( !empty( $args['readonly'] ) ) {
401
+    if (!empty($args['readonly'])) {
402 402
         $options .= ' readonly';
403 403
     }
404 404
 
405
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
406
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
405
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
406
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
407 407
 
408
-    if ( $args['show_option_all'] ) {
409
-        if( $args['multiple'] ) {
410
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
408
+    if ($args['show_option_all']) {
409
+        if ($args['multiple']) {
410
+            $selected = selected(true, in_array(0, $args['selected']), false);
411 411
         } else {
412
-            $selected = selected( $args['selected'], 0, false );
412
+            $selected = selected($args['selected'], 0, false);
413 413
         }
414
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
414
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
415 415
     }
416 416
 
417
-    if ( !empty( $args['options'] ) ) {
417
+    if (!empty($args['options'])) {
418 418
 
419
-        if ( $args['show_option_none'] ) {
420
-            if( $args['multiple'] ) {
421
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
419
+        if ($args['show_option_none']) {
420
+            if ($args['multiple']) {
421
+                $selected = selected(true, in_array("", $args['selected']), false);
422 422
             } else {
423
-                $selected = selected( $args['selected'] === "", true, false );
423
+                $selected = selected($args['selected'] === "", true, false);
424 424
             }
425
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
425
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
426 426
         }
427 427
 
428
-        foreach( $args['options'] as $key => $option ) {
428
+        foreach ($args['options'] as $key => $option) {
429 429
 
430
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
431
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
430
+            if ($args['multiple'] && is_array($args['selected'])) {
431
+                $selected = selected(true, (bool) in_array($key, $args['selected']), false);
432 432
             } else {
433
-                $selected = selected( $args['selected'], $key, false );
433
+                $selected = selected($args['selected'], $key, false);
434 434
             }
435 435
 
436
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
436
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
437 437
         }
438 438
     }
439 439
 
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
     return $output;
443 443
 }
444 444
 
445
-function wpinv_item_dropdown( $args = array() ) {
445
+function wpinv_item_dropdown($args = array()) {
446 446
     $defaults = array(
447 447
         'name'              => 'wpi_item',
448 448
         'id'                => 'wpi_item',
@@ -450,14 +450,14 @@  discard block
 block discarded – undo
450 450
         'multiple'          => false,
451 451
         'selected'          => 0,
452 452
         'number'            => 100,
453
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
454
-        'data'              => array( 'search-type' => 'item' ),
453
+        'placeholder'       => __('Choose a item', 'invoicing'),
454
+        'data'              => array('search-type' => 'item'),
455 455
         'show_option_all'   => false,
456 456
         'show_option_none'  => false,
457 457
         'show_recurring'    => false,
458 458
     );
459 459
 
460
-    $args = wp_parse_args( $args, $defaults );
460
+    $args = wp_parse_args($args, $defaults);
461 461
 
462 462
     $item_args = array(
463 463
         'post_type'      => 'wpi_item',
@@ -466,44 +466,44 @@  discard block
 block discarded – undo
466 466
         'posts_per_page' => $args['number']
467 467
     );
468 468
 
469
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
469
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
470 470
 
471
-    $items      = get_posts( $item_args );
471
+    $items      = get_posts($item_args);
472 472
     $options    = array();
473
-    if ( $items ) {
474
-        foreach ( $items as $item ) {
475
-            $title = esc_html( $item->post_title );
473
+    if ($items) {
474
+        foreach ($items as $item) {
475
+            $title = esc_html($item->post_title);
476 476
             
477
-            if ( !empty( $args['show_recurring'] ) ) {
478
-                $title .= wpinv_get_item_suffix( $item->ID, false );
477
+            if (!empty($args['show_recurring'])) {
478
+                $title .= wpinv_get_item_suffix($item->ID, false);
479 479
             }
480 480
             
481
-            $options[ absint( $item->ID ) ] = $title;
481
+            $options[absint($item->ID)] = $title;
482 482
         }
483 483
     }
484 484
 
485 485
     // This ensures that any selected items are included in the drop down
486
-    if( is_array( $args['selected'] ) ) {
487
-        foreach( $args['selected'] as $item ) {
488
-            if( ! in_array( $item, $options ) ) {
489
-                $title = get_the_title( $item );
490
-                if ( !empty( $args['show_recurring'] ) ) {
491
-                    $title .= wpinv_get_item_suffix( $item, false );
486
+    if (is_array($args['selected'])) {
487
+        foreach ($args['selected'] as $item) {
488
+            if (!in_array($item, $options)) {
489
+                $title = get_the_title($item);
490
+                if (!empty($args['show_recurring'])) {
491
+                    $title .= wpinv_get_item_suffix($item, false);
492 492
                 }
493 493
                 $options[$item] = $title;
494 494
             }
495 495
         }
496
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
497
-        if ( ! in_array( $args['selected'], $options ) ) {
498
-            $title = get_the_title( $args['selected'] );
499
-            if ( !empty( $args['show_recurring'] ) ) {
500
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
496
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
497
+        if (!in_array($args['selected'], $options)) {
498
+            $title = get_the_title($args['selected']);
499
+            if (!empty($args['show_recurring'])) {
500
+                $title .= wpinv_get_item_suffix($args['selected'], false);
501 501
             }
502
-            $options[$args['selected']] = get_the_title( $args['selected'] );
502
+            $options[$args['selected']] = get_the_title($args['selected']);
503 503
         }
504 504
     }
505 505
 
506
-    $output = wpinv_html_select( array(
506
+    $output = wpinv_html_select(array(
507 507
         'name'             => $args['name'],
508 508
         'selected'         => $args['selected'],
509 509
         'id'               => $args['id'],
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
         'show_option_all'  => $args['show_option_all'],
515 515
         'show_option_none' => $args['show_option_none'],
516 516
         'data'             => $args['data'],
517
-    ) );
517
+    ));
518 518
 
519 519
     return $output;
520 520
 }
@@ -534,16 +534,16 @@  discard block
 block discarded – undo
534 534
     );
535 535
 
536 536
     $options = array();
537
-    if ( $items ) {
538
-        foreach ( $items as $item ) {
539
-            $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false );
537
+    if ($items) {
538
+        foreach ($items as $item) {
539
+            $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false);
540 540
         }
541 541
     }
542 542
 
543 543
     return $options;
544 544
 }
545 545
 
546
-function wpinv_html_checkbox( $args = array() ) {
546
+function wpinv_html_checkbox($args = array()) {
547 547
     $defaults = array(
548 548
         'name'     => null,
549 549
         'current'  => null,
@@ -554,17 +554,17 @@  discard block
 block discarded – undo
554 554
         )
555 555
     );
556 556
 
557
-    $args = wp_parse_args( $args, $defaults );
557
+    $args = wp_parse_args($args, $defaults);
558 558
 
559
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
559
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
560 560
     $options = '';
561
-    if ( ! empty( $args['options']['disabled'] ) ) {
561
+    if (!empty($args['options']['disabled'])) {
562 562
         $options .= ' disabled="disabled"';
563
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
563
+    } elseif (!empty($args['options']['readonly'])) {
564 564
         $options .= ' readonly';
565 565
     }
566 566
 
567
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
567
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
568 568
 
569 569
     return $output;
570 570
 }
@@ -572,30 +572,30 @@  discard block
 block discarded – undo
572 572
 /**
573 573
  * Displays a hidden field.
574 574
  */
575
-function getpaid_hidden_field( $name, $value ) {
576
-    $name  = sanitize_text_field( $name );
577
-    $value = esc_attr( $value );
575
+function getpaid_hidden_field($name, $value) {
576
+    $name  = sanitize_text_field($name);
577
+    $value = esc_attr($value);
578 578
 
579 579
     echo "<input type='hidden' name='$name' value='$value' />";
580 580
 }
581 581
 
582
-function wpinv_html_text( $args = array() ) {
582
+function wpinv_html_text($args = array()) {
583 583
     // Backwards compatibility
584
-    if ( func_num_args() > 1 ) {
584
+    if (func_num_args() > 1) {
585 585
         $args = func_get_args();
586 586
 
587 587
         $name  = $args[0];
588
-        $value = isset( $args[1] ) ? $args[1] : '';
589
-        $label = isset( $args[2] ) ? $args[2] : '';
590
-        $desc  = isset( $args[3] ) ? $args[3] : '';
588
+        $value = isset($args[1]) ? $args[1] : '';
589
+        $label = isset($args[2]) ? $args[2] : '';
590
+        $desc  = isset($args[3]) ? $args[3] : '';
591 591
     }
592 592
 
593 593
     $defaults = array(
594 594
         'id'           => '',
595
-        'name'         => isset( $name )  ? $name  : 'text',
596
-        'value'        => isset( $value ) ? $value : null,
597
-        'label'        => isset( $label ) ? $label : null,
598
-        'desc'         => isset( $desc )  ? $desc  : null,
595
+        'name'         => isset($name) ? $name : 'text',
596
+        'value'        => isset($value) ? $value : null,
597
+        'label'        => isset($label) ? $label : null,
598
+        'desc'         => isset($desc) ? $desc : null,
599 599
         'placeholder'  => '',
600 600
         'class'        => 'regular-text',
601 601
         'disabled'     => false,
@@ -605,51 +605,51 @@  discard block
 block discarded – undo
605 605
         'data'         => false
606 606
     );
607 607
 
608
-    $args = wp_parse_args( $args, $defaults );
608
+    $args = wp_parse_args($args, $defaults);
609 609
 
610
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
610
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
611 611
     $options = '';
612
-    if( $args['required'] ) {
612
+    if ($args['required']) {
613 613
         $options .= ' required="required"';
614 614
     }
615
-    if( $args['readonly'] ) {
615
+    if ($args['readonly']) {
616 616
         $options .= ' readonly';
617 617
     }
618
-    if( $args['readonly'] ) {
618
+    if ($args['readonly']) {
619 619
         $options .= ' readonly';
620 620
     }
621 621
 
622 622
     $data = '';
623
-    if ( !empty( $args['data'] ) ) {
624
-        foreach ( $args['data'] as $key => $value ) {
625
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
623
+    if (!empty($args['data'])) {
624
+        foreach ($args['data'] as $key => $value) {
625
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
626 626
         }
627 627
     }
628 628
 
629
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
630
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
631
-    if ( ! empty( $args['desc'] ) ) {
632
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
629
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
630
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
631
+    if (!empty($args['desc'])) {
632
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
633 633
     }
634 634
 
635
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
635
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
636 636
 
637 637
     $output .= '</span>';
638 638
 
639 639
     return $output;
640 640
 }
641 641
 
642
-function wpinv_html_date_field( $args = array() ) {
643
-    if( empty( $args['class'] ) ) {
642
+function wpinv_html_date_field($args = array()) {
643
+    if (empty($args['class'])) {
644 644
         $args['class'] = 'wpiDatepicker';
645
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
645
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
646 646
         $args['class'] .= ' wpiDatepicker';
647 647
     }
648 648
 
649
-    return wpinv_html_text( $args );
649
+    return wpinv_html_text($args);
650 650
 }
651 651
 
652
-function wpinv_html_textarea( $args = array() ) {
652
+function wpinv_html_textarea($args = array()) {
653 653
     $defaults = array(
654 654
         'name'        => 'textarea',
655 655
         'value'       => null,
@@ -660,31 +660,31 @@  discard block
 block discarded – undo
660 660
         'placeholder' => '',
661 661
     );
662 662
 
663
-    $args = wp_parse_args( $args, $defaults );
663
+    $args = wp_parse_args($args, $defaults);
664 664
 
665
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
665
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
666 666
     $disabled = '';
667
-    if( $args['disabled'] ) {
667
+    if ($args['disabled']) {
668 668
         $disabled = ' disabled="disabled"';
669 669
     }
670 670
 
671
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
672
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
673
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
671
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
672
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
673
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
674 674
 
675
-    if ( ! empty( $args['desc'] ) ) {
676
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
675
+    if (!empty($args['desc'])) {
676
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
677 677
     }
678 678
     $output .= '</span>';
679 679
 
680 680
     return $output;
681 681
 }
682 682
 
683
-function wpinv_html_ajax_user_search( $args = array() ) {
683
+function wpinv_html_ajax_user_search($args = array()) {
684 684
     $defaults = array(
685 685
         'name'        => 'user_id',
686 686
         'value'       => null,
687
-        'placeholder' => __( 'Enter username', 'invoicing' ),
687
+        'placeholder' => __('Enter username', 'invoicing'),
688 688
         'label'       => null,
689 689
         'desc'        => null,
690 690
         'class'       => '',
@@ -693,13 +693,13 @@  discard block
 block discarded – undo
693 693
         'data'        => false
694 694
     );
695 695
 
696
-    $args = wp_parse_args( $args, $defaults );
696
+    $args = wp_parse_args($args, $defaults);
697 697
 
698 698
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
699 699
 
700 700
     $output  = '<span class="wpinv_user_search_wrap">';
701
-        $output .= wpinv_html_text( $args );
702
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
701
+        $output .= wpinv_html_text($args);
702
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
703 703
     $output .= '</span>';
704 704
 
705 705
     return $output;
@@ -715,20 +715,20 @@  discard block
 block discarded – undo
715 715
  * 
716 716
  * @param string $template the template that is currently being used.
717 717
  */
718
-function wpinv_template( $template ) {
718
+function wpinv_template($template) {
719 719
     global $post;
720 720
 
721
-    if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) {
721
+    if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) {
722 722
 
723 723
         // If the user can view this invoice, display it.
724
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
724
+        if (wpinv_user_can_view_invoice($post->ID)) {
725 725
 
726
-            return wpinv_get_template_part( 'wpinv-invoice-print', false, false );
726
+            return wpinv_get_template_part('wpinv-invoice-print', false, false);
727 727
 
728 728
         // Else display an error message.
729 729
         } else {
730 730
 
731
-            return wpinv_get_template_part( 'wpinv-invalid-access', false, false );
731
+            return wpinv_get_template_part('wpinv-invalid-access', false, false);
732 732
 
733 733
         }
734 734
 
@@ -736,46 +736,46 @@  discard block
 block discarded – undo
736 736
 
737 737
     return $template;
738 738
 }
739
-add_filter( 'template_include', 'wpinv_template', 10, 1 );
739
+add_filter('template_include', 'wpinv_template', 10, 1);
740 740
 
741 741
 function wpinv_get_business_address() {
742 742
     $business_address   = wpinv_store_address();
743
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
743
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
744 744
     
745 745
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
746 746
     
747
-    return apply_filters( 'wpinv_get_business_address', $business_address );
747
+    return apply_filters('wpinv_get_business_address', $business_address);
748 748
 }
749 749
 
750 750
 /**
751 751
  * Displays the company address.
752 752
  */
753 753
 function wpinv_display_from_address() {
754
-    wpinv_get_template( 'invoice/company-address.php' );
754
+    wpinv_get_template('invoice/company-address.php');
755 755
 }
756
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 );
756
+add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10);
757 757
 
758
-function wpinv_watermark( $id = 0 ) {
759
-    $output = wpinv_get_watermark( $id );
760
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
758
+function wpinv_watermark($id = 0) {
759
+    $output = wpinv_get_watermark($id);
760
+    return apply_filters('wpinv_get_watermark', $output, $id);
761 761
 }
762 762
 
763
-function wpinv_get_watermark( $id ) {
764
-    if ( !$id > 0 ) {
763
+function wpinv_get_watermark($id) {
764
+    if (!$id > 0) {
765 765
         return NULL;
766 766
     }
767 767
 
768
-    $invoice = wpinv_get_invoice( $id );
768
+    $invoice = wpinv_get_invoice($id);
769 769
     
770
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
771
-        if ( $invoice->is_paid() ) {
772
-            return __( 'Paid', 'invoicing' );
770
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
771
+        if ($invoice->is_paid()) {
772
+            return __('Paid', 'invoicing');
773 773
         }
774
-        if ( $invoice->is_refunded() ) {
775
-            return __( 'Refunded', 'invoicing' );
774
+        if ($invoice->is_refunded()) {
775
+            return __('Refunded', 'invoicing');
776 776
         }
777
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
778
-            return __( 'Cancelled', 'invoicing' );
777
+        if ($invoice->has_status(array('wpi-cancelled'))) {
778
+            return __('Cancelled', 'invoicing');
779 779
         }
780 780
     }
781 781
     
@@ -785,30 +785,30 @@  discard block
 block discarded – undo
785 785
 /**
786 786
  * @deprecated
787 787
  */
788
-function wpinv_display_invoice_details( $invoice ) {
789
-    return getpaid_invoice_meta( $invoice );
788
+function wpinv_display_invoice_details($invoice) {
789
+    return getpaid_invoice_meta($invoice);
790 790
 }
791 791
 
792 792
 /**
793 793
  * Displays invoice meta.
794 794
  */
795
-function getpaid_invoice_meta( $invoice ) {
795
+function getpaid_invoice_meta($invoice) {
796 796
 
797
-    $invoice = new WPInv_Invoice( $invoice );
797
+    $invoice = new WPInv_Invoice($invoice);
798 798
 
799 799
     // Ensure that we have an invoice.
800
-    if ( 0 == $invoice->get_id() ) {
800
+    if (0 == $invoice->get_id()) {
801 801
         return;
802 802
     }
803 803
 
804 804
     // Get the invoice meta.
805
-    $meta = getpaid_get_invoice_meta( $invoice );
805
+    $meta = getpaid_get_invoice_meta($invoice);
806 806
 
807 807
     // Display the meta.
808
-    wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) );
808
+    wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta'));
809 809
 
810 810
 }
811
-add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 );
811
+add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10);
812 812
 
813 813
 /**
814 814
  * Retrieves the address markup to use on Invoices.
@@ -820,29 +820,29 @@  discard block
 block discarded – undo
820 820
  * @param  string $separator How to separate address lines.
821 821
  * @return string
822 822
  */
823
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
823
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
824 824
 
825 825
     // Retrieve the address markup...
826
-    $country= empty( $billing_details['country'] ) ? '' : $billing_details['country'];
827
-    $format = wpinv_get_full_address_format( $country );
826
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
827
+    $format = wpinv_get_full_address_format($country);
828 828
 
829 829
     // ... and the replacements.
830
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
830
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
831 831
 
832
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
832
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
833 833
     
834 834
 	// Remove unavailable tags.
835
-    $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
835
+    $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address);
836 836
 
837 837
     // Clean up white space.
838
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
839
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
838
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
839
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
840 840
     
841 841
     // Break newlines apart and remove empty lines/trim commas and white space.
842
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
842
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
843 843
 
844 844
     // Add html breaks.
845
-	$formatted_address = implode( $separator, $formatted_address );
845
+	$formatted_address = implode($separator, $formatted_address);
846 846
 
847 847
 	// We're done!
848 848
 	return $formatted_address;
@@ -854,88 +854,88 @@  discard block
 block discarded – undo
854 854
  * 
855 855
  * @param WPInv_Invoice $invoice
856 856
  */
857
-function wpinv_display_to_address( $invoice = 0 ) {
858
-    if ( ! empty( $invoice ) ) {
859
-        wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) );
857
+function wpinv_display_to_address($invoice = 0) {
858
+    if (!empty($invoice)) {
859
+        wpinv_get_template('invoice/billing-address.php', compact('invoice'));
860 860
     }
861 861
 }
862
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 );
862
+add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40);
863 863
 
864 864
 
865 865
 /**
866 866
  * Displays invoice line items.
867 867
  */
868
-function wpinv_display_line_items( $invoice_id = 0 ) {
868
+function wpinv_display_line_items($invoice_id = 0) {
869 869
 
870 870
     // Prepare the invoice.
871
-    $invoice = new WPInv_Invoice( $invoice_id );
871
+    $invoice = new WPInv_Invoice($invoice_id);
872 872
 
873 873
     // Abort if there is no invoice.
874
-    if ( 0 == $invoice->get_id() ) {
874
+    if (0 == $invoice->get_id()) {
875 875
         return;
876 876
     }
877 877
 
878 878
     // Line item columns.
879
-    $columns = getpaid_invoice_item_columns( $invoice );
880
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
879
+    $columns = getpaid_invoice_item_columns($invoice);
880
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
881 881
 
882
-    wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) );
882
+    wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns'));
883 883
 }
884
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 );
884
+add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10);
885 885
 
886 886
 /**
887 887
  * Displays invoice notices on invoices.
888 888
  */
889 889
 function wpinv_display_invoice_notice() {
890 890
 
891
-    $label  = wpinv_get_option( 'vat_invoice_notice_label' );
892
-    $notice = wpinv_get_option( 'vat_invoice_notice' );
891
+    $label  = wpinv_get_option('vat_invoice_notice_label');
892
+    $notice = wpinv_get_option('vat_invoice_notice');
893 893
 
894
-    if ( empty( $label ) && empty( $notice ) ) {
894
+    if (empty($label) && empty($notice)) {
895 895
         return;
896 896
     }
897 897
 
898 898
     echo '<div class="mt-4 mb-4 wpinv-vat-notice">';
899 899
 
900
-    if ( ! empty( $label ) ) {
901
-        $label = sanitize_text_field( $label );
900
+    if (!empty($label)) {
901
+        $label = sanitize_text_field($label);
902 902
         echo "<h5>$label</h5>";
903 903
     }
904 904
 
905
-    if ( ! empty( $notice ) ) {
906
-        echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>';
905
+    if (!empty($notice)) {
906
+        echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>';
907 907
     }
908 908
 
909 909
     echo '</div>';
910 910
 }
911
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 );
911
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100);
912 912
 
913 913
 /**
914 914
  * @param WPInv_Invoice $invoice
915 915
  */
916
-function wpinv_display_invoice_notes( $invoice ) {
916
+function wpinv_display_invoice_notes($invoice) {
917 917
 
918 918
     // Retrieve the notes.
919
-    $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' );
919
+    $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer');
920 920
 
921 921
     // Abort if we have non.
922
-    if ( empty( $notes ) ) {
922
+    if (empty($notes)) {
923 923
         return;
924 924
     }
925 925
 
926 926
     // Echo the note.
927 927
     echo '<div class="getpaid-invoice-notes-wrapper border position-relative w-100 mb-4 p-0">';
928
-    echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __( 'Notes', 'invoicing' ) .'</h3>';
928
+    echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __('Notes', 'invoicing') . '</h3>';
929 929
     echo '<ul class="getpaid-invoice-notes mt-4 p-0">';
930 930
 
931
-    foreach( $notes as $note ) {
932
-        wpinv_get_invoice_note_line_item( $note );
931
+    foreach ($notes as $note) {
932
+        wpinv_get_invoice_note_line_item($note);
933 933
     }
934 934
 
935 935
     echo '</ul>';
936 936
     echo '</div>';
937 937
 }
938
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 );
938
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60);
939 939
 
940 940
 /**
941 941
  * Loads scripts on our invoice templates.
@@ -943,32 +943,32 @@  discard block
 block discarded – undo
943 943
 function wpinv_display_style() {
944 944
 
945 945
     // Make sure that all scripts have been loaded.
946
-    if ( ! did_action( 'wp_enqueue_scripts' ) ) {
947
-        do_action( 'wp_enqueue_scripts' );
946
+    if (!did_action('wp_enqueue_scripts')) {
947
+        do_action('wp_enqueue_scripts');
948 948
     }
949 949
 
950 950
     // Register the invoices style.
951
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) );
951
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css'));
952 952
 
953 953
     // Load required styles
954
-    wp_print_styles( 'open-sans' );
955
-    wp_print_styles( 'wpinv-single-style' );
956
-    wp_print_styles( 'ayecode-ui' );
954
+    wp_print_styles('open-sans');
955
+    wp_print_styles('wpinv-single-style');
956
+    wp_print_styles('ayecode-ui');
957 957
 
958 958
     // Maybe load custom css.
959
-    $custom_css = wpinv_get_option( 'template_custom_css' );
959
+    $custom_css = wpinv_get_option('template_custom_css');
960 960
 
961
-    if ( isset( $custom_css ) && ! empty( $custom_css ) ) {
962
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
963
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
961
+    if (isset($custom_css) && !empty($custom_css)) {
962
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
963
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
964 964
         echo '<style type="text/css">';
965 965
         echo $custom_css;
966 966
         echo '</style>';
967 967
     }
968 968
 
969 969
 }
970
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
971
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
970
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
971
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
972 972
 
973 973
 
974 974
 /**
@@ -980,41 +980,41 @@  discard block
 block discarded – undo
980 980
     // Retrieve the current invoice.
981 981
     $invoice_id = getpaid_get_current_invoice_id();
982 982
 
983
-    if ( empty( $invoice_id ) ) {
983
+    if (empty($invoice_id)) {
984 984
 
985 985
         return aui()->alert(
986 986
             array(
987 987
                 'type'    => 'warning',
988
-                'content' => __( 'Invalid invoice', 'invoicing' ),
988
+                'content' => __('Invalid invoice', 'invoicing'),
989 989
             )
990 990
         );
991 991
 
992 992
     }
993 993
 
994 994
     // Can the user view this invoice?
995
-    if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) {
995
+    if (!wpinv_user_can_view_invoice($invoice_id)) {
996 996
 
997 997
         return aui()->alert(
998 998
             array(
999 999
                 'type'    => 'warning',
1000
-                'content' => __( 'You are not allowed to view this invoice', 'invoicing' ),
1000
+                'content' => __('You are not allowed to view this invoice', 'invoicing'),
1001 1001
             )
1002 1002
         );
1003 1003
 
1004 1004
     }
1005 1005
 
1006 1006
     // Ensure that it is not yet paid for.
1007
-    $invoice = new WPInv_Invoice( $invoice_id );
1007
+    $invoice = new WPInv_Invoice($invoice_id);
1008 1008
 
1009 1009
     // Maybe mark it as viewed.
1010
-    getpaid_maybe_mark_invoice_as_viewed( $invoice );
1010
+    getpaid_maybe_mark_invoice_as_viewed($invoice);
1011 1011
 
1012
-    if ( $invoice->is_paid() ) {
1012
+    if ($invoice->is_paid()) {
1013 1013
 
1014 1014
         return aui()->alert(
1015 1015
             array(
1016 1016
                 'type'    => 'success',
1017
-                'content' => __( 'This invoice has already been paid.', 'invoicing' ),
1017
+                'content' => __('This invoice has already been paid.', 'invoicing'),
1018 1018
             )
1019 1019
         );
1020 1020
 
@@ -1024,14 +1024,14 @@  discard block
 block discarded – undo
1024 1024
     $wpi_checkout_id = $invoice_id;
1025 1025
 
1026 1026
     // We'll display this invoice via the default form.
1027
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1027
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1028 1028
 
1029
-    if ( 0 == $form->get_id() ) {
1029
+    if (0 == $form->get_id()) {
1030 1030
 
1031 1031
         return aui()->alert(
1032 1032
             array(
1033 1033
                 'type'    => 'warning',
1034
-                'content' => __( 'Error loading the payment form', 'invoicing' ),
1034
+                'content' => __('Error loading the payment form', 'invoicing'),
1035 1035
             )
1036 1036
         );
1037 1037
 
@@ -1039,7 +1039,7 @@  discard block
 block discarded – undo
1039 1039
 
1040 1040
     // Set the invoice.
1041 1041
     $form->invoice = $invoice;
1042
-    $form->set_items( $invoice->get_items() );
1042
+    $form->set_items($invoice->get_items());
1043 1043
 
1044 1044
     // Generate the html.
1045 1045
     return $form->get_html();
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
 }
1048 1048
 
1049 1049
 function wpinv_empty_cart_message() {
1050
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1050
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1051 1051
 }
1052 1052
 
1053 1053
 /**
@@ -1064,38 +1064,38 @@  discard block
 block discarded – undo
1064 1064
         )
1065 1065
     );
1066 1066
 }
1067
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1067
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1068 1068
 
1069
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1070
-    $invoice = wpinv_get_invoice( $invoice_id );
1069
+function wpinv_receipt_billing_address($invoice_id = 0) {
1070
+    $invoice = wpinv_get_invoice($invoice_id);
1071 1071
 
1072
-    if ( empty( $invoice ) ) {
1072
+    if (empty($invoice)) {
1073 1073
         return NULL;
1074 1074
     }
1075 1075
 
1076 1076
     $billing_details = $invoice->get_user_info();
1077
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
1077
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
1078 1078
 
1079 1079
     ob_start();
1080 1080
     ?>
1081 1081
     <table class="table table-bordered table-sm wpi-billing-details">
1082 1082
         <tbody>
1083 1083
             <tr class="wpi-receipt-name">
1084
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1085
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1084
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1085
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1086 1086
             </tr>
1087 1087
             <tr class="wpi-receipt-email">
1088
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1089
-                <td><?php echo $billing_details['email'] ;?></td>
1088
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1089
+                <td><?php echo $billing_details['email']; ?></td>
1090 1090
             </tr>
1091 1091
             <tr class="wpi-receipt-address">
1092
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1093
-                <td><?php echo $address_row ;?></td>
1092
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1093
+                <td><?php echo $address_row; ?></td>
1094 1094
             </tr>
1095
-            <?php if ( $billing_details['phone'] ) { ?>
1095
+            <?php if ($billing_details['phone']) { ?>
1096 1096
             <tr class="wpi-receipt-phone">
1097
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1098
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1097
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1098
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1099 1099
             </tr>
1100 1100
             <?php } ?>
1101 1101
         </tbody>
@@ -1103,7 +1103,7 @@  discard block
 block discarded – undo
1103 1103
     <?php
1104 1104
     $output = ob_get_clean();
1105 1105
     
1106
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1106
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1107 1107
 
1108 1108
     echo $output;
1109 1109
 }
@@ -1111,66 +1111,66 @@  discard block
 block discarded – undo
1111 1111
 /**
1112 1112
  * Filters the receipt page.
1113 1113
  */
1114
-function wpinv_filter_success_page_content( $content ) {
1114
+function wpinv_filter_success_page_content($content) {
1115 1115
 
1116 1116
     // Ensure this is our page.
1117
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1117
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1118 1118
 
1119
-        $gateway = sanitize_text_field( $_GET['payment-confirm'] );
1120
-        return apply_filters( "wpinv_payment_confirm_$gateway", $content );
1119
+        $gateway = sanitize_text_field($_GET['payment-confirm']);
1120
+        return apply_filters("wpinv_payment_confirm_$gateway", $content);
1121 1121
 
1122 1122
     }
1123 1123
 
1124 1124
     return $content;
1125 1125
 }
1126
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1126
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1127 1127
 
1128
-function wpinv_invoice_link( $invoice_id ) {
1129
-    $invoice = wpinv_get_invoice( $invoice_id );
1128
+function wpinv_invoice_link($invoice_id) {
1129
+    $invoice = wpinv_get_invoice($invoice_id);
1130 1130
 
1131
-    if ( empty( $invoice ) ) {
1131
+    if (empty($invoice)) {
1132 1132
         return NULL;
1133 1133
     }
1134 1134
 
1135
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1135
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1136 1136
 
1137
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1137
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1138 1138
 }
1139 1139
 
1140
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
1141
-    if ( empty( $note ) ) {
1140
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
1141
+    if (empty($note)) {
1142 1142
         return NULL;
1143 1143
     }
1144 1144
 
1145
-    if ( is_int( $note ) ) {
1146
-        $note = get_comment( $note );
1145
+    if (is_int($note)) {
1146
+        $note = get_comment($note);
1147 1147
     }
1148 1148
 
1149
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
1149
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
1150 1150
         return NULL;
1151 1151
     }
1152 1152
 
1153
-    $note_classes   = array( 'note' );
1154
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
1153
+    $note_classes   = array('note');
1154
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
1155 1155
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
1156
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
1157
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
1156
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
1157
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
1158 1158
 
1159 1159
     ob_start();
1160 1160
     ?>
1161
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mt-4 pl-3 pr-3">
1161
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mt-4 pl-3 pr-3">
1162 1162
         <div class="note_content bg-light border position-relative p-4">
1163 1163
 
1164
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
1164
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
1165 1165
 
1166
-            <?php if ( ! is_admin() ) : ?>
1166
+            <?php if (!is_admin()) : ?>
1167 1167
                 <em class="meta position-absolute form-text">
1168 1168
                     <?php
1169 1169
                         printf(
1170
-                            __( '%1$s - %2$s at %3$s', 'invoicing' ),
1170
+                            __('%1$s - %2$s at %3$s', 'invoicing'),
1171 1171
                             $note->comment_author,
1172
-                            getpaid_format_date_value( $note->comment_date ),
1173
-                            date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) )
1172
+                            getpaid_format_date_value($note->comment_date),
1173
+                            date_i18n(get_option('time_format'), strtotime($note->comment_date))
1174 1174
                         );
1175 1175
                     ?>
1176 1176
                 </em>
@@ -1178,21 +1178,21 @@  discard block
 block discarded – undo
1178 1178
 
1179 1179
         </div>
1180 1180
 
1181
-        <?php if ( is_admin() ) : ?>
1181
+        <?php if (is_admin()) : ?>
1182 1182
 
1183 1183
             <p class="meta px-4 py-2">
1184
-                <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>">
1184
+                <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>">
1185 1185
                     <?php
1186 1186
                         printf(
1187
-                            __( '%1$s - %2$s at %3$s', 'invoicing' ),
1187
+                            __('%1$s - %2$s at %3$s', 'invoicing'),
1188 1188
                             $note->comment_author,
1189
-                            getpaid_format_date_value( $note->comment_date ),
1190
-                            date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) )
1189
+                            getpaid_format_date_value($note->comment_date),
1190
+                            date_i18n(get_option('time_format'), strtotime($note->comment_date))
1191 1191
                         );
1192 1192
                     ?>
1193 1193
                 </abbr>&nbsp;&nbsp;
1194
-                <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?>
1195
-                    <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
1194
+                <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?>
1195
+                    <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
1196 1196
                 <?php } ?>
1197 1197
             </p>
1198 1198
 
@@ -1201,9 +1201,9 @@  discard block
 block discarded – undo
1201 1201
     </li>
1202 1202
     <?php
1203 1203
     $note_content = ob_get_clean();
1204
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
1204
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
1205 1205
 
1206
-    if ( $echo ) {
1206
+    if ($echo) {
1207 1207
         echo $note_content;
1208 1208
     } else {
1209 1209
         return $note_content;
@@ -1213,36 +1213,36 @@  discard block
 block discarded – undo
1213 1213
 function wpinv_invalid_invoice_content() {
1214 1214
     global $post;
1215 1215
 
1216
-    $invoice = wpinv_get_invoice( $post->ID );
1216
+    $invoice = wpinv_get_invoice($post->ID);
1217 1217
 
1218
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' );
1219
-    if ( !empty( $invoice->get_id() ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
1220
-        if ( is_user_logged_in() ) {
1221
-            if ( wpinv_require_login_to_checkout() ) {
1222
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
1223
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
1218
+    $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing');
1219
+    if (!empty($invoice->get_id()) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
1220
+        if (is_user_logged_in()) {
1221
+            if (wpinv_require_login_to_checkout()) {
1222
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
1223
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
1224 1224
                 }
1225 1225
             }
1226 1226
         } else {
1227
-            if ( wpinv_require_login_to_checkout() ) {
1228
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
1229
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
1227
+            if (wpinv_require_login_to_checkout()) {
1228
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
1229
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
1230 1230
                 }
1231 1231
             }
1232 1232
         }
1233 1233
     } else {
1234
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
1234
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
1235 1235
     }
1236 1236
     ?>
1237 1237
     <div class="row wpinv-row-invalid">
1238 1238
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
1239
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
1239
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
1240 1240
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
1241 1241
         </div>
1242 1242
     </div>
1243 1243
     <?php
1244 1244
 }
1245
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
1245
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
1246 1246
 
1247 1247
 /**
1248 1248
  * Function to get privacy policy text.
@@ -1251,21 +1251,21 @@  discard block
 block discarded – undo
1251 1251
  * @return string
1252 1252
  */
1253 1253
 function wpinv_get_policy_text() {
1254
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
1254
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
1255 1255
 
1256
-    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ));
1256
+    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'));
1257 1257
 
1258
-    if(!$privacy_page_id){
1259
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
1258
+    if (!$privacy_page_id) {
1259
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
1260 1260
     }
1261 1261
 
1262
-    $privacy_link    = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' );
1262
+    $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing');
1263 1263
 
1264 1264
     $find_replace = array(
1265 1265
         '[wpinv_privacy_policy]' => $privacy_link,
1266 1266
     );
1267 1267
 
1268
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
1268
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
1269 1269
 
1270 1270
     return wp_kses_post(wpautop($privacy_text));
1271 1271
 }
@@ -1273,21 +1273,21 @@  discard block
 block discarded – undo
1273 1273
 function wpinv_oxygen_fix_conflict() {
1274 1274
     global $ct_ignore_post_types;
1275 1275
 
1276
-    if ( ! is_array( $ct_ignore_post_types ) ) {
1276
+    if (!is_array($ct_ignore_post_types)) {
1277 1277
         $ct_ignore_post_types = array();
1278 1278
     }
1279 1279
 
1280
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' );
1280
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item');
1281 1281
 
1282
-    foreach ( $post_types as $post_type ) {
1282
+    foreach ($post_types as $post_type) {
1283 1283
         $ct_ignore_post_types[] = $post_type;
1284 1284
 
1285 1285
         // Ignore post type
1286
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
1286
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
1287 1287
     }
1288 1288
 
1289
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
1290
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
1289
+    remove_filter('template_include', 'wpinv_template', 10, 1);
1290
+    add_filter('template_include', 'wpinv_template', 999, 1);
1291 1291
 }
1292 1292
 
1293 1293
 /**
@@ -1295,10 +1295,10 @@  discard block
 block discarded – undo
1295 1295
  * 
1296 1296
  * @param GetPaid_Payment_Form $form
1297 1297
  */
1298
-function getpaid_display_payment_form( $form ) {
1298
+function getpaid_display_payment_form($form) {
1299 1299
 
1300
-    if ( is_numeric( $form ) ) {
1301
-        $form = new GetPaid_Payment_Form( $form );
1300
+    if (is_numeric($form)) {
1301
+        $form = new GetPaid_Payment_Form($form);
1302 1302
     }
1303 1303
 
1304 1304
     $form->display();
@@ -1308,55 +1308,55 @@  discard block
 block discarded – undo
1308 1308
 /**
1309 1309
  * Helper function to display a item payment form on the frontend.
1310 1310
  */
1311
-function getpaid_display_item_payment_form( $items ) {
1311
+function getpaid_display_item_payment_form($items) {
1312 1312
 
1313
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1314
-    $form->set_items( $items );
1313
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1314
+    $form->set_items($items);
1315 1315
 
1316
-    if ( 0 == count( $form->get_items() ) ) {
1316
+    if (0 == count($form->get_items())) {
1317 1317
         echo aui()->alert(
1318 1318
 			array(
1319 1319
 				'type'    => 'warning',
1320
-				'content' => __( 'No published items found', 'invoicing' ),
1320
+				'content' => __('No published items found', 'invoicing'),
1321 1321
 			)
1322 1322
         );
1323 1323
         return;
1324 1324
     }
1325 1325
 
1326
-    $form_items = esc_attr( getpaid_convert_items_to_string( $items ) );
1326
+    $form_items = esc_attr(getpaid_convert_items_to_string($items));
1327 1327
     $form_items = "<input type='hidden' name='getpaid-form-items' value='$form_items' />";
1328
-    $form->display( $form_items );
1328
+    $form->display($form_items);
1329 1329
 }
1330 1330
 
1331 1331
 /**
1332 1332
  * Helper function to display an invoice payment form on the frontend.
1333 1333
  */
1334
-function getpaid_display_invoice_payment_form( $invoice_id ) {
1334
+function getpaid_display_invoice_payment_form($invoice_id) {
1335 1335
 
1336
-    $invoice = wpinv_get_invoice( $invoice_id );
1336
+    $invoice = wpinv_get_invoice($invoice_id);
1337 1337
 
1338
-    if ( empty( $invoice ) ) {
1338
+    if (empty($invoice)) {
1339 1339
 		echo aui()->alert(
1340 1340
 			array(
1341 1341
 				'type'    => 'warning',
1342
-				'content' => __( 'Invoice not found', 'invoicing' ),
1342
+				'content' => __('Invoice not found', 'invoicing'),
1343 1343
 			)
1344 1344
         );
1345 1345
         return;
1346 1346
     }
1347 1347
 
1348
-    if ( $invoice->is_paid() ) {
1348
+    if ($invoice->is_paid()) {
1349 1349
 		echo aui()->alert(
1350 1350
 			array(
1351 1351
 				'type'    => 'warning',
1352
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1352
+				'content' => __('Invoice has already been paid', 'invoicing'),
1353 1353
 			)
1354 1354
         );
1355 1355
         return;
1356 1356
     }
1357 1357
 
1358
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1359
-    $form->set_items( $invoice->get_items() );
1358
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1359
+    $form->set_items($invoice->get_items());
1360 1360
 
1361 1361
     $form->display();
1362 1362
 }
@@ -1364,23 +1364,23 @@  discard block
 block discarded – undo
1364 1364
 /**
1365 1365
  * Helper function to convert item string to array.
1366 1366
  */
1367
-function getpaid_convert_items_to_array( $items ) {
1368
-    $items    = array_filter( array_map( 'trim', explode( ',', $items ) ) );
1367
+function getpaid_convert_items_to_array($items) {
1368
+    $items    = array_filter(array_map('trim', explode(',', $items)));
1369 1369
     $prepared = array();
1370 1370
 
1371
-    foreach ( $items as $item ) {
1372
-        $data = array_map( 'trim', explode( '|', $item ) );
1371
+    foreach ($items as $item) {
1372
+        $data = array_map('trim', explode('|', $item));
1373 1373
 
1374
-        if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) {
1374
+        if (empty($data[0]) || !is_numeric($data[0])) {
1375 1375
             continue;
1376 1376
         }
1377 1377
 
1378 1378
         $quantity = 1;
1379
-        if ( isset( $data[1] ) && is_numeric( $data[1] ) ) {
1379
+        if (isset($data[1]) && is_numeric($data[1])) {
1380 1380
             $quantity = (int) $data[1];
1381 1381
         }
1382 1382
 
1383
-        $prepared[ $data[0] ] = $quantity;
1383
+        $prepared[$data[0]] = $quantity;
1384 1384
 
1385 1385
     }
1386 1386
 
@@ -1390,13 +1390,13 @@  discard block
 block discarded – undo
1390 1390
 /**
1391 1391
  * Helper function to convert item array to string.
1392 1392
  */
1393
-function getpaid_convert_items_to_string( $items ) {
1393
+function getpaid_convert_items_to_string($items) {
1394 1394
     $prepared = array();
1395 1395
 
1396
-    foreach ( $items as $item => $quantity ) {
1396
+    foreach ($items as $item => $quantity) {
1397 1397
         $prepared[] = "$item|$quantity";
1398 1398
     }
1399
-    return implode( ',', $prepared );
1399
+    return implode(',', $prepared);
1400 1400
 }
1401 1401
 
1402 1402
 /**
@@ -1404,21 +1404,21 @@  discard block
 block discarded – undo
1404 1404
  * 
1405 1405
  * Provide a label and one of $form, $items or $invoice.
1406 1406
  */
1407
-function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) {
1408
-    $label = sanitize_text_field( $label );
1407
+function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) {
1408
+    $label = sanitize_text_field($label);
1409 1409
 
1410
-    if ( ! empty( $form ) ) {
1411
-        $form  = esc_attr( $form );
1410
+    if (!empty($form)) {
1411
+        $form = esc_attr($form);
1412 1412
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; 
1413 1413
     }
1414 1414
 	
1415
-	if ( ! empty( $items ) ) {
1416
-        $items  = esc_attr( $items );
1415
+	if (!empty($items)) {
1416
+        $items = esc_attr($items);
1417 1417
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; 
1418 1418
     }
1419 1419
     
1420
-    if ( ! empty( $invoice ) ) {
1421
-        $invoice  = esc_attr( $invoice );
1420
+    if (!empty($invoice)) {
1421
+        $invoice = esc_attr($invoice);
1422 1422
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; 
1423 1423
     }
1424 1424
 
@@ -1429,17 +1429,17 @@  discard block
 block discarded – undo
1429 1429
  *
1430 1430
  * @param WPInv_Invoice $invoice
1431 1431
  */
1432
-function getpaid_the_invoice_description( $invoice ) {
1432
+function getpaid_the_invoice_description($invoice) {
1433 1433
     $description = $invoice->get_description();
1434 1434
 
1435
-    if ( empty( $description ) ) {
1435
+    if (empty($description)) {
1436 1436
         return;
1437 1437
     }
1438 1438
 
1439
-    $description = wp_kses_post( $description );
1439
+    $description = wp_kses_post($description);
1440 1440
     echo "<small class='getpaid-invoice-description text-dark p-2 form-text'><em>$description</em></small>";
1441 1441
 }
1442
-add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 );
1442
+add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100);
1443 1443
 
1444 1444
 /**
1445 1445
  * Render element on a form.
@@ -1447,60 +1447,60 @@  discard block
 block discarded – undo
1447 1447
  * @param array $element
1448 1448
  * @param GetPaid_Payment_Form $form
1449 1449
  */
1450
-function getpaid_payment_form_element( $element, $form ) {
1450
+function getpaid_payment_form_element($element, $form) {
1451 1451
 
1452 1452
     // Set up the args.
1453
-    $element_type    = trim( $element['type'] );
1453
+    $element_type    = trim($element['type']);
1454 1454
     $element['form'] = $form;
1455
-    extract( $element );
1455
+    extract($element);
1456 1456
 
1457 1457
     // Try to locate the appropriate template.
1458
-    $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" );
1458
+    $located = wpinv_locate_template("payment-forms/elements/$element_type.php");
1459 1459
     
1460 1460
     // Abort if this is not our element.
1461
-    if ( empty( $located ) || ! file_exists( $located ) ) {
1461
+    if (empty($located) || !file_exists($located)) {
1462 1462
         return;
1463 1463
     }
1464 1464
 
1465 1465
     // Generate the class and id of the element.
1466
-    $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) );
1467
-    $id            = isset( $id ) ? $id : uniqid( 'gp' );
1466
+    $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type));
1467
+    $id            = isset($id) ? $id : uniqid('gp');
1468 1468
 
1469 1469
     // Echo the opening wrapper.
1470 1470
     echo "<div class='getpaid-payment-form-element $wrapper_class'>";
1471 1471
 
1472 1472
     // Fires before displaying a given element type's content.
1473
-    do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form );
1473
+    do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form);
1474 1474
 
1475 1475
     // Include the template for the element.
1476 1476
     include $located;
1477 1477
 
1478 1478
     // Fires after displaying a given element type's content.
1479
-    do_action( "getpaid_payment_form_{$element_type}_element", $element, $form );
1479
+    do_action("getpaid_payment_form_{$element_type}_element", $element, $form);
1480 1480
 
1481 1481
     // Echo the closing wrapper.
1482 1482
     echo '</div>';
1483 1483
 }
1484
-add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 );
1484
+add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2);
1485 1485
 
1486 1486
 /**
1487 1487
  * Render an element's edit page.
1488 1488
  *
1489 1489
  * @param WP_Post $post
1490 1490
  */
1491
-function getpaid_payment_form_edit_element_template( $post ) {
1491
+function getpaid_payment_form_edit_element_template($post) {
1492 1492
 
1493 1493
     // Retrieve all elements.
1494
-    $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' );
1494
+    $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type');
1495 1495
 
1496
-    foreach ( $all_elements as $element ) {
1496
+    foreach ($all_elements as $element) {
1497 1497
 
1498 1498
         // Try to locate the appropriate template.
1499
-        $element = sanitize_key( $element );
1500
-        $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" );
1499
+        $element = sanitize_key($element);
1500
+        $located = wpinv_locate_template("payment-forms-admin/edit/$element.php");
1501 1501
 
1502 1502
         // Continue if this is not our element.
1503
-        if ( empty( $located ) || ! file_exists( $located ) ) {
1503
+        if (empty($located) || !file_exists($located)) {
1504 1504
             continue;
1505 1505
         }
1506 1506
 
@@ -1511,7 +1511,7 @@  discard block
 block discarded – undo
1511 1511
     }
1512 1512
 
1513 1513
 }
1514
-add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' );
1514
+add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template');
1515 1515
 
1516 1516
 /**
1517 1517
  * Render an element's preview.
@@ -1520,16 +1520,16 @@  discard block
 block discarded – undo
1520 1520
 function getpaid_payment_form_render_element_preview_template() {
1521 1521
 
1522 1522
     // Retrieve all elements.
1523
-    $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' );
1523
+    $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type');
1524 1524
 
1525
-    foreach ( $all_elements as $element ) {
1525
+    foreach ($all_elements as $element) {
1526 1526
 
1527 1527
         // Try to locate the appropriate template.
1528
-        $element = sanitize_key( $element );
1529
-        $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" );
1528
+        $element = sanitize_key($element);
1529
+        $located = wpinv_locate_template("payment-forms-admin/previews/$element.php");
1530 1530
 
1531 1531
         // Continue if this is not our element.
1532
-        if ( empty( $located ) || ! file_exists( $located ) ) {
1532
+        if (empty($located) || !file_exists($located)) {
1533 1533
             continue;
1534 1534
         }
1535 1535
 
@@ -1540,7 +1540,7 @@  discard block
 block discarded – undo
1540 1540
     }
1541 1541
 
1542 1542
 }
1543
-add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' );
1543
+add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template');
1544 1544
 
1545 1545
 /**
1546 1546
  * Shows a list of gateways that support recurring payments.
@@ -1548,17 +1548,17 @@  discard block
 block discarded – undo
1548 1548
 function wpinv_get_recurring_gateways_text() {
1549 1549
     $gateways = array();
1550 1550
 
1551
-    foreach ( wpinv_get_payment_gateways() as $key => $gateway ) {
1552
-        if ( wpinv_gateway_support_subscription( $key ) ) {
1553
-            $gateways[] = sanitize_text_field( $gateway['admin_label'] );
1551
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
1552
+        if (wpinv_gateway_support_subscription($key)) {
1553
+            $gateways[] = sanitize_text_field($gateway['admin_label']);
1554 1554
         }
1555 1555
     }
1556 1556
 
1557
-    if ( empty( $gateways ) ) {
1558
-        return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>";
1557
+    if (empty($gateways)) {
1558
+        return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>";
1559 1559
     }
1560 1560
 
1561
-    return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>";
1561
+    return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>";
1562 1562
 
1563 1563
 }
1564 1564
 
@@ -1568,7 +1568,7 @@  discard block
 block discarded – undo
1568 1568
  * @return GetPaid_Template
1569 1569
  */
1570 1570
 function getpaid_template() {
1571
-    return getpaid()->get( 'template' );
1571
+    return getpaid()->get('template');
1572 1572
 }
1573 1573
 
1574 1574
 /**
@@ -1577,23 +1577,23 @@  discard block
 block discarded – undo
1577 1577
  * @param array args
1578 1578
  * @return string
1579 1579
  */
1580
-function getpaid_paginate_links( $args ) {
1580
+function getpaid_paginate_links($args) {
1581 1581
 
1582 1582
     $args['type']     = 'array';
1583 1583
     $args['mid_size'] = 1;
1584
-    $pages        = paginate_links( $args );
1584
+    $pages = paginate_links($args);
1585 1585
 
1586
-    if ( ! is_array( $pages ) ) {
1586
+    if (!is_array($pages)) {
1587 1587
         return '';
1588 1588
     }
1589 1589
 
1590 1590
     $_pages = array();
1591
-    foreach ( $pages as $page ) {
1592
-        $_pages[] = str_replace( 'page-numbers', 'page-link text-decoration-none', $page );
1591
+    foreach ($pages as $page) {
1592
+        $_pages[] = str_replace('page-numbers', 'page-link text-decoration-none', $page);
1593 1593
     }
1594 1594
 
1595 1595
     $links  = "<nav>\n\t<ul class='pagination justify-content-end m-0'>\n\t\t<li class='page-item'>";
1596
-    $links .= join( "</li>\n\t\t<li class='page-item'>", $_pages );
1596
+    $links .= join("</li>\n\t\t<li class='page-item'>", $_pages);
1597 1597
     $links .= "</li>\n\t</ul>\n</nav>\n";
1598 1598
 
1599 1599
     return $links;
@@ -1606,21 +1606,21 @@  discard block
 block discarded – undo
1606 1606
  * @param string state
1607 1607
  * @return string
1608 1608
  */
1609
-function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12' ) {
1609
+function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12') {
1610 1610
 
1611
-    $states = wpinv_get_country_states( $country );
1612
-    $uniqid = uniqid( '_' );
1611
+    $states = wpinv_get_country_states($country);
1612
+    $uniqid = uniqid('_');
1613 1613
 
1614
-    if ( ! empty( $states ) ) {
1614
+    if (!empty($states)) {
1615 1615
 
1616
-        return aui()->select( array(
1616
+        return aui()->select(array(
1617 1617
             'options'          => $states,
1618 1618
             'name'             => 'wpinv_state',
1619 1619
             'id'               => 'wpinv_state' . $uniqid,
1620
-            'value'            => sanitize_text_field( $state ),
1620
+            'value'            => sanitize_text_field($state),
1621 1621
             'placeholder'      => $placeholder,
1622 1622
             'required'         => $required,
1623
-            'label'            => wp_kses_post( $label ),
1623
+            'label'            => wp_kses_post($label),
1624 1624
             'label_type'       => 'vertical',
1625 1625
             'help_text'        => $help_text,
1626 1626
             'class'            => 'getpaid-address-field wpinv_state',
@@ -1636,10 +1636,10 @@  discard block
 block discarded – undo
1636 1636
             'id'          => 'wpinv_state' . $uniqid,
1637 1637
             'placeholder' => $placeholder,
1638 1638
             'required'    => $required,
1639
-            'label'       => wp_kses_post( $label ),
1639
+            'label'       => wp_kses_post($label),
1640 1640
             'label_type'  => 'vertical',
1641 1641
             'help_text'   => $help_text,
1642
-            'value'       => sanitize_text_field( $state ),
1642
+            'value'       => sanitize_text_field($state),
1643 1643
             'class'       => 'getpaid-address-field wpinv_state',
1644 1644
             'wrap_class'  => "$wrapper_class getpaid-address-field-wrapper__state",
1645 1645
             'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state',
@@ -1654,16 +1654,16 @@  discard block
 block discarded – undo
1654 1654
  * @param array $element
1655 1655
  * @return string
1656 1656
  */
1657
-function getpaid_get_form_element_grid_class( $element ) {
1657
+function getpaid_get_form_element_grid_class($element) {
1658 1658
 
1659 1659
     $class = "col-12";
1660
-    $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width'];
1660
+    $width = empty($element['grid_width']) ? 'full' : $element['grid_width'];
1661 1661
 
1662
-    if ( $width == 'half' ) {
1662
+    if ($width == 'half') {
1663 1663
         $class = "col-12 col-md-6";
1664 1664
     }
1665 1665
 
1666
-    if ( $width == 'third' ) {
1666
+    if ($width == 'third') {
1667 1667
         $class = "col-12 col-md-4";
1668 1668
     }
1669 1669
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -179,8 +179,9 @@  discard block
 block discarded – undo
179 179
 
180 180
 	// Setup possible parts
181 181
 	$templates = array();
182
-	if ( isset( $name ) )
183
-		$templates[] = $slug . '-' . $name . '.php';
182
+	if ( isset( $name ) ) {
183
+			$templates[] = $slug . '-' . $name . '.php';
184
+	}
184 185
 	$templates[] = $slug . '.php';
185 186
 
186 187
 	// Allow template parts to be filtered
@@ -198,8 +199,9 @@  discard block
 block discarded – undo
198 199
 	foreach ( (array)$template_names as $template_name ) {
199 200
 
200 201
 		// Continue if template is empty
201
-		if ( empty( $template_name ) )
202
-			continue;
202
+		if ( empty( $template_name ) ) {
203
+					continue;
204
+		}
203 205
 
204 206
 		// Trim off any slashes from the template name
205 207
 		$template_name = ltrim( $template_name, '/' );
@@ -218,8 +220,9 @@  discard block
 block discarded – undo
218 220
 		}
219 221
 	}
220 222
 
221
-	if ( ( true == $load ) && ! empty( $located ) )
222
-		load_template( $located, $require_once );
223
+	if ( ( true == $load ) && ! empty( $located ) ) {
224
+			load_template( $located, $require_once );
225
+	}
223 226
 
224 227
 	return $located;
225 228
 }
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 2 patches
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -14,70 +14,70 @@  discard block
 block discarded – undo
14 14
 class WPInv_Ajax {
15 15
 
16 16
     /**
17
-	 * Hook in ajax handlers.
18
-	 */
19
-	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
-		self::add_ajax_events();
17
+     * Hook in ajax handlers.
18
+     */
19
+    public static function init() {
20
+        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
+        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
+        self::add_ajax_events();
23 23
     }
24 24
 
25 25
     /**
26
-	 * Set GetPaid AJAX constant and headers.
27
-	 */
28
-	public static function define_ajax() {
29
-
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
-			}
36
-			$GLOBALS['wpdb']->hide_errors();
37
-		}
26
+     * Set GetPaid AJAX constant and headers.
27
+     */
28
+    public static function define_ajax() {
29
+
30
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
+            getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
+            getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
+            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
+                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
+            }
36
+            $GLOBALS['wpdb']->hide_errors();
37
+        }
38 38
 
39 39
     }
40 40
     
41 41
     /**
42
-	 * Send headers for GetPaid Ajax Requests.
43
-	 *
44
-	 * @since 1.0.18
45
-	 */
46
-	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
48
-			send_origin_headers();
49
-			send_nosniff_header();
50
-			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
54
-		}
42
+     * Send headers for GetPaid Ajax Requests.
43
+     *
44
+     * @since 1.0.18
45
+     */
46
+    private static function wpinv_ajax_headers() {
47
+        if ( ! headers_sent() ) {
48
+            send_origin_headers();
49
+            send_nosniff_header();
50
+            nocache_headers();
51
+            header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
+            header( 'X-Robots-Tag: noindex' );
53
+            status_header( 200 );
54
+        }
55 55
     }
56 56
     
57 57
     /**
58
-	 * Check for GetPaid Ajax request and fire action.
59
-	 */
60
-	public static function do_wpinv_ajax() {
61
-		global $wp_query;
58
+     * Check for GetPaid Ajax request and fire action.
59
+     */
60
+    public static function do_wpinv_ajax() {
61
+        global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
-		}
63
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
+            $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
+        }
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+        $action = $wp_query->get( 'wpinv-ajax' );
68 68
 
69
-		if ( $action ) {
70
-			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
73
-			wp_die();
74
-		}
69
+        if ( $action ) {
70
+            self::wpinv_ajax_headers();
71
+            $action = sanitize_text_field( $action );
72
+            do_action( 'wpinv_ajax_' . $action );
73
+            wp_die();
74
+        }
75 75
 
76 76
     }
77 77
 
78 78
     /**
79
-	 * Hook in ajax methods.
80
-	 */
79
+     * Hook in ajax methods.
80
+     */
81 81
     public static function add_ajax_events() {
82 82
 
83 83
         // array( 'event' => is_frontend )
@@ -256,24 +256,24 @@  discard block
 block discarded – undo
256 256
         check_ajax_referer( 'getpaid_form_nonce' );
257 257
 
258 258
         // Is the request set up correctly?
259
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
260
-			echo aui()->alert(
261
-				array(
262
-					'type'    => 'warning',
263
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
264
-				)
259
+        if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
260
+            echo aui()->alert(
261
+                array(
262
+                    'type'    => 'warning',
263
+                    'content' => __( 'No payment form or item provided', 'invoicing' ),
264
+                )
265 265
             );
266 266
             exit;
267 267
         }
268 268
 
269 269
         // Payment form or button?
270
-		if ( ! empty( $_GET['form'] ) ) {
270
+        if ( ! empty( $_GET['form'] ) ) {
271 271
             getpaid_display_payment_form( $_GET['form'] );
272
-		} else if( ! empty( $_GET['invoice'] ) ) {
273
-		    getpaid_display_invoice_payment_form( $_GET['invoice'] );
272
+        } else if( ! empty( $_GET['invoice'] ) ) {
273
+            getpaid_display_invoice_payment_form( $_GET['invoice'] );
274 274
         } else {
275
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
276
-		    getpaid_display_item_payment_form( $items );
275
+            $items = getpaid_convert_items_to_array( $_GET['item'] );
276
+            getpaid_display_item_payment_form( $items );
277 277
         }
278 278
 
279 279
         exit;
Please login to merge, or discard this patch.
Spacing   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
     
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -101,36 +101,36 @@  discard block
 block discarded – undo
101 101
             'payment_form_refresh_prices' => true,
102 102
         );
103 103
 
104
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
105
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
106
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
104
+        foreach ($ajax_events as $ajax_event => $nopriv) {
105
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
106
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
107 107
 
108
-            if ( $nopriv ) {
109
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
110
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
108
+            if ($nopriv) {
109
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
110
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
112 112
             }
113 113
         }
114 114
     }
115 115
     
116 116
     public static function add_note() {
117
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
117
+        check_ajax_referer('add-invoice-note', '_nonce');
118 118
 
119
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
119
+        if (!wpinv_current_user_can_manage_invoicing()) {
120 120
             die(-1);
121 121
         }
122 122
 
123
-        $post_id   = absint( $_POST['post_id'] );
124
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
125
-        $note_type = sanitize_text_field( $_POST['note_type'] );
123
+        $post_id   = absint($_POST['post_id']);
124
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
125
+        $note_type = sanitize_text_field($_POST['note_type']);
126 126
 
127 127
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
128 128
 
129
-        if ( $post_id > 0 ) {
130
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
129
+        if ($post_id > 0) {
130
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
131 131
 
132
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
133
-                wpinv_get_invoice_note_line_item( $note_id );
132
+            if ($note_id > 0 && !is_wp_error($note_id)) {
133
+                wpinv_get_invoice_note_line_item($note_id);
134 134
             }
135 135
         }
136 136
 
@@ -138,16 +138,16 @@  discard block
 block discarded – undo
138 138
     }
139 139
 
140 140
     public static function delete_note() {
141
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
141
+        check_ajax_referer('delete-invoice-note', '_nonce');
142 142
 
143
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
143
+        if (!wpinv_current_user_can_manage_invoicing()) {
144 144
             die(-1);
145 145
         }
146 146
 
147
-        $note_id = (int)$_POST['note_id'];
147
+        $note_id = (int) $_POST['note_id'];
148 148
 
149
-        if ( $note_id > 0 ) {
150
-            wp_delete_comment( $note_id, true );
149
+        if ($note_id > 0) {
150
+            wp_delete_comment($note_id, true);
151 151
         }
152 152
 
153 153
         die();
@@ -165,34 +165,34 @@  discard block
 block discarded – undo
165 165
     public static function get_billing_details() {
166 166
 
167 167
         // Verify nonce.
168
-        check_ajax_referer( 'wpinv-nonce' );
168
+        check_ajax_referer('wpinv-nonce');
169 169
 
170 170
         // Can the user manage the plugin?
171
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
171
+        if (!wpinv_current_user_can_manage_invoicing()) {
172 172
             die(-1);
173 173
         }
174 174
 
175 175
         // Do we have a user id?
176 176
         $user_id = $_GET['user_id'];
177 177
 
178
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
178
+        if (empty($user_id) || !is_numeric($user_id)) {
179 179
             die(-1);
180 180
         }
181 181
 
182 182
         // Fetch the billing details.
183
-        $billing_details    = wpinv_get_user_address( $user_id );
184
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
183
+        $billing_details    = wpinv_get_user_address($user_id);
184
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
185 185
 
186 186
         // unset the user id and email.
187
-        $to_ignore = array( 'user_id', 'email' );
187
+        $to_ignore = array('user_id', 'email');
188 188
 
189
-        foreach ( $to_ignore as $key ) {
190
-            if ( isset( $billing_details[ $key ] ) ) {
191
-                unset( $billing_details[ $key ] );
189
+        foreach ($to_ignore as $key) {
190
+            if (isset($billing_details[$key])) {
191
+                unset($billing_details[$key]);
192 192
             }
193 193
         }
194 194
 
195
-        wp_send_json_success( $billing_details );
195
+        wp_send_json_success($billing_details);
196 196
 
197 197
     }
198 198
 
@@ -202,47 +202,47 @@  discard block
 block discarded – undo
202 202
     public static function check_new_user_email() {
203 203
 
204 204
         // Verify nonce.
205
-        check_ajax_referer( 'wpinv-nonce' );
205
+        check_ajax_referer('wpinv-nonce');
206 206
 
207 207
         // Can the user manage the plugin?
208
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
208
+        if (!wpinv_current_user_can_manage_invoicing()) {
209 209
             die(-1);
210 210
         }
211 211
 
212 212
         // We need an email address.
213
-        if ( empty( $_GET['email'] ) ) {
214
-            _e( "Provide the new user's email address", 'invoicing' );
213
+        if (empty($_GET['email'])) {
214
+            _e("Provide the new user's email address", 'invoicing');
215 215
             exit;
216 216
         }
217 217
 
218 218
         // Ensure the email is valid.
219
-        $email = sanitize_text_field( $_GET['email'] );
220
-        if ( ! is_email( $email ) ) {
221
-            _e( 'Invalid email address', 'invoicing' );
219
+        $email = sanitize_text_field($_GET['email']);
220
+        if (!is_email($email)) {
221
+            _e('Invalid email address', 'invoicing');
222 222
             exit;
223 223
         }
224 224
 
225 225
         // And it does not exist.
226
-        if ( email_exists( $email ) ) {
227
-            _e( 'A user with this email address already exists', 'invoicing' );
226
+        if (email_exists($email)) {
227
+            _e('A user with this email address already exists', 'invoicing');
228 228
             exit;
229 229
         }
230 230
 
231
-        wp_send_json_success( true );
231
+        wp_send_json_success(true);
232 232
     }
233 233
     
234 234
     public static function run_tool() {
235
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
236
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
235
+        check_ajax_referer('wpinv-nonce', '_nonce');
236
+        if (!wpinv_current_user_can_manage_invoicing()) {
237 237
             die(-1);
238 238
         }
239 239
         
240
-        $tool = sanitize_text_field( $_POST['tool'] );
240
+        $tool = sanitize_text_field($_POST['tool']);
241 241
         
242
-        do_action( 'wpinv_run_tool' );
242
+        do_action('wpinv_run_tool');
243 243
         
244
-        if ( !empty( $tool ) ) {
245
-            do_action( 'wpinv_tool_' . $tool );
244
+        if (!empty($tool)) {
245
+            do_action('wpinv_tool_' . $tool);
246 246
         }
247 247
     }
248 248
 
@@ -252,27 +252,27 @@  discard block
 block discarded – undo
252 252
     public static function get_payment_form() {
253 253
 
254 254
         // Check nonce.
255
-        check_ajax_referer( 'getpaid_form_nonce' );
255
+        check_ajax_referer('getpaid_form_nonce');
256 256
 
257 257
         // Is the request set up correctly?
258
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
258
+		if (empty($_GET['form']) && empty($_GET['item'])) {
259 259
 			echo aui()->alert(
260 260
 				array(
261 261
 					'type'    => 'warning',
262
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
262
+					'content' => __('No payment form or item provided', 'invoicing'),
263 263
 				)
264 264
             );
265 265
             exit;
266 266
         }
267 267
 
268 268
         // Payment form or button?
269
-		if ( ! empty( $_GET['form'] ) ) {
270
-            getpaid_display_payment_form( $_GET['form'] );
271
-		} else if( ! empty( $_GET['invoice'] ) ) {
272
-		    getpaid_display_invoice_payment_form( $_GET['invoice'] );
269
+		if (!empty($_GET['form'])) {
270
+            getpaid_display_payment_form($_GET['form']);
271
+		} else if (!empty($_GET['invoice'])) {
272
+		    getpaid_display_invoice_payment_form($_GET['invoice']);
273 273
         } else {
274
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
275
-		    getpaid_display_item_payment_form( $items );
274
+			$items = getpaid_convert_items_to_array($_GET['item']);
275
+		    getpaid_display_item_payment_form($items);
276 276
         }
277 277
 
278 278
         exit;
@@ -287,17 +287,17 @@  discard block
 block discarded – undo
287 287
     public static function payment_form() {
288 288
 
289 289
         // Check nonce.
290
-        check_ajax_referer( 'getpaid_form_nonce' );
290
+        check_ajax_referer('getpaid_form_nonce');
291 291
 
292 292
         // ... form fields...
293
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
294
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
293
+        if (empty($_POST['getpaid_payment_form_submission'])) {
294
+            _e('Error: Reload the page and try again.', 'invoicing');
295 295
             exit;
296 296
         }
297 297
 
298 298
         // Process the payment form.
299
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
300
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
299
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
300
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
301 301
         $checkout->process_checkout();
302 302
 
303 303
         exit;
@@ -310,54 +310,54 @@  discard block
 block discarded – undo
310 310
      */
311 311
     public static function get_payment_form_states_field() {
312 312
 
313
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
313
+        if (empty($_GET['country']) || empty($_GET['form'])) {
314 314
             exit;
315 315
         }
316 316
 
317
-        $elements = getpaid_get_payment_form_elements( $_GET['form'] );
317
+        $elements = getpaid_get_payment_form_elements($_GET['form']);
318 318
 
319
-        if ( empty( $elements ) ) {
319
+        if (empty($elements)) {
320 320
             exit;
321 321
         }
322 322
 
323 323
         $address_fields = array();
324
-        foreach ( $elements as $element ) {
325
-            if ( 'address' === $element['type'] ) {
324
+        foreach ($elements as $element) {
325
+            if ('address' === $element['type']) {
326 326
                 $address_fields = $element;
327 327
                 break;
328 328
             }
329 329
         }
330 330
 
331
-        if ( empty( $address_fields ) ) {
331
+        if (empty($address_fields)) {
332 332
             exit;
333 333
         }
334 334
 
335
-        foreach ( $address_fields['fields'] as $address_field ) {
335
+        foreach ($address_fields['fields'] as $address_field) {
336 336
 
337
-            if ( 'wpinv_state' == $address_field['name'] ) {
337
+            if ('wpinv_state' == $address_field['name']) {
338 338
 
339
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
340
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
341
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
342
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
343
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
344
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
339
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
340
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
341
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
342
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
343
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
344
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
345 345
 
346
-                if ( ! empty( $address_field['required'] ) ) {
346
+                if (!empty($address_field['required'])) {
347 347
                     $label .= "<span class='text-danger'> *</span>";
348 348
                 }
349 349
 
350
-                $html = getpaid_get_states_select_markup (
351
-                    sanitize_text_field( $_GET['country'] ),
350
+                $html = getpaid_get_states_select_markup(
351
+                    sanitize_text_field($_GET['country']),
352 352
                     $value,
353 353
                     $placeholder,
354 354
                     $label,
355 355
                     $description,
356
-                    ! empty( $address_field['required'] ),
356
+                    !empty($address_field['required']),
357 357
                     $wrap_class
358 358
                 );
359 359
 
360
-                wp_send_json_success( $html );
360
+                wp_send_json_success($html);
361 361
                 exit;
362 362
 
363 363
             }
@@ -373,56 +373,56 @@  discard block
 block discarded – undo
373 373
     public static function recalculate_invoice_totals() {
374 374
 
375 375
         // Verify nonce.
376
-        check_ajax_referer( 'wpinv-nonce' );
376
+        check_ajax_referer('wpinv-nonce');
377 377
 
378
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
378
+        if (!wpinv_current_user_can_manage_invoicing()) {
379 379
             exit;
380 380
         }
381 381
 
382 382
         // We need an invoice.
383
-        if ( empty( $_POST['post_id'] ) ) {
383
+        if (empty($_POST['post_id'])) {
384 384
             exit;
385 385
         }
386 386
 
387 387
         // Fetch the invoice.
388
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
388
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
389 389
 
390 390
         // Ensure it exists.
391
-        if ( ! $invoice->get_id() ) {
391
+        if (!$invoice->get_id()) {
392 392
             exit;
393 393
         }
394 394
 
395 395
         // Maybe set the country, state, currency.
396
-        foreach ( array( 'country', 'state', 'currency' ) as $key ) {
397
-            if ( isset( $_POST[ $key ] ) ) {
396
+        foreach (array('country', 'state', 'currency') as $key) {
397
+            if (isset($_POST[$key])) {
398 398
                 $method = "set_$key";
399
-                $invoice->$method( $_POST[ $key ] );
399
+                $invoice->$method($_POST[$key]);
400 400
             }
401 401
         }
402 402
 
403 403
         // Maybe disable taxes.
404
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
404
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
405 405
 
406 406
         // Recalculate totals.
407 407
         $invoice->recalculate_total();
408 408
 
409
-        $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() );
409
+        $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency());
410 410
 
411
-        if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
412
-            $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() );
413
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
411
+        if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
412
+            $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency());
413
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
414 414
         }
415 415
 
416 416
         $totals = array(
417
-            'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ),
418
-            'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ),
419
-            'tax'      => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ),
417
+            'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()),
418
+            'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()),
419
+            'tax'      => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()),
420 420
             'total'    => $total,
421 421
         );
422 422
 
423
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
423
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
424 424
 
425
-        wp_send_json_success( compact( 'totals' ) );
425
+        wp_send_json_success(compact('totals'));
426 426
     }
427 427
 
428 428
     /**
@@ -431,33 +431,33 @@  discard block
 block discarded – undo
431 431
     public static function get_invoice_items() {
432 432
 
433 433
         // Verify nonce.
434
-        check_ajax_referer( 'wpinv-nonce' );
434
+        check_ajax_referer('wpinv-nonce');
435 435
 
436
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
436
+        if (!wpinv_current_user_can_manage_invoicing()) {
437 437
             exit;
438 438
         }
439 439
 
440 440
         // We need an invoice and items.
441
-        if ( empty( $_POST['post_id'] ) ) {
441
+        if (empty($_POST['post_id'])) {
442 442
             exit;
443 443
         }
444 444
 
445 445
         // Fetch the invoice.
446
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
446
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
447 447
 
448 448
         // Ensure it exists.
449
-        if ( ! $invoice->get_id() ) {
449
+        if (!$invoice->get_id()) {
450 450
             exit;
451 451
         }
452 452
 
453 453
         // Return an array of invoice items.
454 454
         $items = array();
455 455
 
456
-        foreach ( $invoice->get_items() as $item_id => $item ) {
457
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
456
+        foreach ($invoice->get_items() as $item_id => $item) {
457
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
458 458
         }
459 459
 
460
-        wp_send_json_success( compact( 'items' ) );
460
+        wp_send_json_success(compact('items'));
461 461
     }
462 462
 
463 463
     /**
@@ -466,50 +466,50 @@  discard block
 block discarded – undo
466 466
     public static function edit_invoice_item() {
467 467
 
468 468
         // Verify nonce.
469
-        check_ajax_referer( 'wpinv-nonce' );
469
+        check_ajax_referer('wpinv-nonce');
470 470
 
471
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
471
+        if (!wpinv_current_user_can_manage_invoicing()) {
472 472
             exit;
473 473
         }
474 474
 
475 475
         // We need an invoice and item details.
476
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
476
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
477 477
             exit;
478 478
         }
479 479
 
480 480
         // Fetch the invoice.
481
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
481
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
482 482
 
483 483
         // Ensure it exists and its not been paid for.
484
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
484
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
485 485
             exit;
486 486
         }
487 487
 
488 488
         // Format the data.
489
-        $data = wp_list_pluck( $_POST['data'], 'value', 'field' );
489
+        $data = wp_list_pluck($_POST['data'], 'value', 'field');
490 490
 
491 491
         // Ensure that we have an item id.
492
-        if ( empty( $data['id'] ) ) {
492
+        if (empty($data['id'])) {
493 493
             exit;
494 494
         }
495 495
 
496 496
         // Abort if the invoice does not have the specified item.
497
-        $item = $invoice->get_item( (int) $data['id'] );
497
+        $item = $invoice->get_item((int) $data['id']);
498 498
 
499
-        if ( empty( $item ) ) {
499
+        if (empty($item)) {
500 500
             exit;
501 501
         }
502 502
 
503 503
         // Update the item.
504
-        $item->set_price( $data['price'] );
505
-        $item->set_name( $data['name'] );
506
-        $item->set_description( $data['description'] );
507
-        $item->set_quantity( $data['quantity'] );
504
+        $item->set_price($data['price']);
505
+        $item->set_name($data['name']);
506
+        $item->set_description($data['description']);
507
+        $item->set_quantity($data['quantity']);
508 508
 
509 509
         // Add it to the invoice.
510
-        $error = $invoice->add_item( $item );
510
+        $error = $invoice->add_item($item);
511 511
         $alert = false;
512
-        if ( is_wp_error( $error ) ) {
512
+        if (is_wp_error($error)) {
513 513
             $alert = $error->get_error_message();
514 514
         }
515 515
 
@@ -522,11 +522,11 @@  discard block
 block discarded – undo
522 522
         // Return an array of invoice items.
523 523
         $items = array();
524 524
 
525
-        foreach ( $invoice->get_items() as $item_id => $item ) {
526
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
525
+        foreach ($invoice->get_items() as $item_id => $item) {
526
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
527 527
         }
528 528
 
529
-        wp_send_json_success( compact( 'items', 'alert' ) );
529
+        wp_send_json_success(compact('items', 'alert'));
530 530
     }
531 531
 
532 532
     /**
@@ -535,33 +535,33 @@  discard block
 block discarded – undo
535 535
     public static function remove_invoice_item() {
536 536
 
537 537
         // Verify nonce.
538
-        check_ajax_referer( 'wpinv-nonce' );
538
+        check_ajax_referer('wpinv-nonce');
539 539
 
540
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
540
+        if (!wpinv_current_user_can_manage_invoicing()) {
541 541
             exit;
542 542
         }
543 543
 
544 544
         // We need an invoice and an item.
545
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
545
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
546 546
             exit;
547 547
         }
548 548
 
549 549
         // Fetch the invoice.
550
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
550
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
551 551
 
552 552
         // Ensure it exists and its not been paid for.
553
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
553
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
554 554
             exit;
555 555
         }
556 556
 
557 557
         // Abort if the invoice does not have the specified item.
558
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
558
+        $item = $invoice->get_item((int) $_POST['item_id']);
559 559
 
560
-        if ( empty( $item ) ) {
560
+        if (empty($item)) {
561 561
             exit;
562 562
         }
563 563
 
564
-        $invoice->remove_item( (int) $_POST['item_id'] );
564
+        $invoice->remove_item((int) $_POST['item_id']);
565 565
 
566 566
         // Update totals.
567 567
         $invoice->recalculate_total();
@@ -572,11 +572,11 @@  discard block
 block discarded – undo
572 572
         // Return an array of invoice items.
573 573
         $items = array();
574 574
 
575
-        foreach ( $invoice->get_items() as $item_id => $item ) {
576
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
575
+        foreach ($invoice->get_items() as $item_id => $item) {
576
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
577 577
         }
578 578
 
579
-        wp_send_json_success( compact( 'items' ) );
579
+        wp_send_json_success(compact('items'));
580 580
     }
581 581
 
582 582
     /**
@@ -585,39 +585,39 @@  discard block
 block discarded – undo
585 585
     public static function add_invoice_items() {
586 586
 
587 587
         // Verify nonce.
588
-        check_ajax_referer( 'wpinv-nonce' );
588
+        check_ajax_referer('wpinv-nonce');
589 589
 
590
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
590
+        if (!wpinv_current_user_can_manage_invoicing()) {
591 591
             exit;
592 592
         }
593 593
 
594 594
         // We need an invoice and items.
595
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
595
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
596 596
             exit;
597 597
         }
598 598
 
599 599
         // Fetch the invoice.
600
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
600
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
601 601
         $alert   = false;
602 602
 
603 603
         // Ensure it exists and its not been paid for.
604
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
604
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
605 605
             exit;
606 606
         }
607 607
 
608 608
         // Add the items.
609
-        foreach ( $_POST['items'] as $data ) {
609
+        foreach ($_POST['items'] as $data) {
610 610
 
611
-            $item = new GetPaid_Form_Item( $data[ 'id' ] );
611
+            $item = new GetPaid_Form_Item($data['id']);
612 612
 
613
-            if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) {
614
-                $item->set_quantity( $data[ 'qty' ] );
613
+            if (is_numeric($data['qty']) && (int) $data['qty'] > 0) {
614
+                $item->set_quantity($data['qty']);
615 615
             }
616 616
 
617
-            if ( $item->get_id() > 0 ) {
618
-                $error = $invoice->add_item( $item );
617
+            if ($item->get_id() > 0) {
618
+                $error = $invoice->add_item($item);
619 619
 
620
-                if ( is_wp_error( $error ) ) {
620
+                if (is_wp_error($error)) {
621 621
                     $alert = $error->get_error_message();
622 622
                 }
623 623
 
@@ -632,11 +632,11 @@  discard block
 block discarded – undo
632 632
         // Return an array of invoice items.
633 633
         $items = array();
634 634
 
635
-        foreach ( $invoice->get_items() as $item_id => $item ) {
636
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
635
+        foreach ($invoice->get_items() as $item_id => $item) {
636
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
637 637
         }
638 638
 
639
-        wp_send_json_success( compact( 'items', 'alert' ) );
639
+        wp_send_json_success(compact('items', 'alert'));
640 640
     }
641 641
 
642 642
     /**
@@ -645,15 +645,15 @@  discard block
 block discarded – undo
645 645
     public static function get_invoicing_items() {
646 646
 
647 647
         // Verify nonce.
648
-        check_ajax_referer( 'wpinv-nonce' );
648
+        check_ajax_referer('wpinv-nonce');
649 649
 
650
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
650
+        if (!wpinv_current_user_can_manage_invoicing()) {
651 651
             exit;
652 652
         }
653 653
 
654 654
         // We need a search term.
655
-        if ( empty( $_GET['search'] ) ) {
656
-            wp_send_json_success( array() );
655
+        if (empty($_GET['search'])) {
656
+            wp_send_json_success(array());
657 657
         }
658 658
 
659 659
         // Retrieve items.
@@ -662,8 +662,8 @@  discard block
 block discarded – undo
662 662
             'orderby'        => 'title',
663 663
             'order'          => 'ASC',
664 664
             'posts_per_page' => -1,
665
-            'post_status'    => array( 'publish' ),
666
-            's'              => trim( $_GET['search'] ),
665
+            'post_status'    => array('publish'),
666
+            's'              => trim($_GET['search']),
667 667
             'meta_query'     => array(
668 668
                 array(
669 669
                     'key'       => '_wpinv_type',
@@ -673,22 +673,22 @@  discard block
 block discarded – undo
673 673
             )
674 674
         );
675 675
 
676
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
676
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
677 677
         $data  = array();
678 678
 
679 679
 
680
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) );
680
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id']));
681 681
 
682
-        foreach ( $items as $item ) {
683
-            $item      = new GetPaid_Form_Item( $item );
682
+        foreach ($items as $item) {
683
+            $item = new GetPaid_Form_Item($item);
684 684
             $data[] = array(
685 685
                 'id'        => (int) $item->get_id(),
686
-                'text'      => strip_tags( $item->get_name() ),
687
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
686
+                'text'      => strip_tags($item->get_name()),
687
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
688 688
             );
689 689
         }
690 690
 
691
-        wp_send_json_success( $data );
691
+        wp_send_json_success($data);
692 692
 
693 693
     }
694 694
 
@@ -698,24 +698,24 @@  discard block
 block discarded – undo
698 698
     public static function get_aui_states_field() {
699 699
 
700 700
         // Verify nonce.
701
-        check_ajax_referer( 'wpinv-nonce' );
701
+        check_ajax_referer('wpinv-nonce');
702 702
 
703 703
         // We need a country.
704
-        if ( empty( $_GET['country'] ) ) {
704
+        if (empty($_GET['country'])) {
705 705
             exit;
706 706
         }
707 707
 
708
-        $states = wpinv_get_country_states( trim( $_GET['country'] ) );
709
-        $state  = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state();
708
+        $states = wpinv_get_country_states(trim($_GET['country']));
709
+        $state  = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state();
710 710
 
711
-        if ( empty( $states ) ) {
711
+        if (empty($states)) {
712 712
 
713 713
             $html = aui()->input(
714 714
                 array(
715 715
                     'type'        => 'text',
716 716
                     'id'          => 'wpinv_state',
717 717
                     'name'        => 'wpinv_state',
718
-                    'label'       => __( 'State', 'invoicing' ),
718
+                    'label'       => __('State', 'invoicing'),
719 719
                     'label_type'  => 'vertical',
720 720
                     'placeholder' => 'Liège',
721 721
                     'class'       => 'form-control-sm',
@@ -729,9 +729,9 @@  discard block
 block discarded – undo
729 729
                 array(
730 730
                     'id'          => 'wpinv_state',
731 731
                     'name'        => 'wpinv_state',
732
-                    'label'       => __( 'State', 'invoicing' ),
732
+                    'label'       => __('State', 'invoicing'),
733 733
                     'label_type'  => 'vertical',
734
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
734
+                    'placeholder' => __('Select a state', 'invoicing'),
735 735
                     'class'       => 'form-control-sm',
736 736
                     'value'       => $state,
737 737
                     'options'     => $states,
@@ -745,7 +745,7 @@  discard block
 block discarded – undo
745 745
         wp_send_json_success(
746 746
             array(
747 747
                 'html'   => $html,
748
-                'select' => ! empty ( $states )
748
+                'select' => !empty ($states)
749 749
             )
750 750
         );
751 751
 
@@ -759,11 +759,11 @@  discard block
 block discarded – undo
759 759
     public static function payment_form_refresh_prices() {
760 760
 
761 761
         // Check nonce.
762
-        check_ajax_referer( 'getpaid_form_nonce' );
762
+        check_ajax_referer('getpaid_form_nonce');
763 763
 
764 764
         // ... form fields...
765
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
766
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
765
+        if (empty($_POST['getpaid_payment_form_submission'])) {
766
+            _e('Error: Reload the page and try again.', 'invoicing');
767 767
             exit;
768 768
         }
769 769
 
@@ -771,18 +771,18 @@  discard block
 block discarded – undo
771 771
         $submission = new GetPaid_Payment_Form_Submission();
772 772
 
773 773
         // Do we have an error?
774
-        if ( ! empty( $submission->last_error ) ) {
774
+        if (!empty($submission->last_error)) {
775 775
             echo $submission->last_error;
776 776
             exit;
777 777
         }
778 778
 
779 779
         // Prepare the response.
780
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
780
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
781 781
         
782 782
         // Filter the response.
783
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
783
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
784 784
 
785
-        wp_send_json_success( $response );
785
+        wp_send_json_success($response);
786 786
     }
787 787
 
788 788
 }
Please login to merge, or discard this patch.