@@ -6,7 +6,7 @@ discard block |
||
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 |
||
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 | /** |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | * @param string $amount The amount to sanitize. |
58 | 58 | * @return float |
59 | 59 | */ |
60 | -function getpaid_standardize_amount( $amount ) { |
|
60 | +function getpaid_standardize_amount($amount) { |
|
61 | 61 | |
62 | - $amount = str_replace( wpinv_thousands_separator(), '', $amount ); |
|
63 | - $amount = str_replace( wpinv_decimal_separator(), '.', $amount ); |
|
64 | - if ( is_numeric( $amount ) ) { |
|
65 | - return floatval( $amount ); |
|
62 | + $amount = str_replace(wpinv_thousands_separator(), '', $amount); |
|
63 | + $amount = str_replace(wpinv_decimal_separator(), '.', $amount); |
|
64 | + if (is_numeric($amount)) { |
|
65 | + return floatval($amount); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | // Cast the remaining to a float. |
69 | - return wpinv_round_amount( preg_replace( '/[^0-9\.\-]/', '', $amount ) ); |
|
69 | + return wpinv_round_amount(preg_replace('/[^0-9\.\-]/', '', $amount)); |
|
70 | 70 | |
71 | 71 | } |
72 | 72 | |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @param string $amount The amount to sanitize. |
77 | 77 | */ |
78 | -function getpaid_unstandardize_amount( $amount ) { |
|
79 | - return str_replace( '.', wpinv_decimal_separator(), $amount ); |
|
78 | +function getpaid_unstandardize_amount($amount) { |
|
79 | + return str_replace('.', wpinv_decimal_separator(), $amount); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -84,23 +84,23 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @param string $amount The amount to sanitize. |
86 | 86 | */ |
87 | -function wpinv_sanitize_amount( $amount ) { |
|
87 | +function wpinv_sanitize_amount($amount) { |
|
88 | 88 | |
89 | - if ( is_numeric( $amount ) ) { |
|
90 | - return floatval( $amount ); |
|
89 | + if (is_numeric($amount)) { |
|
90 | + return floatval($amount); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | // Separate the decimals and thousands. |
94 | - $amount = explode( wpinv_decimal_separator(), $amount ); |
|
94 | + $amount = explode(wpinv_decimal_separator(), $amount); |
|
95 | 95 | |
96 | 96 | // Remove thousands. |
97 | - $amount[0] = str_replace( wpinv_thousands_separator(), '', $amount[0] ); |
|
97 | + $amount[0] = str_replace(wpinv_thousands_separator(), '', $amount[0]); |
|
98 | 98 | |
99 | 99 | // Convert back to string. |
100 | - $amount = count( $amount ) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
100 | + $amount = count($amount) > 1 ? "{$amount[0]}.{$amount[1]}" : $amount[0]; |
|
101 | 101 | |
102 | 102 | // Cast the remaining to a float. |
103 | - return (float) preg_replace( '/[^0-9\.\-]/', '', $amount ); |
|
103 | + return (float) preg_replace('/[^0-9\.\-]/', '', $amount); |
|
104 | 104 | |
105 | 105 | } |
106 | 106 | |
@@ -110,19 +110,19 @@ discard block |
||
110 | 110 | * @param float $amount |
111 | 111 | * @param float|string|int|null $decimals |
112 | 112 | */ |
113 | -function wpinv_round_amount( $amount, $decimals = null, $use_sprintf = false ) { |
|
113 | +function wpinv_round_amount($amount, $decimals = null, $use_sprintf = false) { |
|
114 | 114 | |
115 | - if ( $decimals === null ) { |
|
115 | + if ($decimals === null) { |
|
116 | 116 | $decimals = wpinv_decimals(); |
117 | 117 | } |
118 | 118 | |
119 | - if ( $use_sprintf ) { |
|
120 | - $amount = sprintf( "%.{$decimals}f", (float) $amount ); |
|
119 | + if ($use_sprintf) { |
|
120 | + $amount = sprintf("%.{$decimals}f", (float) $amount); |
|
121 | 121 | } else { |
122 | - $amount = round( (float) $amount, absint( $decimals ) ); |
|
122 | + $amount = round((float) $amount, absint($decimals)); |
|
123 | 123 | } |
124 | 124 | |
125 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
125 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -134,32 +134,32 @@ discard block |
||
134 | 134 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
135 | 135 | * @return array |
136 | 136 | */ |
137 | -function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
|
137 | +function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) { |
|
138 | 138 | |
139 | 139 | $invoice_statuses = array( |
140 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
141 | - 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
|
142 | - 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
143 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
144 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
145 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
146 | - 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
147 | - 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
|
140 | + 'wpi-pending' => _x('Pending payment', 'Invoice status', 'invoicing'), |
|
141 | + 'publish' => _x('Paid', 'Invoice status', 'invoicing'), |
|
142 | + 'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'), |
|
143 | + 'wpi-onhold' => _x('On hold', 'Invoice status', 'invoicing'), |
|
144 | + 'wpi-cancelled' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
145 | + 'wpi-refunded' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
146 | + 'wpi-failed' => _x('Failed', 'Invoice status', 'invoicing'), |
|
147 | + 'wpi-renewal' => _x('Renewal Payment', 'Invoice status', 'invoicing'), |
|
148 | 148 | ); |
149 | 149 | |
150 | - if ( $draft ) { |
|
151 | - $invoice_statuses['draft'] = __( 'Draft', 'invoicing' ); |
|
150 | + if ($draft) { |
|
151 | + $invoice_statuses['draft'] = __('Draft', 'invoicing'); |
|
152 | 152 | } |
153 | 153 | |
154 | - if ( $trashed ) { |
|
155 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
154 | + if ($trashed) { |
|
155 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
156 | 156 | } |
157 | 157 | |
158 | - if ( $invoice instanceof WPInv_Invoice ) { |
|
158 | + if ($invoice instanceof WPInv_Invoice) { |
|
159 | 159 | $invoice = $invoice->get_post_type(); |
160 | 160 | } |
161 | 161 | |
162 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
162 | + return apply_filters('wpinv_statuses', $invoice_statuses, $invoice); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -168,11 +168,11 @@ discard block |
||
168 | 168 | * @param string $status The raw status |
169 | 169 | * @param string|WPInv_Invoice $invoice The invoice object|post type|type |
170 | 170 | */ |
171 | -function wpinv_status_nicename( $status, $invoice = false ) { |
|
172 | - $statuses = wpinv_get_invoice_statuses( true, true, $invoice ); |
|
173 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : $status; |
|
171 | +function wpinv_status_nicename($status, $invoice = false) { |
|
172 | + $statuses = wpinv_get_invoice_statuses(true, true, $invoice); |
|
173 | + $status = isset($statuses[$status]) ? $statuses[$status] : $status; |
|
174 | 174 | |
175 | - return sanitize_text_field( $status ); |
|
175 | + return sanitize_text_field($status); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | * |
181 | 181 | * @param string $current |
182 | 182 | */ |
183 | -function wpinv_get_currency( $current = '' ) { |
|
183 | +function wpinv_get_currency($current = '') { |
|
184 | 184 | |
185 | - if ( empty( $current ) ) { |
|
186 | - $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) ); |
|
185 | + if (empty($current)) { |
|
186 | + $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD')); |
|
187 | 187 | } |
188 | 188 | |
189 | - return trim( strtoupper( $current ) ); |
|
189 | + return trim(strtoupper($current)); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | /** |
@@ -194,25 +194,25 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @param string|null $currency The currency code. Defaults to the default currency. |
196 | 196 | */ |
197 | -function wpinv_currency_symbol( $currency = null ) { |
|
197 | +function wpinv_currency_symbol($currency = null) { |
|
198 | 198 | |
199 | 199 | // Prepare the currency. |
200 | - $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency ); |
|
200 | + $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency); |
|
201 | 201 | |
202 | 202 | // Fetch all symbols. |
203 | 203 | $symbols = wpinv_get_currency_symbols(); |
204 | 204 | |
205 | 205 | // Fetch this currencies symbol. |
206 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency; |
|
206 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
207 | 207 | |
208 | 208 | // Filter the symbol. |
209 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
209 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_currency_position() { |
213 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
213 | + $position = wpinv_get_option('currency_position', 'left'); |
|
214 | 214 | |
215 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
215 | + return apply_filters('wpinv_currency_position', $position); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @param $string|null $current |
222 | 222 | */ |
223 | -function wpinv_thousands_separator( $current = null ) { |
|
223 | +function wpinv_thousands_separator($current = null) { |
|
224 | 224 | |
225 | - if ( null == $current ) { |
|
226 | - $current = wpinv_get_option( 'thousands_separator', ',' ); |
|
225 | + if (null == $current) { |
|
226 | + $current = wpinv_get_option('thousands_separator', ','); |
|
227 | 227 | } |
228 | 228 | |
229 | - return trim( $current ); |
|
229 | + return trim($current); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -234,13 +234,13 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @param $string|null $current |
236 | 236 | */ |
237 | -function wpinv_decimal_separator( $current = null ) { |
|
237 | +function wpinv_decimal_separator($current = null) { |
|
238 | 238 | |
239 | - if ( null == $current ) { |
|
240 | - $current = wpinv_get_option( 'decimal_separator', '.' ); |
|
239 | + if (null == $current) { |
|
240 | + $current = wpinv_get_option('decimal_separator', '.'); |
|
241 | 241 | } |
242 | 242 | |
243 | - return trim( $current ); |
|
243 | + return trim($current); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -248,27 +248,27 @@ discard block |
||
248 | 248 | * |
249 | 249 | * @param $string|null $current |
250 | 250 | */ |
251 | -function wpinv_decimals( $current = null ) { |
|
251 | +function wpinv_decimals($current = null) { |
|
252 | 252 | |
253 | - if ( null == $current ) { |
|
254 | - $current = wpinv_get_option( 'decimals', 2 ); |
|
253 | + if (null == $current) { |
|
254 | + $current = wpinv_get_option('decimals', 2); |
|
255 | 255 | } |
256 | 256 | |
257 | - return absint( $current ); |
|
257 | + return absint($current); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
261 | 261 | * Retrieves a list of all supported currencies. |
262 | 262 | */ |
263 | 263 | function wpinv_get_currencies() { |
264 | - return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) ); |
|
264 | + return apply_filters('wpinv_currencies', wpinv_get_data('currencies')); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | /** |
268 | 268 | * Retrieves a list of all currency symbols. |
269 | 269 | */ |
270 | 270 | function wpinv_get_currency_symbols() { |
271 | - return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) ); |
|
271 | + return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols')); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | /** |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | $currency_pos = wpinv_currency_position(); |
281 | 281 | $format = '%1$s%2$s'; |
282 | 282 | |
283 | - switch ( $currency_pos ) { |
|
283 | + switch ($currency_pos) { |
|
284 | 284 | case 'left': |
285 | 285 | $format = '%1$s%2$s'; |
286 | 286 | break; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | break; |
296 | 296 | } |
297 | 297 | |
298 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
298 | + return apply_filters('getpaid_price_format', $format, $currency_pos); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
@@ -305,25 +305,25 @@ discard block |
||
305 | 305 | * @param string $currency Currency. |
306 | 306 | * @return string |
307 | 307 | */ |
308 | -function wpinv_price( $amount = 0, $currency = '' ) { |
|
308 | +function wpinv_price($amount = 0, $currency = '') { |
|
309 | 309 | |
310 | 310 | // Backwards compatibility. |
311 | - $amount = wpinv_sanitize_amount( $amount ); |
|
311 | + $amount = wpinv_sanitize_amount($amount); |
|
312 | 312 | |
313 | 313 | // Prepare variables. |
314 | - $currency = wpinv_get_currency( $currency ); |
|
314 | + $currency = wpinv_get_currency($currency); |
|
315 | 315 | $amount = (float) $amount; |
316 | 316 | $unformatted_amount = $amount; |
317 | 317 | $negative = $amount < 0; |
318 | - $amount = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) ); |
|
319 | - $amount = wpinv_format_amount( $amount ); |
|
318 | + $amount = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount)); |
|
319 | + $amount = wpinv_format_amount($amount); |
|
320 | 320 | |
321 | 321 | // Format the amount. |
322 | 322 | $format = getpaid_get_price_format(); |
323 | - $formatted_amount = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount ); |
|
323 | + $formatted_amount = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount); |
|
324 | 324 | |
325 | 325 | // Filter the formatting. |
326 | - return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount ); |
|
326 | + return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -334,25 +334,25 @@ discard block |
||
334 | 334 | * @param bool $calculate Whether or not to apply separators. |
335 | 335 | * @return string |
336 | 336 | */ |
337 | -function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) { |
|
337 | +function wpinv_format_amount($amount, $decimals = null, $calculate = false) { |
|
338 | 338 | $thousands_sep = wpinv_thousands_separator(); |
339 | 339 | $decimal_sep = wpinv_decimal_separator(); |
340 | - $decimals = wpinv_decimals( $decimals ); |
|
341 | - $amount = wpinv_sanitize_amount( $amount ); |
|
340 | + $decimals = wpinv_decimals($decimals); |
|
341 | + $amount = wpinv_sanitize_amount($amount); |
|
342 | 342 | |
343 | - if ( $calculate ) { |
|
343 | + if ($calculate) { |
|
344 | 344 | return $amount; |
345 | 345 | } |
346 | 346 | |
347 | 347 | // Fomart the amount. |
348 | - return number_format( $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
348 | + return number_format($amount, $decimals, $decimal_sep, $thousands_sep); |
|
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_sanitize_key( $key ) { |
|
351 | +function wpinv_sanitize_key($key) { |
|
352 | 352 | $raw_key = $key; |
353 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
353 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
354 | 354 | |
355 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
355 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -360,8 +360,8 @@ discard block |
||
360 | 360 | * |
361 | 361 | * @param $str the file whose extension should be retrieved. |
362 | 362 | */ |
363 | -function wpinv_get_file_extension( $str ) { |
|
364 | - $filetype = wp_check_filetype( $str ); |
|
363 | +function wpinv_get_file_extension($str) { |
|
364 | + $filetype = wp_check_filetype($str); |
|
365 | 365 | return $filetype['ext']; |
366 | 366 | } |
367 | 367 | |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | * |
371 | 371 | * @param string $string |
372 | 372 | */ |
373 | -function wpinv_string_is_image_url( $string ) { |
|
374 | - $extension = strtolower( wpinv_get_file_extension( $string ) ); |
|
375 | - return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true ); |
|
373 | +function wpinv_string_is_image_url($string) { |
|
374 | + $extension = strtolower(wpinv_get_file_extension($string)); |
|
375 | + return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | /** |
379 | 379 | * Returns the current URL. |
380 | 380 | */ |
381 | 381 | function wpinv_get_current_page_url() { |
382 | - return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
382 | + return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | /** |
@@ -389,46 +389,46 @@ discard block |
||
389 | 389 | * @param string $name Constant name. |
390 | 390 | * @param mixed $value Value. |
391 | 391 | */ |
392 | -function getpaid_maybe_define_constant( $name, $value ) { |
|
393 | - if ( ! defined( $name ) ) { |
|
394 | - define( $name, $value ); |
|
392 | +function getpaid_maybe_define_constant($name, $value) { |
|
393 | + if (!defined($name)) { |
|
394 | + define($name, $value); |
|
395 | 395 | } |
396 | 396 | } |
397 | 397 | |
398 | 398 | function wpinv_get_php_arg_separator_output() { |
399 | - return ini_get( 'arg_separator.output' ); |
|
399 | + return ini_get('arg_separator.output'); |
|
400 | 400 | } |
401 | 401 | |
402 | -function wpinv_rgb_from_hex( $color ) { |
|
403 | - $color = str_replace( '#', '', $color ); |
|
402 | +function wpinv_rgb_from_hex($color) { |
|
403 | + $color = str_replace('#', '', $color); |
|
404 | 404 | |
405 | 405 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
406 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
407 | - if ( empty( $color ) ) { |
|
406 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
407 | + if (empty($color)) { |
|
408 | 408 | return NULL; |
409 | 409 | } |
410 | 410 | |
411 | - $color = str_split( $color ); |
|
411 | + $color = str_split($color); |
|
412 | 412 | |
413 | 413 | $rgb = array(); |
414 | - $rgb['R'] = hexdec( $color[0] . $color[1] ); |
|
415 | - $rgb['G'] = hexdec( $color[2] . $color[3] ); |
|
416 | - $rgb['B'] = hexdec( $color[4] . $color[5] ); |
|
414 | + $rgb['R'] = hexdec($color[0] . $color[1]); |
|
415 | + $rgb['G'] = hexdec($color[2] . $color[3]); |
|
416 | + $rgb['B'] = hexdec($color[4] . $color[5]); |
|
417 | 417 | |
418 | 418 | return $rgb; |
419 | 419 | } |
420 | 420 | |
421 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
422 | - $base = wpinv_rgb_from_hex( $color ); |
|
421 | +function wpinv_hex_darker($color, $factor = 30) { |
|
422 | + $base = wpinv_rgb_from_hex($color); |
|
423 | 423 | $color = '#'; |
424 | 424 | |
425 | - foreach ( $base as $k => $v ) { |
|
425 | + foreach ($base as $k => $v) { |
|
426 | 426 | $amount = $v / 100; |
427 | - $amount = round( $amount * $factor ); |
|
427 | + $amount = round($amount * $factor); |
|
428 | 428 | $new_decimal = $v - $amount; |
429 | 429 | |
430 | - $new_hex_component = dechex( $new_decimal ); |
|
431 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
430 | + $new_hex_component = dechex($new_decimal); |
|
431 | + if (strlen($new_hex_component) < 2) { |
|
432 | 432 | $new_hex_component = "0" . $new_hex_component; |
433 | 433 | } |
434 | 434 | $color .= $new_hex_component; |
@@ -437,18 +437,18 @@ discard block |
||
437 | 437 | return $color; |
438 | 438 | } |
439 | 439 | |
440 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
441 | - $base = wpinv_rgb_from_hex( $color ); |
|
440 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
441 | + $base = wpinv_rgb_from_hex($color); |
|
442 | 442 | $color = '#'; |
443 | 443 | |
444 | - foreach ( $base as $k => $v ) { |
|
444 | + foreach ($base as $k => $v) { |
|
445 | 445 | $amount = 255 - $v; |
446 | 446 | $amount = $amount / 100; |
447 | - $amount = round( $amount * $factor ); |
|
447 | + $amount = round($amount * $factor); |
|
448 | 448 | $new_decimal = $v + $amount; |
449 | 449 | |
450 | - $new_hex_component = dechex( $new_decimal ); |
|
451 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
450 | + $new_hex_component = dechex($new_decimal); |
|
451 | + if (strlen($new_hex_component) < 2) { |
|
452 | 452 | $new_hex_component = "0" . $new_hex_component; |
453 | 453 | } |
454 | 454 | $color .= $new_hex_component; |
@@ -457,22 +457,22 @@ discard block |
||
457 | 457 | return $color; |
458 | 458 | } |
459 | 459 | |
460 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
461 | - $hex = str_replace( '#', '', $color ); |
|
460 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
461 | + $hex = str_replace('#', '', $color); |
|
462 | 462 | |
463 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
464 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
465 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
463 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
464 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
465 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
466 | 466 | |
467 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
467 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
468 | 468 | |
469 | 469 | return $brightness > 155 ? $dark : $light; |
470 | 470 | } |
471 | 471 | |
472 | -function wpinv_format_hex( $hex ) { |
|
473 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
472 | +function wpinv_format_hex($hex) { |
|
473 | + $hex = trim(str_replace('#', '', $hex)); |
|
474 | 474 | |
475 | - if ( strlen( $hex ) == 3 ) { |
|
475 | + if (strlen($hex) == 3) { |
|
476 | 476 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
477 | 477 | } |
478 | 478 | |
@@ -492,12 +492,12 @@ discard block |
||
492 | 492 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
493 | 493 | * @return string |
494 | 494 | */ |
495 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
496 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
497 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
495 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
496 | + if (function_exists('mb_strimwidth')) { |
|
497 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
498 | 498 | } |
499 | 499 | |
500 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
500 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | /** |
@@ -509,28 +509,28 @@ discard block |
||
509 | 509 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
510 | 510 | * @return int Returns the number of characters in string. |
511 | 511 | */ |
512 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
513 | - if ( function_exists( 'mb_strlen' ) ) { |
|
514 | - return mb_strlen( $str, $encoding ); |
|
512 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
513 | + if (function_exists('mb_strlen')) { |
|
514 | + return mb_strlen($str, $encoding); |
|
515 | 515 | } |
516 | 516 | |
517 | - return strlen( $str ); |
|
517 | + return strlen($str); |
|
518 | 518 | } |
519 | 519 | |
520 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
521 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
522 | - return mb_strtolower( $str, $encoding ); |
|
520 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
521 | + if (function_exists('mb_strtolower')) { |
|
522 | + return mb_strtolower($str, $encoding); |
|
523 | 523 | } |
524 | 524 | |
525 | - return strtolower( $str ); |
|
525 | + return strtolower($str); |
|
526 | 526 | } |
527 | 527 | |
528 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
529 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
530 | - return mb_strtoupper( $str, $encoding ); |
|
528 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
529 | + if (function_exists('mb_strtoupper')) { |
|
530 | + return mb_strtoupper($str, $encoding); |
|
531 | 531 | } |
532 | 532 | |
533 | - return strtoupper( $str ); |
|
533 | + return strtoupper($str); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
@@ -544,12 +544,12 @@ discard block |
||
544 | 544 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
545 | 545 | * @return int Returns the position of the first occurrence of search in the string. |
546 | 546 | */ |
547 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
548 | - if ( function_exists( 'mb_strpos' ) ) { |
|
549 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
547 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
548 | + if (function_exists('mb_strpos')) { |
|
549 | + return mb_strpos($str, $find, $offset, $encoding); |
|
550 | 550 | } |
551 | 551 | |
552 | - return strpos( $str, $find, $offset ); |
|
552 | + return strpos($str, $find, $offset); |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | /** |
@@ -563,12 +563,12 @@ discard block |
||
563 | 563 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
564 | 564 | * @return int Returns the position of the last occurrence of search. |
565 | 565 | */ |
566 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
567 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
568 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
566 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
567 | + if (function_exists('mb_strrpos')) { |
|
568 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
569 | 569 | } |
570 | 570 | |
571 | - return strrpos( $str, $find, $offset ); |
|
571 | + return strrpos($str, $find, $offset); |
|
572 | 572 | } |
573 | 573 | |
574 | 574 | /** |
@@ -583,16 +583,16 @@ discard block |
||
583 | 583 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
584 | 584 | * @return string |
585 | 585 | */ |
586 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
587 | - if ( function_exists( 'mb_substr' ) ) { |
|
588 | - if ( $length === null ) { |
|
589 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
586 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
587 | + if (function_exists('mb_substr')) { |
|
588 | + if ($length === null) { |
|
589 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
590 | 590 | } else { |
591 | - return mb_substr( $str, $start, $length, $encoding ); |
|
591 | + return mb_substr($str, $start, $length, $encoding); |
|
592 | 592 | } |
593 | 593 | } |
594 | 594 | |
595 | - return substr( $str, $start, $length ); |
|
595 | + return substr($str, $start, $length); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -604,48 +604,48 @@ discard block |
||
604 | 604 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
605 | 605 | * @return string The width of string. |
606 | 606 | */ |
607 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
608 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
609 | - return mb_strwidth( $str, $encoding ); |
|
607 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
608 | + if (function_exists('mb_strwidth')) { |
|
609 | + return mb_strwidth($str, $encoding); |
|
610 | 610 | } |
611 | 611 | |
612 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
612 | + return wpinv_utf8_strlen($str, $encoding); |
|
613 | 613 | } |
614 | 614 | |
615 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
616 | - if ( function_exists( 'mb_strlen' ) ) { |
|
617 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
615 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
616 | + if (function_exists('mb_strlen')) { |
|
617 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
618 | 618 | $str_end = ""; |
619 | 619 | |
620 | - if ( $lower_str_end ) { |
|
621 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
620 | + if ($lower_str_end) { |
|
621 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
622 | 622 | } else { |
623 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
623 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | return $first_letter . $str_end; |
627 | 627 | } |
628 | 628 | |
629 | - return ucfirst( $str ); |
|
629 | + return ucfirst($str); |
|
630 | 630 | } |
631 | 631 | |
632 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
633 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
634 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
632 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
633 | + if (function_exists('mb_convert_case')) { |
|
634 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
635 | 635 | } |
636 | 636 | |
637 | - return ucwords( $str ); |
|
637 | + return ucwords($str); |
|
638 | 638 | } |
639 | 639 | |
640 | -function wpinv_period_in_days( $period, $unit ) { |
|
641 | - $period = absint( $period ); |
|
640 | +function wpinv_period_in_days($period, $unit) { |
|
641 | + $period = absint($period); |
|
642 | 642 | |
643 | - if ( $period > 0 ) { |
|
644 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
643 | + if ($period > 0) { |
|
644 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
645 | 645 | $period = $period * 7; |
646 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
646 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
647 | 647 | $period = $period * 30; |
648 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
648 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
649 | 649 | $period = $period * 365; |
650 | 650 | } |
651 | 651 | } |
@@ -653,14 +653,14 @@ discard block |
||
653 | 653 | return $period; |
654 | 654 | } |
655 | 655 | |
656 | -function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
|
657 | - if ( function_exists( 'cal_days_in_month' ) ) { |
|
658 | - return cal_days_in_month( $calendar, $month, $year ); |
|
656 | +function wpinv_cal_days_in_month($calendar, $month, $year) { |
|
657 | + if (function_exists('cal_days_in_month')) { |
|
658 | + return cal_days_in_month($calendar, $month, $year); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | // Fallback in case the calendar extension is not loaded in PHP |
662 | 662 | // Only supports Gregorian calendar |
663 | - return date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
663 | + return date('t', mktime(0, 0, 0, $month, 1, $year)); |
|
664 | 664 | } |
665 | 665 | |
666 | 666 | /** |
@@ -671,12 +671,12 @@ discard block |
||
671 | 671 | * |
672 | 672 | * @return string |
673 | 673 | */ |
674 | -function wpi_help_tip( $tip, $allow_html = false ) { |
|
674 | +function wpi_help_tip($tip, $allow_html = false) { |
|
675 | 675 | |
676 | - if ( $allow_html ) { |
|
677 | - $tip = wpi_sanitize_tooltip( $tip ); |
|
676 | + if ($allow_html) { |
|
677 | + $tip = wpi_sanitize_tooltip($tip); |
|
678 | 678 | } else { |
679 | - $tip = esc_attr( $tip ); |
|
679 | + $tip = esc_attr($tip); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -690,8 +690,8 @@ discard block |
||
690 | 690 | * @param string $var |
691 | 691 | * @return string |
692 | 692 | */ |
693 | -function wpi_sanitize_tooltip( $var ) { |
|
694 | - return wp_kses( html_entity_decode( $var ), array( |
|
693 | +function wpi_sanitize_tooltip($var) { |
|
694 | + return wp_kses(html_entity_decode($var), array( |
|
695 | 695 | 'br' => array(), |
696 | 696 | 'em' => array(), |
697 | 697 | 'strong' => array(), |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | 'li' => array(), |
703 | 703 | 'ol' => array(), |
704 | 704 | 'p' => array(), |
705 | - ) ); |
|
705 | + )); |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | /** |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | */ |
713 | 713 | function wpinv_get_screen_ids() { |
714 | 714 | |
715 | - $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) ); |
|
715 | + $screen_id = sanitize_title(__('Invoicing', 'invoicing')); |
|
716 | 716 | |
717 | 717 | $screen_ids = array( |
718 | 718 | 'toplevel_page_' . $screen_id, |
@@ -731,10 +731,10 @@ discard block |
||
731 | 731 | 'getpaid_page_wpinv-reports', |
732 | 732 | 'getpaid_page_wpi-addons', |
733 | 733 | 'getpaid_page_wpinv-customers', |
734 | - 'gp-setup',// setup wizard |
|
734 | + 'gp-setup', // setup wizard |
|
735 | 735 | ); |
736 | 736 | |
737 | - return apply_filters( 'wpinv_screen_ids', $screen_ids ); |
|
737 | + return apply_filters('wpinv_screen_ids', $screen_ids); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | /** |
@@ -745,14 +745,14 @@ discard block |
||
745 | 745 | * @param array|string $list List of values. |
746 | 746 | * @return array Sanitized array of values. |
747 | 747 | */ |
748 | -function wpinv_parse_list( $list ) { |
|
748 | +function wpinv_parse_list($list) { |
|
749 | 749 | |
750 | - if ( empty( $list ) ) { |
|
750 | + if (empty($list)) { |
|
751 | 751 | $list = array(); |
752 | 752 | } |
753 | 753 | |
754 | - if ( ! is_array( $list ) ) { |
|
755 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
754 | + if (!is_array($list)) { |
|
755 | + return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY); |
|
756 | 756 | } |
757 | 757 | |
758 | 758 | return $list; |
@@ -766,16 +766,16 @@ discard block |
||
766 | 766 | * @param string $key Type of data to fetch. |
767 | 767 | * @return mixed Fetched data. |
768 | 768 | */ |
769 | -function wpinv_get_data( $key ) { |
|
769 | +function wpinv_get_data($key) { |
|
770 | 770 | |
771 | 771 | // Try fetching it from the cache. |
772 | - $data = wp_cache_get( "wpinv-data-$key", 'wpinv' ); |
|
773 | - if( $data ) { |
|
772 | + $data = wp_cache_get("wpinv-data-$key", 'wpinv'); |
|
773 | + if ($data) { |
|
774 | 774 | return $data; |
775 | 775 | } |
776 | 776 | |
777 | - $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
|
778 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
777 | + $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php"); |
|
778 | + wp_cache_set("wpinv-data-$key", $data, 'wpinv'); |
|
779 | 779 | |
780 | 780 | return $data; |
781 | 781 | } |
@@ -789,10 +789,10 @@ discard block |
||
789 | 789 | * @param bool $first_empty Whether or not the first item in the list should be empty |
790 | 790 | * @return mixed Fetched data. |
791 | 791 | */ |
792 | -function wpinv_maybe_add_empty_option( $options, $first_empty ) { |
|
792 | +function wpinv_maybe_add_empty_option($options, $first_empty) { |
|
793 | 793 | |
794 | - if ( ! empty( $options ) && $first_empty ) { |
|
795 | - return array_merge( array( '' => '' ), $options ); |
|
794 | + if (!empty($options) && $first_empty) { |
|
795 | + return array_merge(array('' => ''), $options); |
|
796 | 796 | } |
797 | 797 | return $options; |
798 | 798 | |
@@ -804,21 +804,21 @@ discard block |
||
804 | 804 | * @param mixed $var Data to sanitize. |
805 | 805 | * @return string|array |
806 | 806 | */ |
807 | -function wpinv_clean( $var ) { |
|
807 | +function wpinv_clean($var) { |
|
808 | 808 | |
809 | - if ( is_array( $var ) ) { |
|
810 | - return array_map( 'wpinv_clean', $var ); |
|
809 | + if (is_array($var)) { |
|
810 | + return array_map('wpinv_clean', $var); |
|
811 | 811 | } |
812 | 812 | |
813 | - if ( is_object( $var ) ) { |
|
814 | - $object_vars = get_object_vars( $var ); |
|
815 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
816 | - $var->$property_name = wpinv_clean( $property_value ); |
|
813 | + if (is_object($var)) { |
|
814 | + $object_vars = get_object_vars($var); |
|
815 | + foreach ($object_vars as $property_name => $property_value) { |
|
816 | + $var->$property_name = wpinv_clean($property_value); |
|
817 | 817 | } |
818 | 818 | return $var; |
819 | 819 | } |
820 | 820 | |
821 | - return is_string( $var ) ? sanitize_text_field( stripslashes( $var ) ) : $var; |
|
821 | + return is_string($var) ? sanitize_text_field(stripslashes($var)) : $var; |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
@@ -827,43 +827,43 @@ discard block |
||
827 | 827 | * @param string $str Data to convert. |
828 | 828 | * @return string|array |
829 | 829 | */ |
830 | -function getpaid_convert_price_string_to_options( $str ) { |
|
830 | +function getpaid_convert_price_string_to_options($str) { |
|
831 | 831 | |
832 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
833 | - $options = array(); |
|
832 | + $raw_options = array_map('trim', explode(',', $str)); |
|
833 | + $options = array(); |
|
834 | 834 | |
835 | - foreach ( $raw_options as $option ) { |
|
835 | + foreach ($raw_options as $option) { |
|
836 | 836 | |
837 | - if ( '' == $option ) { |
|
837 | + if ('' == $option) { |
|
838 | 838 | continue; |
839 | 839 | } |
840 | 840 | |
841 | - $option = array_map( 'trim', explode( '|', $option ) ); |
|
841 | + $option = array_map('trim', explode('|', $option)); |
|
842 | 842 | |
843 | 843 | $price = null; |
844 | 844 | $label = null; |
845 | 845 | |
846 | - if ( isset( $option[0] ) && '' != $option[0] ) { |
|
847 | - $label = $option[0]; |
|
846 | + if (isset($option[0]) && '' != $option[0]) { |
|
847 | + $label = $option[0]; |
|
848 | 848 | } |
849 | 849 | |
850 | - if ( isset( $option[1] ) && '' != $option[1] ) { |
|
850 | + if (isset($option[1]) && '' != $option[1]) { |
|
851 | 851 | $price = $option[1]; |
852 | 852 | } |
853 | 853 | |
854 | - if ( ! isset( $price ) ) { |
|
854 | + if (!isset($price)) { |
|
855 | 855 | $price = $label; |
856 | 856 | } |
857 | 857 | |
858 | - if ( ! isset( $price ) || ! is_numeric( $price ) ) { |
|
858 | + if (!isset($price) || !is_numeric($price)) { |
|
859 | 859 | continue; |
860 | 860 | } |
861 | 861 | |
862 | - if ( ! isset( $label ) ) { |
|
862 | + if (!isset($label)) { |
|
863 | 863 | $label = $price; |
864 | 864 | } |
865 | 865 | |
866 | - $options[ "$label|$price" ] = $label; |
|
866 | + $options["$label|$price"] = $label; |
|
867 | 867 | } |
868 | 868 | |
869 | 869 | return $options; |
@@ -872,27 +872,27 @@ discard block |
||
872 | 872 | /** |
873 | 873 | * Returns the help tip. |
874 | 874 | */ |
875 | -function getpaid_get_help_tip( $tip, $additional_classes = '' ) { |
|
876 | - $additional_classes = sanitize_html_class( $additional_classes ); |
|
877 | - $tip = esc_attr__( $tip ); |
|
875 | +function getpaid_get_help_tip($tip, $additional_classes = '') { |
|
876 | + $additional_classes = sanitize_html_class($additional_classes); |
|
877 | + $tip = esc_attr__($tip); |
|
878 | 878 | return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>"; |
879 | 879 | } |
880 | 880 | |
881 | 881 | /** |
882 | 882 | * Formats a date |
883 | 883 | */ |
884 | -function getpaid_format_date( $date, $with_time = false ) { |
|
884 | +function getpaid_format_date($date, $with_time = false) { |
|
885 | 885 | |
886 | - if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) { |
|
886 | + if (empty($date) || $date == '0000-00-00 00:00:00') { |
|
887 | 887 | return ''; |
888 | 888 | } |
889 | 889 | |
890 | 890 | $format = getpaid_date_format(); |
891 | 891 | |
892 | - if ( $with_time ) { |
|
892 | + if ($with_time) { |
|
893 | 893 | $format .= ' ' . getpaid_time_format(); |
894 | 894 | } |
895 | - return date_i18n( $format, strtotime( $date ) ); |
|
895 | + return date_i18n($format, strtotime($date)); |
|
896 | 896 | |
897 | 897 | } |
898 | 898 | |
@@ -901,9 +901,9 @@ discard block |
||
901 | 901 | * |
902 | 902 | * @return string |
903 | 903 | */ |
904 | -function getpaid_format_date_value( $date, $default = "—", $with_time = false ) { |
|
905 | - $date = getpaid_format_date( $date, $with_time ); |
|
906 | - return empty( $date ) ? $default : $date; |
|
904 | +function getpaid_format_date_value($date, $default = "—", $with_time = false) { |
|
905 | + $date = getpaid_format_date($date, $with_time); |
|
906 | + return empty($date) ? $default : $date; |
|
907 | 907 | } |
908 | 908 | |
909 | 909 | /** |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | * @return string |
913 | 913 | */ |
914 | 914 | function getpaid_date_format() { |
915 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
915 | + return apply_filters('getpaid_date_format', get_option('date_format')); |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | /** |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | * @return string |
922 | 922 | */ |
923 | 923 | function getpaid_time_format() { |
924 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
924 | + return apply_filters('getpaid_time_format', get_option('time_format')); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
@@ -931,16 +931,16 @@ discard block |
||
931 | 931 | * @param integer $limit Limit size in characters. |
932 | 932 | * @return string |
933 | 933 | */ |
934 | -function getpaid_limit_length( $string, $limit ) { |
|
934 | +function getpaid_limit_length($string, $limit) { |
|
935 | 935 | $str_limit = $limit - 3; |
936 | 936 | |
937 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
938 | - if ( mb_strlen( $string ) > $limit ) { |
|
939 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
937 | + if (function_exists('mb_strimwidth')) { |
|
938 | + if (mb_strlen($string) > $limit) { |
|
939 | + $string = mb_strimwidth($string, 0, $str_limit) . '...'; |
|
940 | 940 | } |
941 | 941 | } else { |
942 | - if ( strlen( $string ) > $limit ) { |
|
943 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
942 | + if (strlen($string) > $limit) { |
|
943 | + $string = substr($string, 0, $str_limit) . '...'; |
|
944 | 944 | } |
945 | 945 | } |
946 | 946 | return $string; |
@@ -954,7 +954,7 @@ discard block |
||
954 | 954 | * @since 1.0.19 |
955 | 955 | */ |
956 | 956 | function getpaid_api() { |
957 | - return getpaid()->get( 'api' ); |
|
957 | + return getpaid()->get('api'); |
|
958 | 958 | } |
959 | 959 | |
960 | 960 | /** |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | * @since 1.0.19 |
965 | 965 | */ |
966 | 966 | function getpaid_post_types() { |
967 | - return getpaid()->get( 'post_types' ); |
|
967 | + return getpaid()->get('post_types'); |
|
968 | 968 | } |
969 | 969 | |
970 | 970 | /** |
@@ -974,7 +974,7 @@ discard block |
||
974 | 974 | * @since 1.0.19 |
975 | 975 | */ |
976 | 976 | function getpaid_session() { |
977 | - return getpaid()->get( 'session' ); |
|
977 | + return getpaid()->get('session'); |
|
978 | 978 | } |
979 | 979 | |
980 | 980 | /** |
@@ -984,7 +984,7 @@ discard block |
||
984 | 984 | * @since 1.0.19 |
985 | 985 | */ |
986 | 986 | function getpaid_notes() { |
987 | - return getpaid()->get( 'notes' ); |
|
987 | + return getpaid()->get('notes'); |
|
988 | 988 | } |
989 | 989 | |
990 | 990 | /** |
@@ -993,7 +993,7 @@ discard block |
||
993 | 993 | * @return GetPaid_Admin |
994 | 994 | */ |
995 | 995 | function getpaid_admin() { |
996 | - return getpaid()->get( 'admin' ); |
|
996 | + return getpaid()->get('admin'); |
|
997 | 997 | } |
998 | 998 | |
999 | 999 | /** |
@@ -1003,8 +1003,8 @@ discard block |
||
1003 | 1003 | * @param string $base the base url |
1004 | 1004 | * @return string |
1005 | 1005 | */ |
1006 | -function getpaid_get_authenticated_action_url( $action, $base = false ) { |
|
1007 | - return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
1006 | +function getpaid_get_authenticated_action_url($action, $base = false) { |
|
1007 | + return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce'); |
|
1008 | 1008 | } |
1009 | 1009 | |
1010 | 1010 | /** |
@@ -1012,11 +1012,11 @@ discard block |
||
1012 | 1012 | * |
1013 | 1013 | * @return string |
1014 | 1014 | */ |
1015 | -function getpaid_get_post_type_label( $post_type, $plural = true ) { |
|
1015 | +function getpaid_get_post_type_label($post_type, $plural = true) { |
|
1016 | 1016 | |
1017 | - $post_type = get_post_type_object( $post_type ); |
|
1017 | + $post_type = get_post_type_object($post_type); |
|
1018 | 1018 | |
1019 | - if ( ! is_object( $post_type ) ) { |
|
1019 | + if (!is_object($post_type)) { |
|
1020 | 1020 | return null; |
1021 | 1021 | } |
1022 | 1022 | |
@@ -1029,18 +1029,18 @@ discard block |
||
1029 | 1029 | * |
1030 | 1030 | * @return mixed|null |
1031 | 1031 | */ |
1032 | -function getpaid_get_array_field( $array, $key, $secondary_key = null ) { |
|
1032 | +function getpaid_get_array_field($array, $key, $secondary_key = null) { |
|
1033 | 1033 | |
1034 | - if ( ! is_array( $array ) ) { |
|
1034 | + if (!is_array($array)) { |
|
1035 | 1035 | return null; |
1036 | 1036 | } |
1037 | 1037 | |
1038 | - if ( ! empty( $secondary_key ) ) { |
|
1039 | - $array = isset( $array[ $secondary_key ] ) ? $array[ $secondary_key ] : array(); |
|
1040 | - return getpaid_get_array_field( $array, $key ); |
|
1038 | + if (!empty($secondary_key)) { |
|
1039 | + $array = isset($array[$secondary_key]) ? $array[$secondary_key] : array(); |
|
1040 | + return getpaid_get_array_field($array, $key); |
|
1041 | 1041 | } |
1042 | 1042 | |
1043 | - return isset( $array[ $key ] ) ? $array[ $key ] : null; |
|
1043 | + return isset($array[$key]) ? $array[$key] : null; |
|
1044 | 1044 | |
1045 | 1045 | } |
1046 | 1046 | |
@@ -1049,12 +1049,12 @@ discard block |
||
1049 | 1049 | * |
1050 | 1050 | * @return array |
1051 | 1051 | */ |
1052 | -function getpaid_array_merge_if_empty( $args, $defaults ) { |
|
1052 | +function getpaid_array_merge_if_empty($args, $defaults) { |
|
1053 | 1053 | |
1054 | - foreach ( $defaults as $key => $value ) { |
|
1054 | + foreach ($defaults as $key => $value) { |
|
1055 | 1055 | |
1056 | - if ( array_key_exists( $key, $args ) && empty( $args[ $key ] ) ) { |
|
1057 | - $args[ $key ] = $value; |
|
1056 | + if (array_key_exists($key, $args) && empty($args[$key])) { |
|
1057 | + $args[$key] = $value; |
|
1058 | 1058 | } |
1059 | 1059 | |
1060 | 1060 | } |