@@ -77,13 +77,13 @@ discard block |
||
77 | 77 | * @return array |
78 | 78 | */ |
79 | 79 | function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
80 | - $invoice_statuses = array( |
|
81 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
80 | + $invoice_statuses = array( |
|
81 | + 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
82 | 82 | 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
83 | 83 | 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
84 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
85 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
86 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
84 | + 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
85 | + 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
86 | + 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
87 | 87 | 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
88 | 88 | 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
89 | 89 | ); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
97 | 97 | } |
98 | 98 | |
99 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
99 | + return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | function wpinv_status_nicename( $status ) { |
@@ -208,25 +208,25 @@ discard block |
||
208 | 208 | * @return string |
209 | 209 | */ |
210 | 210 | function getpaid_get_price_format() { |
211 | - $currency_pos = wpinv_currency_position(); |
|
212 | - $format = '%1$s%2$s'; |
|
211 | + $currency_pos = wpinv_currency_position(); |
|
212 | + $format = '%1$s%2$s'; |
|
213 | 213 | |
214 | - switch ( $currency_pos ) { |
|
215 | - case 'left': |
|
216 | - $format = '%1$s%2$s'; |
|
217 | - break; |
|
218 | - case 'right': |
|
219 | - $format = '%2$s%1$s'; |
|
220 | - break; |
|
221 | - case 'left_space': |
|
222 | - $format = '%1$s %2$s'; |
|
223 | - break; |
|
224 | - case 'right_space': |
|
225 | - $format = '%2$s %1$s'; |
|
226 | - break; |
|
227 | - } |
|
214 | + switch ( $currency_pos ) { |
|
215 | + case 'left': |
|
216 | + $format = '%1$s%2$s'; |
|
217 | + break; |
|
218 | + case 'right': |
|
219 | + $format = '%2$s%1$s'; |
|
220 | + break; |
|
221 | + case 'left_space': |
|
222 | + $format = '%1$s %2$s'; |
|
223 | + break; |
|
224 | + case 'right_space': |
|
225 | + $format = '%2$s %1$s'; |
|
226 | + break; |
|
227 | + } |
|
228 | 228 | |
229 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
229 | + return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -329,13 +329,13 @@ discard block |
||
329 | 329 | * @param mixed $value Value. |
330 | 330 | */ |
331 | 331 | function getpaid_maybe_define_constant( $name, $value ) { |
332 | - if ( ! defined( $name ) ) { |
|
333 | - define( $name, $value ); |
|
334 | - } |
|
332 | + if ( ! defined( $name ) ) { |
|
333 | + define( $name, $value ); |
|
334 | + } |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | function wpinv_get_php_arg_separator_output() { |
338 | - return ini_get( 'arg_separator.output' ); |
|
338 | + return ini_get( 'arg_separator.output' ); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | function wpinv_rgb_from_hex( $color ) { |
@@ -684,11 +684,11 @@ discard block |
||
684 | 684 | $list = array(); |
685 | 685 | } |
686 | 686 | |
687 | - if ( ! is_array( $list ) ) { |
|
688 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
689 | - } |
|
687 | + if ( ! is_array( $list ) ) { |
|
688 | + return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
689 | + } |
|
690 | 690 | |
691 | - return $list; |
|
691 | + return $list; |
|
692 | 692 | } |
693 | 693 | |
694 | 694 | /** |
@@ -708,9 +708,9 @@ discard block |
||
708 | 708 | } |
709 | 709 | |
710 | 710 | $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
711 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
711 | + wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
712 | 712 | |
713 | - return $data; |
|
713 | + return $data; |
|
714 | 714 | } |
715 | 715 | |
716 | 716 | /** |
@@ -739,17 +739,17 @@ discard block |
||
739 | 739 | */ |
740 | 740 | function wpinv_clean( $var ) { |
741 | 741 | |
742 | - if ( is_array( $var ) ) { |
|
743 | - return array_map( 'wpinv_clean', $var ); |
|
742 | + if ( is_array( $var ) ) { |
|
743 | + return array_map( 'wpinv_clean', $var ); |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | if ( is_object( $var ) ) { |
747 | - $object_vars = get_object_vars( $var ); |
|
748 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
749 | - $var->$property_name = wpinv_clean( $property_value ); |
|
747 | + $object_vars = get_object_vars( $var ); |
|
748 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
749 | + $var->$property_name = wpinv_clean( $property_value ); |
|
750 | 750 | } |
751 | 751 | return $var; |
752 | - } |
|
752 | + } |
|
753 | 753 | |
754 | 754 | return is_string( $var ) ? sanitize_text_field( $var ) : $var; |
755 | 755 | } |
@@ -762,7 +762,7 @@ discard block |
||
762 | 762 | */ |
763 | 763 | function getpaid_convert_price_string_to_options( $str ) { |
764 | 764 | |
765 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
765 | + $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
766 | 766 | $options = array(); |
767 | 767 | |
768 | 768 | foreach ( $raw_options as $option ) { |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | * @return string |
841 | 841 | */ |
842 | 842 | function getpaid_date_format() { |
843 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
843 | + return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | * @return string |
850 | 850 | */ |
851 | 851 | function getpaid_time_format() { |
852 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
852 | + return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
853 | 853 | } |
854 | 854 | |
855 | 855 | /** |
@@ -862,15 +862,15 @@ discard block |
||
862 | 862 | function getpaid_limit_length( $string, $limit ) { |
863 | 863 | $str_limit = $limit - 3; |
864 | 864 | |
865 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
866 | - if ( mb_strlen( $string ) > $limit ) { |
|
867 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
868 | - } |
|
869 | - } else { |
|
870 | - if ( strlen( $string ) > $limit ) { |
|
871 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
872 | - } |
|
873 | - } |
|
865 | + if ( function_exists( 'mb_strimwidth' ) ) { |
|
866 | + if ( mb_strlen( $string ) > $limit ) { |
|
867 | + $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
868 | + } |
|
869 | + } else { |
|
870 | + if ( strlen( $string ) > $limit ) { |
|
871 | + $string = substr( $string, 0, $str_limit ) . '...'; |
|
872 | + } |
|
873 | + } |
|
874 | 874 | return $string; |
875 | 875 | |
876 | 876 | } |
@@ -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? |
@@ -21,25 +21,25 @@ discard block |
||
21 | 21 | function wpinv_get_ip() { |
22 | 22 | $ip = $_SERVER['REMOTE_ADDR']; |
23 | 23 | |
24 | - if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
24 | + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
25 | 25 | //Check ip from share internet. |
26 | 26 | $ip = $_SERVER['HTTP_CLIENT_IP']; |
27 | - } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
27 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
28 | 28 | //Check ip is pass from proxy. |
29 | 29 | $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; |
30 | 30 | } |
31 | 31 | |
32 | - return apply_filters( 'wpinv_get_ip', $ip ); |
|
32 | + return apply_filters('wpinv_get_ip', $ip); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | function wpinv_get_user_agent() { |
36 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
37 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
36 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
37 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
38 | 38 | } else { |
39 | 39 | $user_agent = ''; |
40 | 40 | } |
41 | 41 | |
42 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
42 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -47,27 +47,27 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @param string $amount The amount to sanitize. |
49 | 49 | */ |
50 | -function wpinv_sanitize_amount( $amount ) { |
|
50 | +function wpinv_sanitize_amount($amount) { |
|
51 | 51 | |
52 | 52 | // Format decimals. |
53 | - $amount = str_replace( wpinv_decimal_separator(), '.', $amount ); |
|
53 | + $amount = str_replace(wpinv_decimal_separator(), '.', $amount); |
|
54 | 54 | |
55 | 55 | // Remove thousands. |
56 | - $amount = str_replace( wpinv_thousands_separator(), '', $amount ); |
|
56 | + $amount = str_replace(wpinv_thousands_separator(), '', $amount); |
|
57 | 57 | |
58 | 58 | // Cast the remaining to a float. |
59 | - return (float) preg_replace( '/[^0-9\.\-]/', '', $amount ); |
|
59 | + return (float) preg_replace('/[^0-9\.\-]/', '', $amount); |
|
60 | 60 | |
61 | 61 | } |
62 | 62 | |
63 | -function wpinv_round_amount( $amount, $decimals = NULL ) { |
|
64 | - if ( $decimals === NULL ) { |
|
63 | +function wpinv_round_amount($amount, $decimals = NULL) { |
|
64 | + if ($decimals === NULL) { |
|
65 | 65 | $decimals = wpinv_decimals(); |
66 | 66 | } |
67 | 67 | |
68 | - $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) ); |
|
68 | + $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals))); |
|
69 | 69 | |
70 | - return apply_filters( 'wpinv_round_amount', $amount, $decimals ); |
|
70 | + return apply_filters('wpinv_round_amount', $amount, $decimals); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -76,32 +76,32 @@ discard block |
||
76 | 76 | * @since 1.0.19 |
77 | 77 | * @return array |
78 | 78 | */ |
79 | -function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) { |
|
79 | +function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) { |
|
80 | 80 | $invoice_statuses = array( |
81 | - 'wpi-pending' => _x( 'Pending payment', 'Invoice status', 'invoicing' ), |
|
82 | - 'publish' => _x( 'Paid', 'Invoice status', 'invoicing' ), |
|
83 | - 'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ), |
|
84 | - 'wpi-onhold' => _x( 'On hold', 'Invoice status', 'invoicing' ), |
|
85 | - 'wpi-cancelled' => _x( 'Cancelled', 'Invoice status', 'invoicing' ), |
|
86 | - 'wpi-refunded' => _x( 'Refunded', 'Invoice status', 'invoicing' ), |
|
87 | - 'wpi-failed' => _x( 'Failed', 'Invoice status', 'invoicing' ), |
|
88 | - 'wpi-renewal' => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ), |
|
81 | + 'wpi-pending' => _x('Pending payment', 'Invoice status', 'invoicing'), |
|
82 | + 'publish' => _x('Paid', 'Invoice status', 'invoicing'), |
|
83 | + 'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'), |
|
84 | + 'wpi-onhold' => _x('On hold', 'Invoice status', 'invoicing'), |
|
85 | + 'wpi-cancelled' => _x('Cancelled', 'Invoice status', 'invoicing'), |
|
86 | + 'wpi-refunded' => _x('Refunded', 'Invoice status', 'invoicing'), |
|
87 | + 'wpi-failed' => _x('Failed', 'Invoice status', 'invoicing'), |
|
88 | + 'wpi-renewal' => _x('Renewal Payment', 'Invoice status', 'invoicing'), |
|
89 | 89 | ); |
90 | 90 | |
91 | - if ( $draft ) { |
|
92 | - $invoice_statuses['draft'] = __( 'Draft', 'invoicing' ); |
|
91 | + if ($draft) { |
|
92 | + $invoice_statuses['draft'] = __('Draft', 'invoicing'); |
|
93 | 93 | } |
94 | 94 | |
95 | - if ( $trashed ) { |
|
96 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
95 | + if ($trashed) { |
|
96 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
97 | 97 | } |
98 | 98 | |
99 | - return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice ); |
|
99 | + return apply_filters('wpinv_statuses', $invoice_statuses, $invoice); |
|
100 | 100 | } |
101 | 101 | |
102 | -function wpinv_status_nicename( $status ) { |
|
103 | - $statuses = wpinv_get_invoice_statuses( true, true ); |
|
104 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' ); |
|
102 | +function wpinv_status_nicename($status) { |
|
103 | + $statuses = wpinv_get_invoice_statuses(true, true); |
|
104 | + $status = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing'); |
|
105 | 105 | |
106 | 106 | return $status; |
107 | 107 | } |
@@ -111,13 +111,13 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @param string $current |
113 | 113 | */ |
114 | -function wpinv_get_currency( $current = '' ) { |
|
114 | +function wpinv_get_currency($current = '') { |
|
115 | 115 | |
116 | - if ( empty( $current ) ) { |
|
117 | - $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) ); |
|
116 | + if (empty($current)) { |
|
117 | + $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD')); |
|
118 | 118 | } |
119 | 119 | |
120 | - return trim( strtoupper( $current ) ); |
|
120 | + return trim(strtoupper($current)); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -125,25 +125,25 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @param string|null $currency The currency code. Defaults to the default currency. |
127 | 127 | */ |
128 | -function wpinv_currency_symbol( $currency = null ) { |
|
128 | +function wpinv_currency_symbol($currency = null) { |
|
129 | 129 | |
130 | 130 | // Prepare the currency. |
131 | - $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency ); |
|
131 | + $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency); |
|
132 | 132 | |
133 | 133 | // Fetch all symbols. |
134 | 134 | $symbols = wpinv_get_currency_symbols(); |
135 | 135 | |
136 | 136 | // Fetch this currencies symbol. |
137 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency; |
|
137 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency; |
|
138 | 138 | |
139 | 139 | // Filter the symbol. |
140 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
140 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | function wpinv_currency_position() { |
144 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
144 | + $position = wpinv_get_option('currency_position', 'left'); |
|
145 | 145 | |
146 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
146 | + return apply_filters('wpinv_currency_position', $position); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | * |
152 | 152 | * @param $string|null $current |
153 | 153 | */ |
154 | -function wpinv_thousands_separator( $current = null ) { |
|
154 | +function wpinv_thousands_separator($current = null) { |
|
155 | 155 | |
156 | - if ( null == $current ) { |
|
157 | - $current = wpinv_get_option( 'thousands_separator', '.' ); |
|
156 | + if (null == $current) { |
|
157 | + $current = wpinv_get_option('thousands_separator', '.'); |
|
158 | 158 | } |
159 | 159 | |
160 | - return trim( $current ); |
|
160 | + return trim($current); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -165,13 +165,13 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @param $string|null $current |
167 | 167 | */ |
168 | -function wpinv_decimal_separator( $current = null ) { |
|
168 | +function wpinv_decimal_separator($current = null) { |
|
169 | 169 | |
170 | - if ( null == $current ) { |
|
171 | - $current = wpinv_get_option( 'decimal_separator', '.' ); |
|
170 | + if (null == $current) { |
|
171 | + $current = wpinv_get_option('decimal_separator', '.'); |
|
172 | 172 | } |
173 | 173 | |
174 | - return trim( $current ); |
|
174 | + return trim($current); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -179,27 +179,27 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @param $string|null $current |
181 | 181 | */ |
182 | -function wpinv_decimals( $current = null ) { |
|
182 | +function wpinv_decimals($current = null) { |
|
183 | 183 | |
184 | - if ( null == $current ) { |
|
185 | - $current = wpinv_get_option( 'decimals', 2 ); |
|
184 | + if (null == $current) { |
|
185 | + $current = wpinv_get_option('decimals', 2); |
|
186 | 186 | } |
187 | 187 | |
188 | - return absint( $current ); |
|
188 | + return absint($current); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * Retrieves a list of all supported currencies. |
193 | 193 | */ |
194 | 194 | function wpinv_get_currencies() { |
195 | - return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) ); |
|
195 | + return apply_filters('wpinv_currencies', wpinv_get_data('currencies')); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
199 | 199 | * Retrieves a list of all currency symbols. |
200 | 200 | */ |
201 | 201 | function wpinv_get_currency_symbols() { |
202 | - return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) ); |
|
202 | + return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols')); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | $currency_pos = wpinv_currency_position(); |
212 | 212 | $format = '%1$s%2$s'; |
213 | 213 | |
214 | - switch ( $currency_pos ) { |
|
214 | + switch ($currency_pos) { |
|
215 | 215 | case 'left': |
216 | 216 | $format = '%1$s%2$s'; |
217 | 217 | break; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | break; |
227 | 227 | } |
228 | 228 | |
229 | - return apply_filters( 'getpaid_price_format', $format, $currency_pos ); |
|
229 | + return apply_filters('getpaid_price_format', $format, $currency_pos); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -236,25 +236,25 @@ discard block |
||
236 | 236 | * @param string $currency Currency. |
237 | 237 | * @return string |
238 | 238 | */ |
239 | -function wpinv_price( $amount = 0, $currency = '' ) { |
|
239 | +function wpinv_price($amount = 0, $currency = '') { |
|
240 | 240 | |
241 | 241 | // Backwards compatibility. |
242 | - $amount = floatval( wpinv_sanitize_amount( str_replace( wpinv_thousands_separator(), '', $amount ) ) ); |
|
242 | + $amount = floatval(wpinv_sanitize_amount(str_replace(wpinv_thousands_separator(), '', $amount))); |
|
243 | 243 | |
244 | 244 | // Prepare variables. |
245 | - $currency = wpinv_get_currency( $currency ); |
|
245 | + $currency = wpinv_get_currency($currency); |
|
246 | 246 | $amount = (float) $amount; |
247 | 247 | $unformatted_amount = $amount; |
248 | 248 | $negative = $amount < 0; |
249 | - $amount = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) ); |
|
250 | - $amount = wpinv_format_amount( $amount ); |
|
249 | + $amount = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount)); |
|
250 | + $amount = wpinv_format_amount($amount); |
|
251 | 251 | |
252 | 252 | // Format the amount. |
253 | 253 | $format = getpaid_get_price_format(); |
254 | - $formatted_amount = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount ); |
|
254 | + $formatted_amount = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount); |
|
255 | 255 | |
256 | 256 | // Filter the formatting. |
257 | - return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount ); |
|
257 | + return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -265,33 +265,33 @@ discard block |
||
265 | 265 | * @param bool $calculate Whether or not to apply separators. |
266 | 266 | * @return string |
267 | 267 | */ |
268 | -function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) { |
|
268 | +function wpinv_format_amount($amount, $decimals = null, $calculate = false) { |
|
269 | 269 | $thousands_sep = wpinv_thousands_separator(); |
270 | 270 | $decimal_sep = wpinv_decimal_separator(); |
271 | - $decimals = wpinv_decimals( $decimals ); |
|
271 | + $decimals = wpinv_decimals($decimals); |
|
272 | 272 | |
273 | 273 | // Format decimals. |
274 | - $amount = str_replace( $decimal_sep, '.', $amount ); |
|
274 | + $amount = str_replace($decimal_sep, '.', $amount); |
|
275 | 275 | |
276 | 276 | // Remove thousands. |
277 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
277 | + $amount = str_replace($thousands_sep, '', $amount); |
|
278 | 278 | |
279 | 279 | // Cast the remaining to a float. |
280 | - $amount = floatval( $amount ); |
|
280 | + $amount = floatval($amount); |
|
281 | 281 | |
282 | - if ( $calculate ) { |
|
282 | + if ($calculate) { |
|
283 | 283 | return $amount; |
284 | 284 | } |
285 | 285 | |
286 | 286 | // Fomart the amount. |
287 | - return number_format( $amount, $decimals, $decimal_sep, $thousands_sep ); |
|
287 | + return number_format($amount, $decimals, $decimal_sep, $thousands_sep); |
|
288 | 288 | } |
289 | 289 | |
290 | -function wpinv_sanitize_key( $key ) { |
|
290 | +function wpinv_sanitize_key($key) { |
|
291 | 291 | $raw_key = $key; |
292 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
292 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
293 | 293 | |
294 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
294 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @param $str the file whose extension should be retrieved. |
301 | 301 | */ |
302 | -function wpinv_get_file_extension( $str ) { |
|
303 | - $filetype = wp_check_filetype( $str ); |
|
302 | +function wpinv_get_file_extension($str) { |
|
303 | + $filetype = wp_check_filetype($str); |
|
304 | 304 | return $filetype['ext']; |
305 | 305 | } |
306 | 306 | |
@@ -309,16 +309,16 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @param string $string |
311 | 311 | */ |
312 | -function wpinv_string_is_image_url( $string ) { |
|
313 | - $extension = strtolower( wpinv_get_file_extension( $string ) ); |
|
314 | - return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true ); |
|
312 | +function wpinv_string_is_image_url($string) { |
|
313 | + $extension = strtolower(wpinv_get_file_extension($string)); |
|
314 | + return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | /** |
318 | 318 | * Returns the current URL. |
319 | 319 | */ |
320 | 320 | function wpinv_get_current_page_url() { |
321 | - return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
321 | + return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -328,46 +328,46 @@ discard block |
||
328 | 328 | * @param string $name Constant name. |
329 | 329 | * @param mixed $value Value. |
330 | 330 | */ |
331 | -function getpaid_maybe_define_constant( $name, $value ) { |
|
332 | - if ( ! defined( $name ) ) { |
|
333 | - define( $name, $value ); |
|
331 | +function getpaid_maybe_define_constant($name, $value) { |
|
332 | + if (!defined($name)) { |
|
333 | + define($name, $value); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
337 | 337 | function wpinv_get_php_arg_separator_output() { |
338 | - return ini_get( 'arg_separator.output' ); |
|
338 | + return ini_get('arg_separator.output'); |
|
339 | 339 | } |
340 | 340 | |
341 | -function wpinv_rgb_from_hex( $color ) { |
|
342 | - $color = str_replace( '#', '', $color ); |
|
341 | +function wpinv_rgb_from_hex($color) { |
|
342 | + $color = str_replace('#', '', $color); |
|
343 | 343 | |
344 | 344 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
345 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
346 | - if ( empty( $color ) ) { |
|
345 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
346 | + if (empty($color)) { |
|
347 | 347 | return NULL; |
348 | 348 | } |
349 | 349 | |
350 | - $color = str_split( $color ); |
|
350 | + $color = str_split($color); |
|
351 | 351 | |
352 | 352 | $rgb = array(); |
353 | - $rgb['R'] = hexdec( $color[0] . $color[1] ); |
|
354 | - $rgb['G'] = hexdec( $color[2] . $color[3] ); |
|
355 | - $rgb['B'] = hexdec( $color[4] . $color[5] ); |
|
353 | + $rgb['R'] = hexdec($color[0] . $color[1]); |
|
354 | + $rgb['G'] = hexdec($color[2] . $color[3]); |
|
355 | + $rgb['B'] = hexdec($color[4] . $color[5]); |
|
356 | 356 | |
357 | 357 | return $rgb; |
358 | 358 | } |
359 | 359 | |
360 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
361 | - $base = wpinv_rgb_from_hex( $color ); |
|
360 | +function wpinv_hex_darker($color, $factor = 30) { |
|
361 | + $base = wpinv_rgb_from_hex($color); |
|
362 | 362 | $color = '#'; |
363 | 363 | |
364 | - foreach ( $base as $k => $v ) { |
|
364 | + foreach ($base as $k => $v) { |
|
365 | 365 | $amount = $v / 100; |
366 | - $amount = round( $amount * $factor ); |
|
366 | + $amount = round($amount * $factor); |
|
367 | 367 | $new_decimal = $v - $amount; |
368 | 368 | |
369 | - $new_hex_component = dechex( $new_decimal ); |
|
370 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
369 | + $new_hex_component = dechex($new_decimal); |
|
370 | + if (strlen($new_hex_component) < 2) { |
|
371 | 371 | $new_hex_component = "0" . $new_hex_component; |
372 | 372 | } |
373 | 373 | $color .= $new_hex_component; |
@@ -376,18 +376,18 @@ discard block |
||
376 | 376 | return $color; |
377 | 377 | } |
378 | 378 | |
379 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
380 | - $base = wpinv_rgb_from_hex( $color ); |
|
379 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
380 | + $base = wpinv_rgb_from_hex($color); |
|
381 | 381 | $color = '#'; |
382 | 382 | |
383 | - foreach ( $base as $k => $v ) { |
|
383 | + foreach ($base as $k => $v) { |
|
384 | 384 | $amount = 255 - $v; |
385 | 385 | $amount = $amount / 100; |
386 | - $amount = round( $amount * $factor ); |
|
386 | + $amount = round($amount * $factor); |
|
387 | 387 | $new_decimal = $v + $amount; |
388 | 388 | |
389 | - $new_hex_component = dechex( $new_decimal ); |
|
390 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
389 | + $new_hex_component = dechex($new_decimal); |
|
390 | + if (strlen($new_hex_component) < 2) { |
|
391 | 391 | $new_hex_component = "0" . $new_hex_component; |
392 | 392 | } |
393 | 393 | $color .= $new_hex_component; |
@@ -396,22 +396,22 @@ discard block |
||
396 | 396 | return $color; |
397 | 397 | } |
398 | 398 | |
399 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
400 | - $hex = str_replace( '#', '', $color ); |
|
399 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
400 | + $hex = str_replace('#', '', $color); |
|
401 | 401 | |
402 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
403 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
404 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
402 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
403 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
404 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
405 | 405 | |
406 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
406 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
407 | 407 | |
408 | 408 | return $brightness > 155 ? $dark : $light; |
409 | 409 | } |
410 | 410 | |
411 | -function wpinv_format_hex( $hex ) { |
|
412 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
411 | +function wpinv_format_hex($hex) { |
|
412 | + $hex = trim(str_replace('#', '', $hex)); |
|
413 | 413 | |
414 | - if ( strlen( $hex ) == 3 ) { |
|
414 | + if (strlen($hex) == 3) { |
|
415 | 415 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
416 | 416 | } |
417 | 417 | |
@@ -431,12 +431,12 @@ discard block |
||
431 | 431 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
432 | 432 | * @return string |
433 | 433 | */ |
434 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
435 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
436 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
434 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
435 | + if (function_exists('mb_strimwidth')) { |
|
436 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
437 | 437 | } |
438 | 438 | |
439 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
439 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | /** |
@@ -448,28 +448,28 @@ discard block |
||
448 | 448 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
449 | 449 | * @return int Returns the number of characters in string. |
450 | 450 | */ |
451 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
452 | - if ( function_exists( 'mb_strlen' ) ) { |
|
453 | - return mb_strlen( $str, $encoding ); |
|
451 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
452 | + if (function_exists('mb_strlen')) { |
|
453 | + return mb_strlen($str, $encoding); |
|
454 | 454 | } |
455 | 455 | |
456 | - return strlen( $str ); |
|
456 | + return strlen($str); |
|
457 | 457 | } |
458 | 458 | |
459 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
460 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
461 | - return mb_strtolower( $str, $encoding ); |
|
459 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
460 | + if (function_exists('mb_strtolower')) { |
|
461 | + return mb_strtolower($str, $encoding); |
|
462 | 462 | } |
463 | 463 | |
464 | - return strtolower( $str ); |
|
464 | + return strtolower($str); |
|
465 | 465 | } |
466 | 466 | |
467 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
468 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
469 | - return mb_strtoupper( $str, $encoding ); |
|
467 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
468 | + if (function_exists('mb_strtoupper')) { |
|
469 | + return mb_strtoupper($str, $encoding); |
|
470 | 470 | } |
471 | 471 | |
472 | - return strtoupper( $str ); |
|
472 | + return strtoupper($str); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
@@ -483,12 +483,12 @@ discard block |
||
483 | 483 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
484 | 484 | * @return int Returns the position of the first occurrence of search in the string. |
485 | 485 | */ |
486 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
487 | - if ( function_exists( 'mb_strpos' ) ) { |
|
488 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
486 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
487 | + if (function_exists('mb_strpos')) { |
|
488 | + return mb_strpos($str, $find, $offset, $encoding); |
|
489 | 489 | } |
490 | 490 | |
491 | - return strpos( $str, $find, $offset ); |
|
491 | + return strpos($str, $find, $offset); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | /** |
@@ -502,12 +502,12 @@ discard block |
||
502 | 502 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
503 | 503 | * @return int Returns the position of the last occurrence of search. |
504 | 504 | */ |
505 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
506 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
507 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
505 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
506 | + if (function_exists('mb_strrpos')) { |
|
507 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
508 | 508 | } |
509 | 509 | |
510 | - return strrpos( $str, $find, $offset ); |
|
510 | + return strrpos($str, $find, $offset); |
|
511 | 511 | } |
512 | 512 | |
513 | 513 | /** |
@@ -522,16 +522,16 @@ discard block |
||
522 | 522 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
523 | 523 | * @return string |
524 | 524 | */ |
525 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
526 | - if ( function_exists( 'mb_substr' ) ) { |
|
527 | - if ( $length === null ) { |
|
528 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
525 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
526 | + if (function_exists('mb_substr')) { |
|
527 | + if ($length === null) { |
|
528 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
529 | 529 | } else { |
530 | - return mb_substr( $str, $start, $length, $encoding ); |
|
530 | + return mb_substr($str, $start, $length, $encoding); |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
534 | - return substr( $str, $start, $length ); |
|
534 | + return substr($str, $start, $length); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | /** |
@@ -543,48 +543,48 @@ discard block |
||
543 | 543 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
544 | 544 | * @return string The width of string. |
545 | 545 | */ |
546 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
547 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
548 | - return mb_strwidth( $str, $encoding ); |
|
546 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
547 | + if (function_exists('mb_strwidth')) { |
|
548 | + return mb_strwidth($str, $encoding); |
|
549 | 549 | } |
550 | 550 | |
551 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
551 | + return wpinv_utf8_strlen($str, $encoding); |
|
552 | 552 | } |
553 | 553 | |
554 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
555 | - if ( function_exists( 'mb_strlen' ) ) { |
|
556 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
554 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
555 | + if (function_exists('mb_strlen')) { |
|
556 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
557 | 557 | $str_end = ""; |
558 | 558 | |
559 | - if ( $lower_str_end ) { |
|
560 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
559 | + if ($lower_str_end) { |
|
560 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
561 | 561 | } else { |
562 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
562 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | return $first_letter . $str_end; |
566 | 566 | } |
567 | 567 | |
568 | - return ucfirst( $str ); |
|
568 | + return ucfirst($str); |
|
569 | 569 | } |
570 | 570 | |
571 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
572 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
573 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
571 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
572 | + if (function_exists('mb_convert_case')) { |
|
573 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
574 | 574 | } |
575 | 575 | |
576 | - return ucwords( $str ); |
|
576 | + return ucwords($str); |
|
577 | 577 | } |
578 | 578 | |
579 | -function wpinv_period_in_days( $period, $unit ) { |
|
580 | - $period = absint( $period ); |
|
579 | +function wpinv_period_in_days($period, $unit) { |
|
580 | + $period = absint($period); |
|
581 | 581 | |
582 | - if ( $period > 0 ) { |
|
583 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
582 | + if ($period > 0) { |
|
583 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
584 | 584 | $period = $period * 7; |
585 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
585 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
586 | 586 | $period = $period * 30; |
587 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
587 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
588 | 588 | $period = $period * 365; |
589 | 589 | } |
590 | 590 | } |
@@ -592,14 +592,14 @@ discard block |
||
592 | 592 | return $period; |
593 | 593 | } |
594 | 594 | |
595 | -function wpinv_cal_days_in_month( $calendar, $month, $year ) { |
|
596 | - if ( function_exists( 'cal_days_in_month' ) ) { |
|
597 | - return cal_days_in_month( $calendar, $month, $year ); |
|
595 | +function wpinv_cal_days_in_month($calendar, $month, $year) { |
|
596 | + if (function_exists('cal_days_in_month')) { |
|
597 | + return cal_days_in_month($calendar, $month, $year); |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | // Fallback in case the calendar extension is not loaded in PHP |
601 | 601 | // Only supports Gregorian calendar |
602 | - return date( 't', mktime( 0, 0, 0, $month, 1, $year ) ); |
|
602 | + return date('t', mktime(0, 0, 0, $month, 1, $year)); |
|
603 | 603 | } |
604 | 604 | |
605 | 605 | /** |
@@ -610,11 +610,11 @@ discard block |
||
610 | 610 | * |
611 | 611 | * @return string |
612 | 612 | */ |
613 | -function wpi_help_tip( $tip, $allow_html = false ) { |
|
614 | - if ( $allow_html ) { |
|
615 | - $tip = wpi_sanitize_tooltip( $tip ); |
|
613 | +function wpi_help_tip($tip, $allow_html = false) { |
|
614 | + if ($allow_html) { |
|
615 | + $tip = wpi_sanitize_tooltip($tip); |
|
616 | 616 | } else { |
617 | - $tip = esc_attr( $tip ); |
|
617 | + $tip = esc_attr($tip); |
|
618 | 618 | } |
619 | 619 | |
620 | 620 | return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
@@ -628,8 +628,8 @@ discard block |
||
628 | 628 | * @param string $var |
629 | 629 | * @return string |
630 | 630 | */ |
631 | -function wpi_sanitize_tooltip( $var ) { |
|
632 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
631 | +function wpi_sanitize_tooltip($var) { |
|
632 | + return htmlspecialchars(wp_kses(html_entity_decode($var), array( |
|
633 | 633 | 'br' => array(), |
634 | 634 | 'em' => array(), |
635 | 635 | 'strong' => array(), |
@@ -639,7 +639,7 @@ discard block |
||
639 | 639 | 'li' => array(), |
640 | 640 | 'ol' => array(), |
641 | 641 | 'p' => array(), |
642 | - ) ) ); |
|
642 | + ))); |
|
643 | 643 | } |
644 | 644 | |
645 | 645 | /** |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | */ |
650 | 650 | function wpinv_get_screen_ids() { |
651 | 651 | |
652 | - $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) ); |
|
652 | + $screen_id = sanitize_title(__('Invoicing', 'invoicing')); |
|
653 | 653 | |
654 | 654 | $screen_ids = array( |
655 | 655 | 'toplevel_page_' . $screen_id, |
@@ -667,7 +667,7 @@ discard block |
||
667 | 667 | 'invoicing_page_wpi-addons', |
668 | 668 | ); |
669 | 669 | |
670 | - return apply_filters( 'wpinv_screen_ids', $screen_ids ); |
|
670 | + return apply_filters('wpinv_screen_ids', $screen_ids); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
@@ -678,14 +678,14 @@ discard block |
||
678 | 678 | * @param array|string $list List of values. |
679 | 679 | * @return array Sanitized array of values. |
680 | 680 | */ |
681 | -function wpinv_parse_list( $list ) { |
|
681 | +function wpinv_parse_list($list) { |
|
682 | 682 | |
683 | - if ( empty( $list ) ) { |
|
683 | + if (empty($list)) { |
|
684 | 684 | $list = array(); |
685 | 685 | } |
686 | 686 | |
687 | - if ( ! is_array( $list ) ) { |
|
688 | - return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY ); |
|
687 | + if (!is_array($list)) { |
|
688 | + return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | return $list; |
@@ -699,16 +699,16 @@ discard block |
||
699 | 699 | * @param string $key Type of data to fetch. |
700 | 700 | * @return mixed Fetched data. |
701 | 701 | */ |
702 | -function wpinv_get_data( $key ) { |
|
702 | +function wpinv_get_data($key) { |
|
703 | 703 | |
704 | 704 | // Try fetching it from the cache. |
705 | - $data = wp_cache_get( "wpinv-data-$key", 'wpinv' ); |
|
706 | - if( $data ) { |
|
705 | + $data = wp_cache_get("wpinv-data-$key", 'wpinv'); |
|
706 | + if ($data) { |
|
707 | 707 | return $data; |
708 | 708 | } |
709 | 709 | |
710 | - $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" ); |
|
711 | - wp_cache_set( "wpinv-data-$key", $data, 'wpinv' ); |
|
710 | + $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php"); |
|
711 | + wp_cache_set("wpinv-data-$key", $data, 'wpinv'); |
|
712 | 712 | |
713 | 713 | return $data; |
714 | 714 | } |
@@ -722,10 +722,10 @@ discard block |
||
722 | 722 | * @param bool $first_empty Whether or not the first item in the list should be empty |
723 | 723 | * @return mixed Fetched data. |
724 | 724 | */ |
725 | -function wpinv_maybe_add_empty_option( $options, $first_empty ) { |
|
725 | +function wpinv_maybe_add_empty_option($options, $first_empty) { |
|
726 | 726 | |
727 | - if ( ! empty( $options ) && $first_empty ) { |
|
728 | - return array_merge( array( '' => '' ), $options ); |
|
727 | + if (!empty($options) && $first_empty) { |
|
728 | + return array_merge(array('' => ''), $options); |
|
729 | 729 | } |
730 | 730 | return $options; |
731 | 731 | |
@@ -737,21 +737,21 @@ discard block |
||
737 | 737 | * @param mixed $var Data to sanitize. |
738 | 738 | * @return string|array |
739 | 739 | */ |
740 | -function wpinv_clean( $var ) { |
|
740 | +function wpinv_clean($var) { |
|
741 | 741 | |
742 | - if ( is_array( $var ) ) { |
|
743 | - return array_map( 'wpinv_clean', $var ); |
|
742 | + if (is_array($var)) { |
|
743 | + return array_map('wpinv_clean', $var); |
|
744 | 744 | } |
745 | 745 | |
746 | - if ( is_object( $var ) ) { |
|
747 | - $object_vars = get_object_vars( $var ); |
|
748 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
749 | - $var->$property_name = wpinv_clean( $property_value ); |
|
746 | + if (is_object($var)) { |
|
747 | + $object_vars = get_object_vars($var); |
|
748 | + foreach ($object_vars as $property_name => $property_value) { |
|
749 | + $var->$property_name = wpinv_clean($property_value); |
|
750 | 750 | } |
751 | 751 | return $var; |
752 | 752 | } |
753 | 753 | |
754 | - return is_string( $var ) ? sanitize_text_field( $var ) : $var; |
|
754 | + return is_string($var) ? sanitize_text_field($var) : $var; |
|
755 | 755 | } |
756 | 756 | |
757 | 757 | /** |
@@ -760,43 +760,43 @@ discard block |
||
760 | 760 | * @param string $str Data to convert. |
761 | 761 | * @return string|array |
762 | 762 | */ |
763 | -function getpaid_convert_price_string_to_options( $str ) { |
|
763 | +function getpaid_convert_price_string_to_options($str) { |
|
764 | 764 | |
765 | - $raw_options = array_map( 'trim', explode( ',', $str ) ); |
|
766 | - $options = array(); |
|
765 | + $raw_options = array_map('trim', explode(',', $str)); |
|
766 | + $options = array(); |
|
767 | 767 | |
768 | - foreach ( $raw_options as $option ) { |
|
768 | + foreach ($raw_options as $option) { |
|
769 | 769 | |
770 | - if ( '' == $option ) { |
|
770 | + if ('' == $option) { |
|
771 | 771 | continue; |
772 | 772 | } |
773 | 773 | |
774 | - $option = array_map( 'trim', explode( '|', $option ) ); |
|
774 | + $option = array_map('trim', explode('|', $option)); |
|
775 | 775 | |
776 | 776 | $price = null; |
777 | 777 | $label = null; |
778 | 778 | |
779 | - if ( isset( $option[0] ) && '' != $option[0] ) { |
|
780 | - $label = $option[0]; |
|
779 | + if (isset($option[0]) && '' != $option[0]) { |
|
780 | + $label = $option[0]; |
|
781 | 781 | } |
782 | 782 | |
783 | - if ( isset( $option[1] ) && '' != $option[1] ) { |
|
783 | + if (isset($option[1]) && '' != $option[1]) { |
|
784 | 784 | $price = $option[1]; |
785 | 785 | } |
786 | 786 | |
787 | - if ( ! isset( $price ) ) { |
|
787 | + if (!isset($price)) { |
|
788 | 788 | $price = $label; |
789 | 789 | } |
790 | 790 | |
791 | - if ( ! isset( $price ) || ! is_numeric( $price ) ) { |
|
791 | + if (!isset($price) || !is_numeric($price)) { |
|
792 | 792 | continue; |
793 | 793 | } |
794 | 794 | |
795 | - if ( ! isset( $label ) ) { |
|
795 | + if (!isset($label)) { |
|
796 | 796 | $label = $price; |
797 | 797 | } |
798 | 798 | |
799 | - $options[ $price ] = $label; |
|
799 | + $options[$price] = $label; |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | return $options; |
@@ -805,22 +805,22 @@ discard block |
||
805 | 805 | /** |
806 | 806 | * Returns the help tip. |
807 | 807 | */ |
808 | -function getpaid_get_help_tip( $tip, $additional_classes = '' ) { |
|
809 | - $additional_classes = sanitize_html_class( $additional_classes ); |
|
810 | - $tip = esc_attr__( $tip ); |
|
808 | +function getpaid_get_help_tip($tip, $additional_classes = '') { |
|
809 | + $additional_classes = sanitize_html_class($additional_classes); |
|
810 | + $tip = esc_attr__($tip); |
|
811 | 811 | return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>"; |
812 | 812 | } |
813 | 813 | |
814 | 814 | /** |
815 | 815 | * Formats a date |
816 | 816 | */ |
817 | -function getpaid_format_date( $date ) { |
|
817 | +function getpaid_format_date($date) { |
|
818 | 818 | |
819 | - if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) { |
|
819 | + if (empty($date) || $date == '0000-00-00 00:00:00') { |
|
820 | 820 | return ''; |
821 | 821 | } |
822 | 822 | |
823 | - return date_i18n( getpaid_date_format(), strtotime( $date ) ); |
|
823 | + return date_i18n(getpaid_date_format(), strtotime($date)); |
|
824 | 824 | |
825 | 825 | } |
826 | 826 | |
@@ -829,9 +829,9 @@ discard block |
||
829 | 829 | * |
830 | 830 | * @return string |
831 | 831 | */ |
832 | -function getpaid_format_date_value( $date, $default = "—" ) { |
|
833 | - $date = getpaid_format_date( $date ); |
|
834 | - return empty( $date ) ? $default : $date; |
|
832 | +function getpaid_format_date_value($date, $default = "—") { |
|
833 | + $date = getpaid_format_date($date); |
|
834 | + return empty($date) ? $default : $date; |
|
835 | 835 | } |
836 | 836 | |
837 | 837 | /** |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | * @return string |
841 | 841 | */ |
842 | 842 | function getpaid_date_format() { |
843 | - return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) ); |
|
843 | + return apply_filters('getpaid_date_format', get_option('date_format')); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | /** |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | * @return string |
850 | 850 | */ |
851 | 851 | function getpaid_time_format() { |
852 | - return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) ); |
|
852 | + return apply_filters('getpaid_time_format', get_option('time_format')); |
|
853 | 853 | } |
854 | 854 | |
855 | 855 | /** |
@@ -859,16 +859,16 @@ discard block |
||
859 | 859 | * @param integer $limit Limit size in characters. |
860 | 860 | * @return string |
861 | 861 | */ |
862 | -function getpaid_limit_length( $string, $limit ) { |
|
862 | +function getpaid_limit_length($string, $limit) { |
|
863 | 863 | $str_limit = $limit - 3; |
864 | 864 | |
865 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
866 | - if ( mb_strlen( $string ) > $limit ) { |
|
867 | - $string = mb_strimwidth( $string, 0, $str_limit ) . '...'; |
|
865 | + if (function_exists('mb_strimwidth')) { |
|
866 | + if (mb_strlen($string) > $limit) { |
|
867 | + $string = mb_strimwidth($string, 0, $str_limit) . '...'; |
|
868 | 868 | } |
869 | 869 | } else { |
870 | - if ( strlen( $string ) > $limit ) { |
|
871 | - $string = substr( $string, 0, $str_limit ) . '...'; |
|
870 | + if (strlen($string) > $limit) { |
|
871 | + $string = substr($string, 0, $str_limit) . '...'; |
|
872 | 872 | } |
873 | 873 | } |
874 | 874 | return $string; |
@@ -882,7 +882,7 @@ discard block |
||
882 | 882 | * @since 1.0.19 |
883 | 883 | */ |
884 | 884 | function getpaid_api() { |
885 | - return getpaid()->get( 'api' ); |
|
885 | + return getpaid()->get('api'); |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | /** |
@@ -892,7 +892,7 @@ discard block |
||
892 | 892 | * @since 1.0.19 |
893 | 893 | */ |
894 | 894 | function getpaid_post_types() { |
895 | - return getpaid()->get( 'post_types' ); |
|
895 | + return getpaid()->get('post_types'); |
|
896 | 896 | } |
897 | 897 | |
898 | 898 | /** |
@@ -902,7 +902,7 @@ discard block |
||
902 | 902 | * @since 1.0.19 |
903 | 903 | */ |
904 | 904 | function getpaid_session() { |
905 | - return getpaid()->get( 'session' ); |
|
905 | + return getpaid()->get('session'); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | /** |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | * @since 1.0.19 |
913 | 913 | */ |
914 | 914 | function getpaid_notes() { |
915 | - return getpaid()->get( 'notes' ); |
|
915 | + return getpaid()->get('notes'); |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | /** |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | * @return GetPaid_Admin |
922 | 922 | */ |
923 | 923 | function getpaid_admin() { |
924 | - return getpaid()->get( 'admin' ); |
|
924 | + return getpaid()->get('admin'); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
@@ -931,6 +931,6 @@ discard block |
||
931 | 931 | * @param string $base the base url |
932 | 932 | * @return string |
933 | 933 | */ |
934 | -function getpaid_get_authenticated_action_url( $action, $base = false ) { |
|
935 | - return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' ); |
|
934 | +function getpaid_get_authenticated_action_url($action, $base = false) { |
|
935 | + return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce'); |
|
936 | 936 | } |
@@ -12,93 +12,93 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Daily_Maintenance { |
14 | 14 | |
15 | - /** |
|
16 | - * Class constructor. |
|
17 | - */ |
|
18 | - public function __construct(){ |
|
19 | - |
|
20 | - // Clear deprecated events. |
|
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | - |
|
23 | - // (Maybe) schedule a cron that runs daily. |
|
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | - |
|
26 | - // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | - |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Schedules a cron to run every day at 7 a.m |
|
35 | - * |
|
36 | - */ |
|
37 | - public function maybe_create_scheduled_event() { |
|
38 | - |
|
39 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
40 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
41 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
42 | - } |
|
43 | - |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Clears deprecated events. |
|
48 | - * |
|
49 | - */ |
|
50 | - public function maybe_clear_deprecated_events() { |
|
51 | - |
|
52 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
53 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
55 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
56 | - } |
|
57 | - |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Fires the old hook for backwards compatibility. |
|
62 | - * |
|
63 | - */ |
|
64 | - public function backwards_compat() { |
|
65 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Expires expired subscriptions. |
|
70 | - * |
|
71 | - */ |
|
72 | - public function maybe_expire_subscriptions() { |
|
73 | - |
|
74 | - // Fetch expired subscriptions (skips those that expire today). |
|
75 | - $args = array( |
|
76 | - 'number' => -1, |
|
77 | - 'count_total' => false, |
|
78 | - 'status' => 'trialling active failing cancelled', |
|
79 | - 'date_expires_query' => array( |
|
80 | - 'before' => 'today', |
|
81 | - 'inclusive' => false, |
|
82 | - ), |
|
83 | - ); |
|
84 | - |
|
85 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
86 | - |
|
87 | - foreach ( $subscriptions as $subscription ) { |
|
88 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
89 | - $subscription->set_status( 'expired' ); |
|
90 | - $subscription->save(); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Logs cron runs. |
|
98 | - * |
|
99 | - */ |
|
100 | - public function log_cron_run() { |
|
101 | - wpinv_error_log( "GetPaid Daily Cron" ); |
|
102 | - } |
|
15 | + /** |
|
16 | + * Class constructor. |
|
17 | + */ |
|
18 | + public function __construct(){ |
|
19 | + |
|
20 | + // Clear deprecated events. |
|
21 | + add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
22 | + |
|
23 | + // (Maybe) schedule a cron that runs daily. |
|
24 | + add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
25 | + |
|
26 | + // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
|
27 | + add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | + add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | + add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
30 | + |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Schedules a cron to run every day at 7 a.m |
|
35 | + * |
|
36 | + */ |
|
37 | + public function maybe_create_scheduled_event() { |
|
38 | + |
|
39 | + if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
40 | + $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
41 | + wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
42 | + } |
|
43 | + |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Clears deprecated events. |
|
48 | + * |
|
49 | + */ |
|
50 | + public function maybe_clear_deprecated_events() { |
|
51 | + |
|
52 | + if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
53 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
54 | + wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
55 | + update_option( 'wpinv_cleared_old_events', 1 ); |
|
56 | + } |
|
57 | + |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Fires the old hook for backwards compatibility. |
|
62 | + * |
|
63 | + */ |
|
64 | + public function backwards_compat() { |
|
65 | + do_action( 'wpinv_register_schedule_event_daily' ); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Expires expired subscriptions. |
|
70 | + * |
|
71 | + */ |
|
72 | + public function maybe_expire_subscriptions() { |
|
73 | + |
|
74 | + // Fetch expired subscriptions (skips those that expire today). |
|
75 | + $args = array( |
|
76 | + 'number' => -1, |
|
77 | + 'count_total' => false, |
|
78 | + 'status' => 'trialling active failing cancelled', |
|
79 | + 'date_expires_query' => array( |
|
80 | + 'before' => 'today', |
|
81 | + 'inclusive' => false, |
|
82 | + ), |
|
83 | + ); |
|
84 | + |
|
85 | + $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
86 | + |
|
87 | + foreach ( $subscriptions as $subscription ) { |
|
88 | + if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
89 | + $subscription->set_status( 'expired' ); |
|
90 | + $subscription->save(); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Logs cron runs. |
|
98 | + * |
|
99 | + */ |
|
100 | + public function log_cron_run() { |
|
101 | + wpinv_error_log( "GetPaid Daily Cron" ); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Daily maintenance class. |
@@ -15,18 +15,18 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * Class constructor. |
17 | 17 | */ |
18 | - public function __construct(){ |
|
18 | + public function __construct() { |
|
19 | 19 | |
20 | 20 | // Clear deprecated events. |
21 | - add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) ); |
|
21 | + add_action('wp', array($this, 'maybe_clear_deprecated_events')); |
|
22 | 22 | |
23 | 23 | // (Maybe) schedule a cron that runs daily. |
24 | - add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) ); |
|
24 | + add_action('wp', array($this, 'maybe_create_scheduled_event')); |
|
25 | 25 | |
26 | 26 | // Fired everyday at 7 a.m (this might vary for sites with few visitors) |
27 | - add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) ); |
|
28 | - add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) ); |
|
29 | - add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) ); |
|
27 | + add_action('getpaid_daily_maintenance', array($this, 'log_cron_run')); |
|
28 | + add_action('getpaid_daily_maintenance', array($this, 'backwards_compat')); |
|
29 | + add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions')); |
|
30 | 30 | |
31 | 31 | } |
32 | 32 | |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function maybe_create_scheduled_event() { |
38 | 38 | |
39 | - if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) { |
|
40 | - $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) ); |
|
41 | - wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' ); |
|
39 | + if (!wp_next_scheduled('getpaid_daily_maintenance')) { |
|
40 | + $timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp')); |
|
41 | + wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance'); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | } |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function maybe_clear_deprecated_events() { |
51 | 51 | |
52 | - if ( ! get_option( 'wpinv_cleared_old_events' ) ) { |
|
53 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' ); |
|
54 | - wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' ); |
|
55 | - update_option( 'wpinv_cleared_old_events', 1 ); |
|
52 | + if (!get_option('wpinv_cleared_old_events')) { |
|
53 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily'); |
|
54 | + wp_clear_scheduled_hook('wpinv_register_schedule_event_daily'); |
|
55 | + update_option('wpinv_cleared_old_events', 1); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * |
63 | 63 | */ |
64 | 64 | public function backwards_compat() { |
65 | - do_action( 'wpinv_register_schedule_event_daily' ); |
|
65 | + do_action('wpinv_register_schedule_event_daily'); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | public function maybe_expire_subscriptions() { |
73 | 73 | |
74 | 74 | // Fetch expired subscriptions (skips those that expire today). |
75 | - $args = array( |
|
75 | + $args = array( |
|
76 | 76 | 'number' => -1, |
77 | 77 | 'count_total' => false, |
78 | 78 | 'status' => 'trialling active failing cancelled', |
@@ -82,11 +82,11 @@ discard block |
||
82 | 82 | ), |
83 | 83 | ); |
84 | 84 | |
85 | - $subscriptions = new GetPaid_Subscriptions_Query( $args ); |
|
85 | + $subscriptions = new GetPaid_Subscriptions_Query($args); |
|
86 | 86 | |
87 | - foreach ( $subscriptions as $subscription ) { |
|
88 | - if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) { |
|
89 | - $subscription->set_status( 'expired' ); |
|
87 | + foreach ($subscriptions as $subscription) { |
|
88 | + if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', true, $subscription)) { |
|
89 | + $subscription->set_status('expired'); |
|
90 | 90 | $subscription->save(); |
91 | 91 | } |
92 | 92 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * |
99 | 99 | */ |
100 | 100 | public function log_cron_run() { |
101 | - wpinv_error_log( "GetPaid Daily Cron" ); |
|
101 | + wpinv_error_log("GetPaid Daily Cron"); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | } |
@@ -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 | * Returns the errors as html |
@@ -14,27 +14,27 @@ discard block |
||
14 | 14 | * @param clear whether or not to clear the errors. |
15 | 15 | * @since 1.0.19 |
16 | 16 | */ |
17 | -function getpaid_get_errors_html( $clear = true ) { |
|
17 | +function getpaid_get_errors_html($clear = true) { |
|
18 | 18 | |
19 | 19 | $errors = ''; |
20 | - foreach ( wpinv_get_errors() as $error ) { |
|
21 | - $type = 'error'; |
|
20 | + foreach (wpinv_get_errors() as $error) { |
|
21 | + $type = 'error'; |
|
22 | 22 | |
23 | - if ( is_array( $error ) ) { |
|
23 | + if (is_array($error)) { |
|
24 | 24 | $type = $error['type']; |
25 | 25 | $error = $error['text']; |
26 | 26 | } |
27 | 27 | |
28 | 28 | $errors .= aui()->alert( |
29 | 29 | array( |
30 | - 'content' => wp_kses_post( $error ), |
|
30 | + 'content' => wp_kses_post($error), |
|
31 | 31 | 'type' => $type, |
32 | 32 | ) |
33 | 33 | ); |
34 | 34 | |
35 | 35 | } |
36 | 36 | |
37 | - if ( $clear ){ |
|
37 | + if ($clear) { |
|
38 | 38 | wpinv_clear_errors(); |
39 | 39 | } |
40 | 40 | |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | * @return array |
56 | 56 | */ |
57 | 57 | function wpinv_get_errors() { |
58 | - $errors = getpaid_session()->get( 'wpinv_errors' ); |
|
59 | - return is_array( $errors ) ? $errors : array(); |
|
58 | + $errors = getpaid_session()->get('wpinv_errors'); |
|
59 | + return is_array($errors) ? $errors : array(); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -66,15 +66,15 @@ discard block |
||
66 | 66 | * @param string $error_message The error message. |
67 | 67 | * @param string $type Either error, info, warning, primary, dark, light or success. |
68 | 68 | */ |
69 | -function wpinv_set_error( $error_id, $error_message, $type = 'error' ) { |
|
69 | +function wpinv_set_error($error_id, $error_message, $type = 'error') { |
|
70 | 70 | |
71 | 71 | $errors = wpinv_get_errors(); |
72 | - $errors[ $error_id ] = array( |
|
72 | + $errors[$error_id] = array( |
|
73 | 73 | 'type' => $type, |
74 | 74 | 'text' => $error_message, |
75 | 75 | ); |
76 | 76 | |
77 | - getpaid_session()->set( 'wpinv_errors', $errors ); |
|
77 | + getpaid_session()->set('wpinv_errors', $errors); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * |
83 | 83 | */ |
84 | 84 | function wpinv_has_errors() { |
85 | - return count( wpinv_get_errors() ) > 0; |
|
85 | + return count(wpinv_get_errors()) > 0; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -90,21 +90,21 @@ discard block |
||
90 | 90 | * |
91 | 91 | */ |
92 | 92 | function wpinv_clear_errors() { |
93 | - getpaid_session()->set( 'wpinv_errors', null ); |
|
93 | + getpaid_session()->set('wpinv_errors', null); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
97 | 97 | * Clears a single error. |
98 | 98 | * |
99 | 99 | */ |
100 | -function wpinv_unset_error( $error_id ) { |
|
100 | +function wpinv_unset_error($error_id) { |
|
101 | 101 | $errors = wpinv_get_errors(); |
102 | 102 | |
103 | - if ( isset( $errors[ $error_id ] ) ) { |
|
104 | - unset( $errors[ $error_id ] ); |
|
103 | + if (isset($errors[$error_id])) { |
|
104 | + unset($errors[$error_id]); |
|
105 | 105 | } |
106 | 106 | |
107 | - getpaid_session()->set( 'wpinv_errors', $errors ); |
|
107 | + getpaid_session()->set('wpinv_errors', $errors); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -115,15 +115,15 @@ discard block |
||
115 | 115 | * @param string $message Message to log. |
116 | 116 | * @param string $version Version the message was added in. |
117 | 117 | */ |
118 | -function getpaid_doing_it_wrong( $function, $message, $version ) { |
|
118 | +function getpaid_doing_it_wrong($function, $message, $version) { |
|
119 | 119 | |
120 | 120 | $message .= ' Backtrace: ' . wp_debug_backtrace_summary(); |
121 | 121 | |
122 | - if ( is_ajax() || defined( 'REST_REQUEST' ) ) { |
|
123 | - do_action( 'doing_it_wrong_run', $function, $message, $version ); |
|
124 | - error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." ); |
|
122 | + if (is_ajax() || defined('REST_REQUEST')) { |
|
123 | + do_action('doing_it_wrong_run', $function, $message, $version); |
|
124 | + error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}."); |
|
125 | 125 | } else { |
126 | - _doing_it_wrong( $function, $message, $version ); |
|
126 | + _doing_it_wrong($function, $message, $version); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | } |
@@ -137,38 +137,38 @@ discard block |
||
137 | 137 | * @param string $line The line that contains the error. |
138 | 138 | * @param bool $exit Whether or not to exit function execution. |
139 | 139 | */ |
140 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
140 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
141 | 141 | |
142 | - if ( true === apply_filters( 'wpinv_log_errors', true ) ) { |
|
142 | + if (true === apply_filters('wpinv_log_errors', true)) { |
|
143 | 143 | |
144 | 144 | // Ensure the log is a scalar. |
145 | - if ( ! is_scalar( $log ) ) { |
|
146 | - $log = print_r( $log, true ); |
|
145 | + if (!is_scalar($log)) { |
|
146 | + $log = print_r($log, true); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | // Add title. |
150 | - if ( ! empty( $title ) ) { |
|
151 | - $log = $title . ' ' . trim( $log ); |
|
150 | + if (!empty($title)) { |
|
151 | + $log = $title . ' ' . trim($log); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // Add the file to the label. |
155 | - if ( ! empty( $file ) ) { |
|
155 | + if (!empty($file)) { |
|
156 | 156 | $log .= ' in ' . $file; |
157 | 157 | } |
158 | 158 | |
159 | 159 | // Add the line number to the label. |
160 | - if ( ! empty( $line ) ) { |
|
160 | + if (!empty($line)) { |
|
161 | 161 | $log .= ' on line ' . $line; |
162 | 162 | } |
163 | 163 | |
164 | 164 | // Log the message. |
165 | - error_log( trim ( $log ) ); |
|
165 | + error_log(trim($log)); |
|
166 | 166 | |
167 | 167 | // ... and a backtrace. |
168 | - error_log( 'Backtrace ' . wp_debug_backtrace_summary() ); |
|
168 | + error_log('Backtrace ' . wp_debug_backtrace_summary()); |
|
169 | 169 | |
170 | 170 | // Maybe exit. |
171 | - if ( $exit ) { |
|
171 | + if ($exit) { |
|
172 | 172 | exit; |
173 | 173 | } |
174 | 174 |