@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; // Exit if accessed directly |
4 | 4 | } |
5 | 5 | |
@@ -14,65 +14,65 @@ discard block |
||
14 | 14 | } |
15 | 15 | |
16 | 16 | public function init() { |
17 | - do_action( 'wpinv_class_notes_init', $this ); |
|
17 | + do_action('wpinv_class_notes_init', $this); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function includes() { |
21 | - do_action( 'wpinv_class_notes_includes', $this ); |
|
21 | + do_action('wpinv_class_notes_includes', $this); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function actions() { |
25 | 25 | // Secure inovice notes |
26 | - add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 ); |
|
26 | + add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1); |
|
27 | 27 | |
28 | - do_action( 'wpinv_class_notes_actions', $this ); |
|
28 | + do_action('wpinv_class_notes_actions', $this); |
|
29 | 29 | } |
30 | 30 | |
31 | - public function set_invoice_note_type( $query ) { |
|
32 | - $post_ID = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
31 | + public function set_invoice_note_type($query) { |
|
32 | + $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id']; |
|
33 | 33 | |
34 | - if ( $post_ID && get_post_type( $post_ID ) == $this->invoice_post_type ) { |
|
34 | + if ($post_ID && get_post_type($post_ID) == $this->invoice_post_type) { |
|
35 | 35 | $query->query_vars['type__in'] = $this->comment_type; |
36 | 36 | $query->query_vars['type__not_in'] = ''; |
37 | 37 | } else { |
38 | - if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) { |
|
39 | - if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) { |
|
40 | - $key = array_search( $this->comment_type, $type_in ); |
|
41 | - unset( $query->query_vars['type__in'][$key] ); |
|
42 | - } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) { |
|
38 | + if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) { |
|
39 | + if (is_array($type_in) && in_array($this->comment_type, $type_in)) { |
|
40 | + $key = array_search($this->comment_type, $type_in); |
|
41 | + unset($query->query_vars['type__in'][$key]); |
|
42 | + } else if (!is_array($type_in) && $type_in == $this->comment_type) { |
|
43 | 43 | $query->query_vars['type__in'] = ''; |
44 | 44 | } |
45 | 45 | } |
46 | 46 | |
47 | - if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) { |
|
48 | - if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) { |
|
47 | + if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) { |
|
48 | + if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) { |
|
49 | 49 | $query->query_vars['type__not_in'][] = $this->comment_type; |
50 | - } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) { |
|
50 | + } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) { |
|
51 | 51 | $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in']; |
52 | 52 | $query->query_vars['type__not_in'][] = $this->comment_type; |
53 | 53 | } |
54 | 54 | } else { |
55 | - $query->query_vars['type__not_in'] = $this->comment_type; |
|
55 | + $query->query_vars['type__not_in'] = $this->comment_type; |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | 59 | return $query; |
60 | 60 | } |
61 | 61 | |
62 | - public function get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
62 | + public function get_invoice_notes($invoice_id = 0, $type = '') { |
|
63 | 63 | $args = array( |
64 | 64 | 'post_id' => $invoice_id, |
65 | 65 | 'order' => 'comment_date_gmt', |
66 | 66 | 'order' => 'DESC', |
67 | 67 | ); |
68 | 68 | |
69 | - if ( $type == 'customer' ) { |
|
69 | + if ($type == 'customer') { |
|
70 | 70 | $args['meta_key'] = '_wpi_customer_note'; |
71 | 71 | $args['meta_value'] = 1; |
72 | 72 | } |
73 | 73 | |
74 | - $args = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type ); |
|
74 | + $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type); |
|
75 | 75 | |
76 | - return get_comments( $args ); |
|
76 | + return get_comments($args); |
|
77 | 77 | } |
78 | 78 | } |
@@ -7,112 +7,112 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_item_quantities_enabled() { |
15 | - $ret = wpinv_get_option( 'item_quantities', true ); |
|
15 | + $ret = wpinv_get_option('item_quantities', true); |
|
16 | 16 | |
17 | - return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret ); |
|
17 | + return (bool)apply_filters('wpinv_item_quantities_enabled', $ret); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | function wpinv_get_ip() { |
21 | 21 | $ip = '127.0.0.1'; |
22 | 22 | |
23 | - if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { |
|
24 | - $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] ); |
|
25 | - } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
|
26 | - $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] ); |
|
27 | - } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) { |
|
28 | - $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] ); |
|
23 | + if (!empty($_SERVER['HTTP_CLIENT_IP'])) { |
|
24 | + $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']); |
|
25 | + } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
26 | + $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); |
|
27 | + } elseif (!empty($_SERVER['REMOTE_ADDR'])) { |
|
28 | + $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']); |
|
29 | 29 | } |
30 | 30 | |
31 | - return apply_filters( 'wpinv_get_ip', $ip ); |
|
31 | + return apply_filters('wpinv_get_ip', $ip); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | function wpinv_get_user_agent() { |
35 | - if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) { |
|
36 | - $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ); |
|
35 | + if (!empty($_SERVER['HTTP_USER_AGENT'])) { |
|
36 | + $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']); |
|
37 | 37 | } else { |
38 | 38 | $user_agent = ''; |
39 | 39 | } |
40 | 40 | |
41 | - return apply_filters( 'wpinv_get_user_agent', $user_agent ); |
|
41 | + return apply_filters('wpinv_get_user_agent', $user_agent); |
|
42 | 42 | } |
43 | 43 | |
44 | -function wpinv_sanitize_amount( $amount ) { |
|
44 | +function wpinv_sanitize_amount($amount) { |
|
45 | 45 | $is_negative = false; |
46 | 46 | $thousands_sep = wpinv_thousands_seperator(); |
47 | 47 | $decimal_sep = wpinv_decimal_seperator(); |
48 | 48 | |
49 | 49 | // Sanitize the amount |
50 | - if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) { |
|
51 | - if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
52 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
53 | - } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) { |
|
54 | - $amount = str_replace( '.', '', $amount ); |
|
50 | + if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) { |
|
51 | + if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) { |
|
52 | + $amount = str_replace($thousands_sep, '', $amount); |
|
53 | + } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) { |
|
54 | + $amount = str_replace('.', '', $amount); |
|
55 | 55 | } |
56 | 56 | |
57 | - $amount = str_replace( $decimal_sep, '.', $amount ); |
|
58 | - } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
59 | - $amount = str_replace( $thousands_sep, '', $amount ); |
|
57 | + $amount = str_replace($decimal_sep, '.', $amount); |
|
58 | + } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
59 | + $amount = str_replace($thousands_sep, '', $amount); |
|
60 | 60 | } |
61 | 61 | |
62 | - if( $amount < 0 ) { |
|
62 | + if ($amount < 0) { |
|
63 | 63 | $is_negative = true; |
64 | 64 | } |
65 | 65 | |
66 | - $amount = preg_replace( '/[^0-9\.]/', '', $amount ); |
|
66 | + $amount = preg_replace('/[^0-9\.]/', '', $amount); |
|
67 | 67 | |
68 | - $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', 2, $amount ); |
|
69 | - $amount = number_format( (double) $amount, $decimals, '.', '' ); |
|
68 | + $decimals = apply_filters('wpinv_sanitize_amount_decimals', 2, $amount); |
|
69 | + $amount = number_format((double)$amount, $decimals, '.', ''); |
|
70 | 70 | |
71 | - if( $is_negative ) { |
|
71 | + if ($is_negative) { |
|
72 | 72 | $amount *= -1; |
73 | 73 | } |
74 | 74 | |
75 | - return apply_filters( 'wpinv_sanitize_amount', $amount ); |
|
75 | + return apply_filters('wpinv_sanitize_amount', $amount); |
|
76 | 76 | } |
77 | 77 | |
78 | -function wpinv_get_invoice_statuses( $trashed = false ) { |
|
78 | +function wpinv_get_invoice_statuses($trashed = false) { |
|
79 | 79 | $invoice_statuses = array( |
80 | - 'pending' => __( 'Pending Payment', 'invoicing' ), |
|
81 | - 'publish' => __( 'Paid', 'invoicing' ), |
|
82 | - 'processing' => __( 'Processing', 'invoicing' ), |
|
83 | - 'onhold' => __( 'On Hold', 'invoicing' ), |
|
84 | - 'refunded' => __( 'Refunded', 'invoicing' ), |
|
85 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
86 | - 'failed' => __( 'Failed', 'invoicing' ), |
|
87 | - 'renewal' => __( 'Renewal Payment', 'invoicing' ) |
|
80 | + 'pending' => __('Pending Payment', 'invoicing'), |
|
81 | + 'publish' => __('Paid', 'invoicing'), |
|
82 | + 'processing' => __('Processing', 'invoicing'), |
|
83 | + 'onhold' => __('On Hold', 'invoicing'), |
|
84 | + 'refunded' => __('Refunded', 'invoicing'), |
|
85 | + 'cancelled' => __('Cancelled', 'invoicing'), |
|
86 | + 'failed' => __('Failed', 'invoicing'), |
|
87 | + 'renewal' => __('Renewal Payment', 'invoicing') |
|
88 | 88 | ); |
89 | 89 | |
90 | - if ( $trashed ) { |
|
91 | - $invoice_statuses['trash'] = __( 'Trash', 'invoicing' ); |
|
90 | + if ($trashed) { |
|
91 | + $invoice_statuses['trash'] = __('Trash', 'invoicing'); |
|
92 | 92 | } |
93 | 93 | |
94 | - return apply_filters( 'wpinv_statuses', $invoice_statuses ); |
|
94 | + return apply_filters('wpinv_statuses', $invoice_statuses); |
|
95 | 95 | } |
96 | 96 | |
97 | -function wpinv_status_nicename( $status ) { |
|
97 | +function wpinv_status_nicename($status) { |
|
98 | 98 | $statuses = wpinv_get_invoice_statuses(); |
99 | - $status = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' ); |
|
99 | + $status = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing'); |
|
100 | 100 | |
101 | 101 | return $status; |
102 | 102 | } |
103 | 103 | |
104 | 104 | function wpinv_get_currency() { |
105 | - $currency = wpinv_get_option( 'currency', 'USD' ); |
|
105 | + $currency = wpinv_get_option('currency', 'USD'); |
|
106 | 106 | |
107 | - return apply_filters( 'wpinv_currency', $currency ); |
|
107 | + return apply_filters('wpinv_currency', $currency); |
|
108 | 108 | } |
109 | 109 | |
110 | -function wpinv_currency_symbol( $currency = '' ) { |
|
111 | - if ( empty( $currency ) ) { |
|
110 | +function wpinv_currency_symbol($currency = '') { |
|
111 | + if (empty($currency)) { |
|
112 | 112 | $currency = wpinv_get_currency(); |
113 | 113 | } |
114 | 114 | |
115 | - $symbols = apply_filters( 'wpinv_currency_symbols', array( |
|
115 | + $symbols = apply_filters('wpinv_currency_symbols', array( |
|
116 | 116 | 'AED' => 'د.إ', |
117 | 117 | 'ARS' => '$', |
118 | 118 | 'AUD' => '$', |
@@ -164,78 +164,78 @@ discard block |
||
164 | 164 | 'USD' => '$', |
165 | 165 | 'VND' => '₫', |
166 | 166 | 'ZAR' => 'R', |
167 | - ) ); |
|
167 | + )); |
|
168 | 168 | |
169 | - $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '$'; |
|
169 | + $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '$'; |
|
170 | 170 | |
171 | - return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency ); |
|
171 | + return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | function wpinv_currency_position() { |
175 | - $position = wpinv_get_option( 'currency_position', 'left' ); |
|
175 | + $position = wpinv_get_option('currency_position', 'left'); |
|
176 | 176 | |
177 | - return apply_filters( 'wpinv_currency_position', $position ); |
|
177 | + return apply_filters('wpinv_currency_position', $position); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | function wpinv_thousands_seperator() { |
181 | - $thousand_sep = wpinv_get_option( 'thousands_seperator', ',' ); |
|
181 | + $thousand_sep = wpinv_get_option('thousands_seperator', ','); |
|
182 | 182 | |
183 | - return apply_filters( 'wpinv_thousands_seperator', $thousand_sep ); |
|
183 | + return apply_filters('wpinv_thousands_seperator', $thousand_sep); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | function wpinv_decimal_seperator() { |
187 | - $decimal_sep = wpinv_get_option( 'decimal_seperator', '.' ); |
|
187 | + $decimal_sep = wpinv_get_option('decimal_seperator', '.'); |
|
188 | 188 | |
189 | - return apply_filters( 'wpinv_decimal_seperator', $decimal_sep ); |
|
189 | + return apply_filters('wpinv_decimal_seperator', $decimal_sep); |
|
190 | 190 | } |
191 | 191 | |
192 | 192 | function wpinv_decimals() { |
193 | - $decimals = wpinv_get_option( 'decimals', 2 ); |
|
193 | + $decimals = wpinv_get_option('decimals', 2); |
|
194 | 194 | |
195 | - return apply_filters( 'wpinv_decimals', $decimals ); |
|
195 | + return apply_filters('wpinv_decimals', $decimals); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | function wpinv_get_currencies() { |
199 | 199 | $currencies = array( |
200 | - 'USD' => __( 'US Dollars ($)', 'invoicing' ), |
|
201 | - 'EUR' => __( 'Euros (€)', 'invoicing' ), |
|
202 | - 'GBP' => __( 'Pounds Sterling (£)', 'invoicing' ), |
|
203 | - 'AUD' => __( 'Australian Dollars ($)', 'invoicing' ), |
|
204 | - 'BRL' => __( 'Brazilian Real (R$)', 'invoicing' ), |
|
205 | - 'CAD' => __( 'Canadian Dollars ($)', 'invoicing' ), |
|
206 | - 'CLP' => __( 'Chilean Peso ($)', 'invoicing' ), |
|
207 | - 'CNY' => __( 'Chinese Yuan (¥)', 'invoicing' ), |
|
208 | - 'CZK' => __( 'Czech Koruna (Kč)', 'invoicing' ), |
|
209 | - 'DKK' => __( 'Danish Krone (DKK)', 'invoicing' ), |
|
210 | - 'HKD' => __( 'Hong Kong Dollar ($)', 'invoicing' ), |
|
211 | - 'HUF' => __( 'Hungarian Forint (Ft)', 'invoicing' ), |
|
212 | - 'INR' => __( 'Indian Rupee (₹)', 'invoicing' ), |
|
213 | - 'ILS' => __( 'Israeli Shekel (₪)', 'invoicing' ), |
|
214 | - 'JPY' => __( 'Japanese Yen (¥)', 'invoicing' ), |
|
215 | - 'MYR' => __( 'Malaysian Ringgit (RM)', 'invoicing' ), |
|
216 | - 'MXN' => __( 'Mexican Peso ($)', 'invoicing' ), |
|
217 | - 'NZD' => __( 'New Zealand Dollar ($)', 'invoicing' ), |
|
218 | - 'NOK' => __( 'Norwegian Krone (kr)', 'invoicing' ), |
|
219 | - 'PHP' => __( 'Philippine Peso (₱)', 'invoicing' ), |
|
220 | - 'PLN' => __( 'Polish Zloty (zł)', 'invoicing' ), |
|
221 | - 'SGD' => __( 'Singapore Dollar ($)', 'invoicing' ), |
|
222 | - 'SEK' => __( 'Swedish Krona (kr)', 'invoicing' ), |
|
223 | - 'CHF' => __( 'Swiss Franc (CHF)', 'invoicing' ), |
|
224 | - 'TWD' => __( 'Taiwan New Dollar (NT$)', 'invoicing' ), |
|
225 | - 'THB' => __( 'Thai Baht (฿)', 'invoicing' ), |
|
226 | - 'TRY' => __( 'Turkish Lira (₺)', 'invoicing' ), |
|
227 | - 'RIAL' => __( 'Iranian Rial (﷼)', 'invoicing' ), |
|
228 | - 'RUB' => __( 'Russian Ruble (₽)', 'invoicing' ), |
|
229 | - 'ZAR' => __( 'South African Rand (R)', 'invoicing' ) |
|
200 | + 'USD' => __('US Dollars ($)', 'invoicing'), |
|
201 | + 'EUR' => __('Euros (€)', 'invoicing'), |
|
202 | + 'GBP' => __('Pounds Sterling (£)', 'invoicing'), |
|
203 | + 'AUD' => __('Australian Dollars ($)', 'invoicing'), |
|
204 | + 'BRL' => __('Brazilian Real (R$)', 'invoicing'), |
|
205 | + 'CAD' => __('Canadian Dollars ($)', 'invoicing'), |
|
206 | + 'CLP' => __('Chilean Peso ($)', 'invoicing'), |
|
207 | + 'CNY' => __('Chinese Yuan (¥)', 'invoicing'), |
|
208 | + 'CZK' => __('Czech Koruna (Kč)', 'invoicing'), |
|
209 | + 'DKK' => __('Danish Krone (DKK)', 'invoicing'), |
|
210 | + 'HKD' => __('Hong Kong Dollar ($)', 'invoicing'), |
|
211 | + 'HUF' => __('Hungarian Forint (Ft)', 'invoicing'), |
|
212 | + 'INR' => __('Indian Rupee (₹)', 'invoicing'), |
|
213 | + 'ILS' => __('Israeli Shekel (₪)', 'invoicing'), |
|
214 | + 'JPY' => __('Japanese Yen (¥)', 'invoicing'), |
|
215 | + 'MYR' => __('Malaysian Ringgit (RM)', 'invoicing'), |
|
216 | + 'MXN' => __('Mexican Peso ($)', 'invoicing'), |
|
217 | + 'NZD' => __('New Zealand Dollar ($)', 'invoicing'), |
|
218 | + 'NOK' => __('Norwegian Krone (kr)', 'invoicing'), |
|
219 | + 'PHP' => __('Philippine Peso (₱)', 'invoicing'), |
|
220 | + 'PLN' => __('Polish Zloty (zł)', 'invoicing'), |
|
221 | + 'SGD' => __('Singapore Dollar ($)', 'invoicing'), |
|
222 | + 'SEK' => __('Swedish Krona (kr)', 'invoicing'), |
|
223 | + 'CHF' => __('Swiss Franc (CHF)', 'invoicing'), |
|
224 | + 'TWD' => __('Taiwan New Dollar (NT$)', 'invoicing'), |
|
225 | + 'THB' => __('Thai Baht (฿)', 'invoicing'), |
|
226 | + 'TRY' => __('Turkish Lira (₺)', 'invoicing'), |
|
227 | + 'RIAL' => __('Iranian Rial (﷼)', 'invoicing'), |
|
228 | + 'RUB' => __('Russian Ruble (₽)', 'invoicing'), |
|
229 | + 'ZAR' => __('South African Rand (R)', 'invoicing') |
|
230 | 230 | ); |
231 | 231 | |
232 | - asort( $currencies ); |
|
232 | + asort($currencies); |
|
233 | 233 | |
234 | - return apply_filters( 'wpinv_currencies', $currencies ); |
|
234 | + return apply_filters('wpinv_currencies', $currencies); |
|
235 | 235 | } |
236 | 236 | |
237 | -function wpinv_price( $amount = '', $currency = '' ) { |
|
238 | - if( empty( $currency ) ) { |
|
237 | +function wpinv_price($amount = '', $currency = '') { |
|
238 | + if (empty($currency)) { |
|
239 | 239 | $currency = wpinv_get_currency(); |
240 | 240 | } |
241 | 241 | |
@@ -243,14 +243,14 @@ discard block |
||
243 | 243 | |
244 | 244 | $negative = $amount < 0; |
245 | 245 | |
246 | - if ( $negative ) { |
|
247 | - $amount = substr( $amount, 1 ); |
|
246 | + if ($negative) { |
|
247 | + $amount = substr($amount, 1); |
|
248 | 248 | } |
249 | 249 | |
250 | - $symbol = wpinv_currency_symbol( $currency ); |
|
250 | + $symbol = wpinv_currency_symbol($currency); |
|
251 | 251 | |
252 | - if ( $position == 'left' || $position == 'left_space' ) { |
|
253 | - switch ( $currency ) { |
|
252 | + if ($position == 'left' || $position == 'left_space') { |
|
253 | + switch ($currency) { |
|
254 | 254 | case "GBP" : |
255 | 255 | case "BRL" : |
256 | 256 | case "EUR" : |
@@ -262,15 +262,15 @@ discard block |
||
262 | 262 | case "NZD" : |
263 | 263 | case "SGD" : |
264 | 264 | case "JPY" : |
265 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
265 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
266 | 266 | break; |
267 | 267 | default : |
268 | 268 | //$price = $currency . ' ' . $amount; |
269 | - $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
269 | + $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount; |
|
270 | 270 | break; |
271 | 271 | } |
272 | 272 | } else { |
273 | - switch ( $currency ) { |
|
273 | + switch ($currency) { |
|
274 | 274 | case "GBP" : |
275 | 275 | case "BRL" : |
276 | 276 | case "EUR" : |
@@ -281,82 +281,82 @@ discard block |
||
281 | 281 | case "MXN" : |
282 | 282 | case "SGD" : |
283 | 283 | case "JPY" : |
284 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
284 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
285 | 285 | break; |
286 | 286 | default : |
287 | 287 | //$price = $amount . ' ' . $currency; |
288 | - $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
288 | + $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol; |
|
289 | 289 | break; |
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
293 | - if ( $negative ) { |
|
293 | + if ($negative) { |
|
294 | 294 | $price = '-' . $price; |
295 | 295 | } |
296 | 296 | |
297 | - $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount ); |
|
297 | + $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount); |
|
298 | 298 | |
299 | 299 | return $price; |
300 | 300 | } |
301 | 301 | |
302 | -function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) { |
|
302 | +function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) { |
|
303 | 303 | $thousands_sep = wpinv_thousands_seperator(); |
304 | 304 | $decimal_sep = wpinv_decimal_seperator(); |
305 | 305 | |
306 | - if ( $decimals === NULL ) { |
|
306 | + if ($decimals === NULL) { |
|
307 | 307 | $decimals = wpinv_decimals(); |
308 | 308 | } |
309 | 309 | |
310 | - if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) { |
|
311 | - $whole = substr( $amount, 0, $sep_found ); |
|
312 | - $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) ); |
|
310 | + if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) { |
|
311 | + $whole = substr($amount, 0, $sep_found); |
|
312 | + $part = substr($amount, $sep_found + 1, (strlen($amount) - 1)); |
|
313 | 313 | $amount = $whole . '.' . $part; |
314 | 314 | } |
315 | 315 | |
316 | - if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
317 | - $amount = str_replace( ',', '', $amount ); |
|
316 | + if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
317 | + $amount = str_replace(',', '', $amount); |
|
318 | 318 | } |
319 | 319 | |
320 | - if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) { |
|
321 | - $amount = str_replace( ' ', '', $amount ); |
|
320 | + if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) { |
|
321 | + $amount = str_replace(' ', '', $amount); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( empty( $amount ) ) { |
|
324 | + if (empty($amount)) { |
|
325 | 325 | $amount = 0; |
326 | 326 | } |
327 | 327 | |
328 | - $decimals = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate ); |
|
329 | - $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep ); |
|
328 | + $decimals = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate); |
|
329 | + $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep); |
|
330 | 330 | |
331 | - if ( $calculate ) { |
|
332 | - if ( $thousands_sep === "," ) { |
|
333 | - $formatted = str_replace( ",", "", $formatted ); |
|
331 | + if ($calculate) { |
|
332 | + if ($thousands_sep === ",") { |
|
333 | + $formatted = str_replace(",", "", $formatted); |
|
334 | 334 | } |
335 | 335 | |
336 | - if ( $decimal_sep === "," ) { |
|
337 | - $formatted = str_replace( ",", ".", $formatted ); |
|
336 | + if ($decimal_sep === ",") { |
|
337 | + $formatted = str_replace(",", ".", $formatted); |
|
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | - return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate ); |
|
341 | + return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate); |
|
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_sanitize_key( $key ) { |
|
344 | +function wpinv_sanitize_key($key) { |
|
345 | 345 | $raw_key = $key; |
346 | - $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key ); |
|
346 | + $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key); |
|
347 | 347 | |
348 | - return apply_filters( 'wpinv_sanitize_key', $key, $raw_key ); |
|
348 | + return apply_filters('wpinv_sanitize_key', $key, $raw_key); |
|
349 | 349 | } |
350 | 350 | |
351 | -function wpinv_get_file_extension( $str ) { |
|
352 | - $parts = explode( '.', $str ); |
|
353 | - return end( $parts ); |
|
351 | +function wpinv_get_file_extension($str) { |
|
352 | + $parts = explode('.', $str); |
|
353 | + return end($parts); |
|
354 | 354 | } |
355 | 355 | |
356 | -function wpinv_string_is_image_url( $str ) { |
|
357 | - $ext = wpinv_get_file_extension( $str ); |
|
356 | +function wpinv_string_is_image_url($str) { |
|
357 | + $ext = wpinv_get_file_extension($str); |
|
358 | 358 | |
359 | - switch ( strtolower( $ext ) ) { |
|
359 | + switch (strtolower($ext)) { |
|
360 | 360 | case 'jpeg'; |
361 | 361 | case 'jpg'; |
362 | 362 | $return = true; |
@@ -372,32 +372,32 @@ discard block |
||
372 | 372 | break; |
373 | 373 | } |
374 | 374 | |
375 | - return (bool)apply_filters( 'wpinv_string_is_image', $return, $str ); |
|
375 | + return (bool)apply_filters('wpinv_string_is_image', $return, $str); |
|
376 | 376 | } |
377 | 377 | |
378 | -function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) { |
|
379 | - $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG ); |
|
378 | +function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) { |
|
379 | + $should_log = apply_filters('wpinv_log_errors', WP_DEBUG); |
|
380 | 380 | |
381 | - if ( true === $should_log ) { |
|
381 | + if (true === $should_log) { |
|
382 | 382 | $label = ''; |
383 | - if ( $file && $file !== '' ) { |
|
384 | - $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' ); |
|
383 | + if ($file && $file !== '') { |
|
384 | + $label .= basename($file) . ($line ? '(' . $line . ')' : ''); |
|
385 | 385 | } |
386 | 386 | |
387 | - if ( $title && $title !== '' ) { |
|
387 | + if ($title && $title !== '') { |
|
388 | 388 | $label = $label !== '' ? $label . ' ' : ''; |
389 | 389 | $label .= $title . ' '; |
390 | 390 | } |
391 | 391 | |
392 | - $label = $label !== '' ? trim( $label ) . ' : ' : ''; |
|
392 | + $label = $label !== '' ? trim($label) . ' : ' : ''; |
|
393 | 393 | |
394 | - if ( is_array( $log ) || is_object( $log ) ) { |
|
395 | - error_log( $label . print_r( $log, true ) ); |
|
394 | + if (is_array($log) || is_object($log)) { |
|
395 | + error_log($label . print_r($log, true)); |
|
396 | 396 | } else { |
397 | - error_log( $label . $log ); |
|
397 | + error_log($label . $log); |
|
398 | 398 | } |
399 | 399 | |
400 | - if ( $exit ) { |
|
400 | + if ($exit) { |
|
401 | 401 | exit; |
402 | 402 | } |
403 | 403 | } |
@@ -405,65 +405,65 @@ discard block |
||
405 | 405 | |
406 | 406 | function wpinv_is_ajax_disabled() { |
407 | 407 | $retval = false; |
408 | - return apply_filters( 'wpinv_is_ajax_disabled', $retval ); |
|
408 | + return apply_filters('wpinv_is_ajax_disabled', $retval); |
|
409 | 409 | } |
410 | 410 | |
411 | -function wpinv_get_current_page_url( $nocache = false ) { |
|
411 | +function wpinv_get_current_page_url($nocache = false) { |
|
412 | 412 | global $wp; |
413 | 413 | |
414 | - if ( get_option( 'permalink_structure' ) ) { |
|
415 | - $base = trailingslashit( home_url( $wp->request ) ); |
|
414 | + if (get_option('permalink_structure')) { |
|
415 | + $base = trailingslashit(home_url($wp->request)); |
|
416 | 416 | } else { |
417 | - $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) ); |
|
418 | - $base = remove_query_arg( array( 'post_type', 'name' ), $base ); |
|
417 | + $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request))); |
|
418 | + $base = remove_query_arg(array('post_type', 'name'), $base); |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | $scheme = is_ssl() ? 'https' : 'http'; |
422 | - $uri = set_url_scheme( $base, $scheme ); |
|
422 | + $uri = set_url_scheme($base, $scheme); |
|
423 | 423 | |
424 | - if ( is_front_page() ) { |
|
425 | - $uri = home_url( '/' ); |
|
426 | - } elseif ( wpinv_is_checkout( array(), false ) ) { |
|
424 | + if (is_front_page()) { |
|
425 | + $uri = home_url('/'); |
|
426 | + } elseif (wpinv_is_checkout(array(), false)) { |
|
427 | 427 | $uri = wpinv_get_checkout_uri(); |
428 | 428 | } |
429 | 429 | |
430 | - $uri = apply_filters( 'wpinv_get_current_page_url', $uri ); |
|
430 | + $uri = apply_filters('wpinv_get_current_page_url', $uri); |
|
431 | 431 | |
432 | - if ( $nocache ) { |
|
433 | - $uri = wpinv_add_cache_busting( $uri ); |
|
432 | + if ($nocache) { |
|
433 | + $uri = wpinv_add_cache_busting($uri); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | return $uri; |
437 | 437 | } |
438 | 438 | |
439 | 439 | function wpinv_get_php_arg_separator_output() { |
440 | - return ini_get( 'arg_separator.output' ); |
|
440 | + return ini_get('arg_separator.output'); |
|
441 | 441 | } |
442 | 442 | |
443 | -function wpinv_rgb_from_hex( $color ) { |
|
444 | - $color = str_replace( '#', '', $color ); |
|
443 | +function wpinv_rgb_from_hex($color) { |
|
444 | + $color = str_replace('#', '', $color); |
|
445 | 445 | // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF" |
446 | - $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color ); |
|
446 | + $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color); |
|
447 | 447 | |
448 | 448 | $rgb = array(); |
449 | - $rgb['R'] = hexdec( $color{0}.$color{1} ); |
|
450 | - $rgb['G'] = hexdec( $color{2}.$color{3} ); |
|
451 | - $rgb['B'] = hexdec( $color{4}.$color{5} ); |
|
449 | + $rgb['R'] = hexdec($color{0} . $color{1} ); |
|
450 | + $rgb['G'] = hexdec($color{2} . $color{3} ); |
|
451 | + $rgb['B'] = hexdec($color{4} . $color{5} ); |
|
452 | 452 | |
453 | 453 | return $rgb; |
454 | 454 | } |
455 | 455 | |
456 | -function wpinv_hex_darker( $color, $factor = 30 ) { |
|
457 | - $base = wpinv_rgb_from_hex( $color ); |
|
456 | +function wpinv_hex_darker($color, $factor = 30) { |
|
457 | + $base = wpinv_rgb_from_hex($color); |
|
458 | 458 | $color = '#'; |
459 | 459 | |
460 | - foreach ( $base as $k => $v ) { |
|
460 | + foreach ($base as $k => $v) { |
|
461 | 461 | $amount = $v / 100; |
462 | - $amount = round( $amount * $factor ); |
|
462 | + $amount = round($amount * $factor); |
|
463 | 463 | $new_decimal = $v - $amount; |
464 | 464 | |
465 | - $new_hex_component = dechex( $new_decimal ); |
|
466 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
465 | + $new_hex_component = dechex($new_decimal); |
|
466 | + if (strlen($new_hex_component) < 2) { |
|
467 | 467 | $new_hex_component = "0" . $new_hex_component; |
468 | 468 | } |
469 | 469 | $color .= $new_hex_component; |
@@ -472,18 +472,18 @@ discard block |
||
472 | 472 | return $color; |
473 | 473 | } |
474 | 474 | |
475 | -function wpinv_hex_lighter( $color, $factor = 30 ) { |
|
476 | - $base = wpinv_rgb_from_hex( $color ); |
|
475 | +function wpinv_hex_lighter($color, $factor = 30) { |
|
476 | + $base = wpinv_rgb_from_hex($color); |
|
477 | 477 | $color = '#'; |
478 | 478 | |
479 | - foreach ( $base as $k => $v ) { |
|
479 | + foreach ($base as $k => $v) { |
|
480 | 480 | $amount = 255 - $v; |
481 | 481 | $amount = $amount / 100; |
482 | - $amount = round( $amount * $factor ); |
|
482 | + $amount = round($amount * $factor); |
|
483 | 483 | $new_decimal = $v + $amount; |
484 | 484 | |
485 | - $new_hex_component = dechex( $new_decimal ); |
|
486 | - if ( strlen( $new_hex_component ) < 2 ) { |
|
485 | + $new_hex_component = dechex($new_decimal); |
|
486 | + if (strlen($new_hex_component) < 2) { |
|
487 | 487 | $new_hex_component = "0" . $new_hex_component; |
488 | 488 | } |
489 | 489 | $color .= $new_hex_component; |
@@ -492,22 +492,22 @@ discard block |
||
492 | 492 | return $color; |
493 | 493 | } |
494 | 494 | |
495 | -function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) { |
|
496 | - $hex = str_replace( '#', '', $color ); |
|
495 | +function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') { |
|
496 | + $hex = str_replace('#', '', $color); |
|
497 | 497 | |
498 | - $c_r = hexdec( substr( $hex, 0, 2 ) ); |
|
499 | - $c_g = hexdec( substr( $hex, 2, 2 ) ); |
|
500 | - $c_b = hexdec( substr( $hex, 4, 2 ) ); |
|
498 | + $c_r = hexdec(substr($hex, 0, 2)); |
|
499 | + $c_g = hexdec(substr($hex, 2, 2)); |
|
500 | + $c_b = hexdec(substr($hex, 4, 2)); |
|
501 | 501 | |
502 | - $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000; |
|
502 | + $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000; |
|
503 | 503 | |
504 | 504 | return $brightness > 155 ? $dark : $light; |
505 | 505 | } |
506 | 506 | |
507 | -function wpinv_format_hex( $hex ) { |
|
508 | - $hex = trim( str_replace( '#', '', $hex ) ); |
|
507 | +function wpinv_format_hex($hex) { |
|
508 | + $hex = trim(str_replace('#', '', $hex)); |
|
509 | 509 | |
510 | - if ( strlen( $hex ) == 3 ) { |
|
510 | + if (strlen($hex) == 3) { |
|
511 | 511 | $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2]; |
512 | 512 | } |
513 | 513 | |
@@ -527,12 +527,12 @@ discard block |
||
527 | 527 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
528 | 528 | * @return string |
529 | 529 | */ |
530 | -function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) { |
|
531 | - if ( function_exists( 'mb_strimwidth' ) ) { |
|
532 | - return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding ); |
|
530 | +function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') { |
|
531 | + if (function_exists('mb_strimwidth')) { |
|
532 | + return mb_strimwidth($str, $start, $width, $trimmaker, $encoding); |
|
533 | 533 | } |
534 | 534 | |
535 | - return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker; |
|
535 | + return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker; |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | /** |
@@ -544,28 +544,28 @@ discard block |
||
544 | 544 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
545 | 545 | * @return int Returns the number of characters in string. |
546 | 546 | */ |
547 | -function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) { |
|
548 | - if ( function_exists( 'mb_strlen' ) ) { |
|
549 | - return mb_strlen( $str, $encoding ); |
|
547 | +function wpinv_utf8_strlen($str, $encoding = 'UTF-8') { |
|
548 | + if (function_exists('mb_strlen')) { |
|
549 | + return mb_strlen($str, $encoding); |
|
550 | 550 | } |
551 | 551 | |
552 | - return strlen( $str ); |
|
552 | + return strlen($str); |
|
553 | 553 | } |
554 | 554 | |
555 | -function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) { |
|
556 | - if ( function_exists( 'mb_strtolower' ) ) { |
|
557 | - return mb_strtolower( $str, $encoding ); |
|
555 | +function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') { |
|
556 | + if (function_exists('mb_strtolower')) { |
|
557 | + return mb_strtolower($str, $encoding); |
|
558 | 558 | } |
559 | 559 | |
560 | - return strtolower( $str ); |
|
560 | + return strtolower($str); |
|
561 | 561 | } |
562 | 562 | |
563 | -function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) { |
|
564 | - if ( function_exists( 'mb_strtoupper' ) ) { |
|
565 | - return mb_strtoupper( $str, $encoding ); |
|
563 | +function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') { |
|
564 | + if (function_exists('mb_strtoupper')) { |
|
565 | + return mb_strtoupper($str, $encoding); |
|
566 | 566 | } |
567 | 567 | |
568 | - return strtoupper( $str ); |
|
568 | + return strtoupper($str); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | /** |
@@ -579,12 +579,12 @@ discard block |
||
579 | 579 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
580 | 580 | * @return int Returns the position of the first occurrence of search in the string. |
581 | 581 | */ |
582 | -function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
583 | - if ( function_exists( 'mb_strpos' ) ) { |
|
584 | - return mb_strpos( $str, $find, $offset, $encoding ); |
|
582 | +function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
583 | + if (function_exists('mb_strpos')) { |
|
584 | + return mb_strpos($str, $find, $offset, $encoding); |
|
585 | 585 | } |
586 | 586 | |
587 | - return strpos( $str, $find, $offset ); |
|
587 | + return strpos($str, $find, $offset); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | /** |
@@ -598,12 +598,12 @@ discard block |
||
598 | 598 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
599 | 599 | * @return int Returns the position of the last occurrence of search. |
600 | 600 | */ |
601 | -function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) { |
|
602 | - if ( function_exists( 'mb_strrpos' ) ) { |
|
603 | - return mb_strrpos( $str, $find, $offset, $encoding ); |
|
601 | +function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') { |
|
602 | + if (function_exists('mb_strrpos')) { |
|
603 | + return mb_strrpos($str, $find, $offset, $encoding); |
|
604 | 604 | } |
605 | 605 | |
606 | - return strrpos( $str, $find, $offset ); |
|
606 | + return strrpos($str, $find, $offset); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -618,16 +618,16 @@ discard block |
||
618 | 618 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
619 | 619 | * @return string |
620 | 620 | */ |
621 | -function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) { |
|
622 | - if ( function_exists( 'mb_substr' ) ) { |
|
623 | - if ( $length === null ) { |
|
624 | - return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
621 | +function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') { |
|
622 | + if (function_exists('mb_substr')) { |
|
623 | + if ($length === null) { |
|
624 | + return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
625 | 625 | } else { |
626 | - return mb_substr( $str, $start, $length, $encoding ); |
|
626 | + return mb_substr($str, $start, $length, $encoding); |
|
627 | 627 | } |
628 | 628 | } |
629 | 629 | |
630 | - return substr( $str, $start, $length ); |
|
630 | + return substr($str, $start, $length); |
|
631 | 631 | } |
632 | 632 | |
633 | 633 | /** |
@@ -639,48 +639,48 @@ discard block |
||
639 | 639 | * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8". |
640 | 640 | * @return string The width of string. |
641 | 641 | */ |
642 | -function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) { |
|
643 | - if ( function_exists( 'mb_strwidth' ) ) { |
|
644 | - return mb_strwidth( $str, $encoding ); |
|
642 | +function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') { |
|
643 | + if (function_exists('mb_strwidth')) { |
|
644 | + return mb_strwidth($str, $encoding); |
|
645 | 645 | } |
646 | 646 | |
647 | - return wpinv_utf8_strlen( $str, $encoding ); |
|
647 | + return wpinv_utf8_strlen($str, $encoding); |
|
648 | 648 | } |
649 | 649 | |
650 | -function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) { |
|
651 | - if ( function_exists( 'mb_strlen' ) ) { |
|
652 | - $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding ); |
|
650 | +function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') { |
|
651 | + if (function_exists('mb_strlen')) { |
|
652 | + $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding); |
|
653 | 653 | $str_end = ""; |
654 | 654 | |
655 | - if ( $lower_str_end ) { |
|
656 | - $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding ); |
|
655 | + if ($lower_str_end) { |
|
656 | + $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding); |
|
657 | 657 | } else { |
658 | - $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ); |
|
658 | + $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | return $first_letter . $str_end; |
662 | 662 | } |
663 | 663 | |
664 | - return ucfirst( $str ); |
|
664 | + return ucfirst($str); |
|
665 | 665 | } |
666 | 666 | |
667 | -function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) { |
|
668 | - if ( function_exists( 'mb_convert_case' ) ) { |
|
669 | - return mb_convert_case( $str, MB_CASE_TITLE, $encoding ); |
|
667 | +function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') { |
|
668 | + if (function_exists('mb_convert_case')) { |
|
669 | + return mb_convert_case($str, MB_CASE_TITLE, $encoding); |
|
670 | 670 | } |
671 | 671 | |
672 | - return ucwords( $str ); |
|
672 | + return ucwords($str); |
|
673 | 673 | } |
674 | 674 | |
675 | -function wpinv_period_in_days( $period, $unit ) { |
|
676 | - $period = absint( $period ); |
|
675 | +function wpinv_period_in_days($period, $unit) { |
|
676 | + $period = absint($period); |
|
677 | 677 | |
678 | - if ( $period > 0 ) { |
|
679 | - if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) { |
|
678 | + if ($period > 0) { |
|
679 | + if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) { |
|
680 | 680 | $period = $period * 7; |
681 | - } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) { |
|
681 | + } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) { |
|
682 | 682 | $period = $period * 30; |
683 | - } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) { |
|
683 | + } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) { |
|
684 | 684 | $period = $period * 365; |
685 | 685 | } |
686 | 686 | } |
@@ -130,7 +130,6 @@ |
||
130 | 130 | private function mostSpecificSubdivision() |
131 | 131 | { |
132 | 132 | return empty($this->subdivisions) ? |
133 | - new \GeoIp2\Record\Subdivision(array(), $this->locales) : |
|
134 | - end($this->subdivisions); |
|
133 | + new \GeoIp2\Record\Subdivision(array(), $this->locales) : end($this->subdivisions); |
|
135 | 134 | } |
136 | 135 | } |
@@ -76,7 +76,7 @@ |
||
76 | 76 | // This is for backwards compatibility. Do not remove except for a |
77 | 77 | // major version bump. |
78 | 78 | if (is_string($options)) { |
79 | - $options = array( 'host' => $options ); |
|
79 | + $options = array('host' => $options); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | if (!isset($options['host'])) { |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | if ($nodesWithStyleAttributes !== false) { |
239 | 239 | /** @var $nodeWithStyleAttribute DOMNode */ |
240 | 240 | foreach ($nodesWithStyleAttributes as $node) { |
241 | - $normalizedOriginalStyle = preg_replace_callback( '/[A-z\\-]+(?=\\:)/S', array( $this, 'strtolower' ), $node->getAttribute('style') ); |
|
241 | + $normalizedOriginalStyle = preg_replace_callback('/[A-z\\-]+(?=\\:)/S', array($this, 'strtolower'), $node->getAttribute('style')); |
|
242 | 242 | |
243 | 243 | // in order to not overwrite existing style attributes in the HTML, we have to save the original HTML styles |
244 | 244 | $nodePath = $node->getNodePath(); |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | // now sort the selectors by precedence |
292 | - usort($allSelectors, array($this,'sortBySelectorPrecedence')); |
|
292 | + usort($allSelectors, array($this, 'sortBySelectorPrecedence')); |
|
293 | 293 | |
294 | 294 | $this->caches[self::CACHE_KEY_CSS][$cssKey] = $allSelectors; |
295 | 295 | } |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | if ($nodesWithStyleDisplayNone->length > 0) { |
330 | 330 | /** @var $node \DOMNode */ |
331 | 331 | foreach ($nodesWithStyleDisplayNone as $node) { |
332 | - if ($node->parentNode && is_callable(array($node->parentNode,'removeChild'))) { |
|
332 | + if ($node->parentNode && is_callable(array($node->parentNode, 'removeChild'))) { |
|
333 | 333 | $node->parentNode->removeChild($node); |
334 | 334 | } |
335 | 335 | } |
@@ -338,10 +338,10 @@ discard block |
||
338 | 338 | $this->copyCssWithMediaToStyleNode($cssParts, $xmlDocument); |
339 | 339 | |
340 | 340 | if ($this->preserveEncoding) { |
341 | - if ( function_exists( 'mb_convert_encoding' ) ) { |
|
342 | - return mb_convert_encoding( $xmlDocument->saveHTML(), self::ENCODING, 'HTML-ENTITIES' ); |
|
341 | + if (function_exists('mb_convert_encoding')) { |
|
342 | + return mb_convert_encoding($xmlDocument->saveHTML(), self::ENCODING, 'HTML-ENTITIES'); |
|
343 | 343 | } else { |
344 | - return htmlspecialchars_decode( utf8_encode( html_entity_decode( $xmlDocument->saveHTML(), ENT_COMPAT, self::ENCODING ) ) ); |
|
344 | + return htmlspecialchars_decode(utf8_encode(html_entity_decode($xmlDocument->saveHTML(), ENT_COMPAT, self::ENCODING))); |
|
345 | 345 | } |
346 | 346 | } else { |
347 | 347 | return $xmlDocument->saveHTML(); |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | * @return array |
463 | 463 | */ |
464 | 464 | private function splitCssAndMediaQuery($css) { |
465 | - $css = preg_replace_callback( '#@media\\s+(?:only\\s)?(?:[\\s{\(]|screen|all)\\s?[^{]+{.*}\\s*}\\s*#misU', array( $this, '_media_concat' ), $css ); |
|
465 | + $css = preg_replace_callback('#@media\\s+(?:only\\s)?(?:[\\s{\(]|screen|all)\\s?[^{]+{.*}\\s*}\\s*#misU', array($this, '_media_concat'), $css); |
|
466 | 466 | |
467 | 467 | // filter the CSS |
468 | 468 | $search = array( |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | return array('css' => $css, 'media' => self::$_media); |
487 | 487 | } |
488 | 488 | |
489 | - private function _media_concat( $matches ) { |
|
489 | + private function _media_concat($matches) { |
|
490 | 490 | self::$_media .= $matches[0]; |
491 | 491 | } |
492 | 492 | |
@@ -524,10 +524,10 @@ discard block |
||
524 | 524 | $bodyWithoutUnprocessableTags = $this->html; |
525 | 525 | } |
526 | 526 | |
527 | - if ( function_exists( 'mb_convert_encoding' ) ) { |
|
528 | - return mb_convert_encoding( $bodyWithoutUnprocessableTags, 'HTML-ENTITIES', self::ENCODING ); |
|
527 | + if (function_exists('mb_convert_encoding')) { |
|
528 | + return mb_convert_encoding($bodyWithoutUnprocessableTags, 'HTML-ENTITIES', self::ENCODING); |
|
529 | 529 | } else { |
530 | - return htmlspecialchars_decode( utf8_decode( htmlentities( $bodyWithoutUnprocessableTags, ENT_COMPAT, self::ENCODING, false ) ) ); |
|
530 | + return htmlspecialchars_decode(utf8_decode(htmlentities($bodyWithoutUnprocessableTags, ENT_COMPAT, self::ENCODING, false))); |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
@@ -562,7 +562,7 @@ discard block |
||
562 | 562 | $precedence = 0; |
563 | 563 | $value = 100; |
564 | 564 | // ids: worth 100, classes: worth 10, elements: worth 1 |
565 | - $search = array('\\#','\\.',''); |
|
565 | + $search = array('\\#', '\\.', ''); |
|
566 | 566 | |
567 | 567 | foreach ($search as $s) { |
568 | 568 | if (trim($selector == '')) { |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | */ |
591 | 591 | private function translateCssToXpath($paramCssSelector) { |
592 | 592 | $cssSelector = ' ' . $paramCssSelector . ' '; |
593 | - $cssSelector = preg_replace_callback( '/\s+\w+\s+/', array( $this, 'strtolower' ), $cssSelector ); |
|
593 | + $cssSelector = preg_replace_callback('/\s+\w+\s+/', array($this, 'strtolower'), $cssSelector); |
|
594 | 594 | $cssSelector = trim($cssSelector); |
595 | 595 | $xpathKey = md5($cssSelector); |
596 | 596 | if (!isset($this->caches[self::CACHE_KEY_XPATH][$xpathKey])) { |
@@ -713,7 +713,7 @@ discard block |
||
713 | 713 | * @return array |
714 | 714 | */ |
715 | 715 | private function parseNth(array $match) { |
716 | - if (in_array(strtolower($match[2]), array('even','odd'))) { |
|
716 | + if (in_array(strtolower($match[2]), array('even', 'odd'))) { |
|
717 | 717 | $index = strtolower($match[2]) == 'even' ? 0 : 1; |
718 | 718 | return array(self::MULTIPLIER => 2, self::INDEX => $index); |
719 | 719 | } elseif (stripos($match[2], 'n') === false) { |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | * @param array $args |
22 | 22 | * @param array $assoc_args |
23 | 23 | */ |
24 | - public function count( $args, $assoc_args ) { |
|
24 | + public function count($args, $assoc_args) { |
|
25 | 25 | $sessions = WP_Session_Utils::count_sessions(); |
26 | 26 | |
27 | - \WP_CLI::line( sprintf( '%d sessions currently exist.', absint( $sessions ) ) ); |
|
27 | + \WP_CLI::line(sprintf('%d sessions currently exist.', absint($sessions))); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | * @param array $args |
54 | 54 | * @param array $assoc_args |
55 | 55 | */ |
56 | - public function delete( $args, $assoc_args ) { |
|
57 | - if ( isset( $assoc_args['limit'] ) ) { |
|
58 | - $limit = absint( $assoc_args['limit'] ); |
|
56 | + public function delete($args, $assoc_args) { |
|
57 | + if (isset($assoc_args['limit'])) { |
|
58 | + $limit = absint($assoc_args['limit']); |
|
59 | 59 | |
60 | - $count = WP_Session_Utils::delete_old_sessions( $limit ); |
|
60 | + $count = WP_Session_Utils::delete_old_sessions($limit); |
|
61 | 61 | |
62 | - if ( $count > 0 ) { |
|
63 | - \WP_CLI::line( sprintf( 'Deleted %d sessions.', $count ) ); |
|
62 | + if ($count > 0) { |
|
63 | + \WP_CLI::line(sprintf('Deleted %d sessions.', $count)); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // Clear memory |
@@ -69,32 +69,32 @@ discard block |
||
69 | 69 | } |
70 | 70 | |
71 | 71 | // Determine if we're deleting all sessions or just a subset. |
72 | - $all = isset( $assoc_args['all'] ); |
|
72 | + $all = isset($assoc_args['all']); |
|
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Determine the size of each batch for deletion. |
76 | 76 | * |
77 | 77 | * @param int |
78 | 78 | */ |
79 | - $batch = isset( $assoc_args['batch'] ) ? absint( $assoc_args['batch'] ) : apply_filters( 'wp_session_delete_batch_size', 1000 ); |
|
79 | + $batch = isset($assoc_args['batch']) ? absint($assoc_args['batch']) : apply_filters('wp_session_delete_batch_size', 1000); |
|
80 | 80 | |
81 | - switch ( $all ) { |
|
81 | + switch ($all) { |
|
82 | 82 | case true: |
83 | 83 | $count = WP_Session_Utils::delete_all_sessions(); |
84 | 84 | |
85 | - \WP_CLI::line( sprintf( 'Deleted all %d sessions.', $count ) ); |
|
85 | + \WP_CLI::line(sprintf('Deleted all %d sessions.', $count)); |
|
86 | 86 | break; |
87 | 87 | case false: |
88 | 88 | do { |
89 | - $count = WP_Session_Utils::delete_old_sessions( $batch ); |
|
89 | + $count = WP_Session_Utils::delete_old_sessions($batch); |
|
90 | 90 | |
91 | - if ( $count > 0 ) { |
|
92 | - \WP_CLI::line( sprintf( 'Deleted %d sessions.', $count ) ); |
|
91 | + if ($count > 0) { |
|
92 | + \WP_CLI::line(sprintf('Deleted %d sessions.', $count)); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | // Clear memory |
96 | 96 | self::free_up_memory(); |
97 | - } while ( $count > 0 ); |
|
97 | + } while ($count > 0); |
|
98 | 98 | break; |
99 | 99 | } |
100 | 100 | } |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | * @param array $args |
121 | 121 | * @param array $assoc_args |
122 | 122 | */ |
123 | - public function generate( $args, $assoc_args ) { |
|
124 | - $count = absint( $args[0] ); |
|
125 | - $date = isset( $assoc_args['expires'] ) ? $assoc_args['expires'] : null; |
|
123 | + public function generate($args, $assoc_args) { |
|
124 | + $count = absint($args[0]); |
|
125 | + $date = isset($assoc_args['expires']) ? $assoc_args['expires'] : null; |
|
126 | 126 | |
127 | - $notify = \WP_CLI\Utils\make_progress_bar( 'Generating sessions', $count ); |
|
127 | + $notify = \WP_CLI\Utils\make_progress_bar('Generating sessions', $count); |
|
128 | 128 | |
129 | - for ( $i = 0; $i < $count; $i ++ ) { |
|
130 | - WP_Session_Utils::create_dummy_session( $date ); |
|
129 | + for ($i = 0; $i < $count; $i++) { |
|
130 | + WP_Session_Utils::create_dummy_session($date); |
|
131 | 131 | $notify->tick(); |
132 | 132 | } |
133 | 133 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | global $wp_object_cache, $wpdb; |
145 | 145 | $wpdb->queries = array(); |
146 | 146 | |
147 | - if ( ! is_object( $wp_object_cache ) ) { |
|
147 | + if (!is_object($wp_object_cache)) { |
|
148 | 148 | return; |
149 | 149 | } |
150 | 150 | |
@@ -155,4 +155,4 @@ discard block |
||
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
158 | -\WP_CLI::add_command( 'session', 'WP_Session_Command' ); |
|
159 | 158 | \ No newline at end of file |
159 | +\WP_CLI::add_command('session', 'WP_Session_Command'); |
|
160 | 160 | \ No newline at end of file |
@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @param string $data |
35 | 35 | */ |
36 | -function wp_session_decode( $data ) { |
|
36 | +function wp_session_decode($data) { |
|
37 | 37 | $wp_session = WP_Session::get_instance(); |
38 | 38 | |
39 | - return $wp_session->json_in( $data ); |
|
39 | + return $wp_session->json_in($data); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return bool |
59 | 59 | */ |
60 | -function wp_session_regenerate_id( $delete_old_session = false ) { |
|
60 | +function wp_session_regenerate_id($delete_old_session = false) { |
|
61 | 61 | $wp_session = WP_Session::get_instance(); |
62 | 62 | |
63 | - $wp_session->regenerate_id( $delete_old_session ); |
|
63 | + $wp_session->regenerate_id($delete_old_session); |
|
64 | 64 | |
65 | 65 | return true; |
66 | 66 | } |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | */ |
75 | 75 | function wp_session_start() { |
76 | 76 | $wp_session = WP_Session::get_instance(); |
77 | - do_action( 'wp_session_start' ); |
|
77 | + do_action('wp_session_start'); |
|
78 | 78 | |
79 | 79 | return $wp_session->session_started(); |
80 | 80 | } |
81 | -if ( ! defined( 'WP_CLI' ) || false === WP_CLI ) { |
|
82 | - add_action( 'plugins_loaded', 'wp_session_start' ); |
|
81 | +if (!defined('WP_CLI') || false === WP_CLI) { |
|
82 | + add_action('plugins_loaded', 'wp_session_start'); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | function wp_session_status() { |
91 | 91 | $wp_session = WP_Session::get_instance(); |
92 | 92 | |
93 | - if ( $wp_session->session_started() ) { |
|
93 | + if ($wp_session->session_started()) { |
|
94 | 94 | return PHP_SESSION_ACTIVE; |
95 | 95 | } |
96 | 96 | |
@@ -113,10 +113,10 @@ discard block |
||
113 | 113 | $wp_session = WP_Session::get_instance(); |
114 | 114 | |
115 | 115 | $wp_session->write_data(); |
116 | - do_action( 'wp_session_commit' ); |
|
116 | + do_action('wp_session_commit'); |
|
117 | 117 | } |
118 | -if ( ! defined( 'WP_CLI' ) || false === WP_CLI ) { |
|
119 | - add_action( 'shutdown', 'wp_session_write_close' ); |
|
118 | +if (!defined('WP_CLI') || false === WP_CLI) { |
|
119 | + add_action('shutdown', 'wp_session_write_close'); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -127,33 +127,33 @@ discard block |
||
127 | 127 | * of a scheduled task or cron job. |
128 | 128 | */ |
129 | 129 | function wp_session_cleanup() { |
130 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
130 | + if (defined('WP_SETUP_CONFIG')) { |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | - if ( ! defined( 'WP_INSTALLING' ) ) { |
|
134 | + if (!defined('WP_INSTALLING')) { |
|
135 | 135 | /** |
136 | 136 | * Determine the size of each batch for deletion. |
137 | 137 | * |
138 | 138 | * @param int |
139 | 139 | */ |
140 | - $batch_size = apply_filters( 'wp_session_delete_batch_size', 1000 ); |
|
140 | + $batch_size = apply_filters('wp_session_delete_batch_size', 1000); |
|
141 | 141 | |
142 | 142 | // Delete a batch of old sessions |
143 | - WP_Session_Utils::delete_old_sessions( $batch_size ); |
|
143 | + WP_Session_Utils::delete_old_sessions($batch_size); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | // Allow other plugins to hook in to the garbage collection process. |
147 | - do_action( 'wp_session_cleanup' ); |
|
147 | + do_action('wp_session_cleanup'); |
|
148 | 148 | } |
149 | -add_action( 'wp_session_garbage_collection', 'wp_session_cleanup' ); |
|
149 | +add_action('wp_session_garbage_collection', 'wp_session_cleanup'); |
|
150 | 150 | |
151 | 151 | /** |
152 | 152 | * Register the garbage collector as a twice daily event. |
153 | 153 | */ |
154 | 154 | function wp_session_register_garbage_collection() { |
155 | - if ( ! wp_next_scheduled( 'wp_session_garbage_collection' ) ) { |
|
156 | - wp_schedule_event( time(), 'hourly', 'wp_session_garbage_collection' ); |
|
155 | + if (!wp_next_scheduled('wp_session_garbage_collection')) { |
|
156 | + wp_schedule_event(time(), 'hourly', 'wp_session_garbage_collection'); |
|
157 | 157 | } |
158 | 158 | } |
159 | -add_action( 'wp', 'wp_session_register_garbage_collection' ); |
|
159 | +add_action('wp', 'wp_session_register_garbage_collection'); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * @return bool|WP_Session |
54 | 54 | */ |
55 | 55 | public static function get_instance() { |
56 | - if ( ! self::$instance ) { |
|
56 | + if (!self::$instance) { |
|
57 | 57 | self::$instance = new self(); |
58 | 58 | } |
59 | 59 | |
@@ -69,19 +69,19 @@ discard block |
||
69 | 69 | * @uses apply_filters Calls `wp_session_expiration` to determine how long until sessions expire. |
70 | 70 | */ |
71 | 71 | protected function __construct() { |
72 | - if ( isset( $_COOKIE[WP_SESSION_COOKIE] ) ) { |
|
73 | - $cookie = stripslashes( $_COOKIE[WP_SESSION_COOKIE] ); |
|
74 | - $cookie_crumbs = explode( '||', $cookie ); |
|
72 | + if (isset($_COOKIE[WP_SESSION_COOKIE])) { |
|
73 | + $cookie = stripslashes($_COOKIE[WP_SESSION_COOKIE]); |
|
74 | + $cookie_crumbs = explode('||', $cookie); |
|
75 | 75 | |
76 | - $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0] ); |
|
77 | - $this->expires = absint( $cookie_crumbs[1] ); |
|
78 | - $this->exp_variant = absint( $cookie_crumbs[2] ); |
|
76 | + $this->session_id = preg_replace("/[^A-Za-z0-9_]/", '', $cookie_crumbs[0]); |
|
77 | + $this->expires = absint($cookie_crumbs[1]); |
|
78 | + $this->exp_variant = absint($cookie_crumbs[2]); |
|
79 | 79 | |
80 | 80 | // Update the session expiration if we're past the variant time |
81 | - if ( time() > $this->exp_variant ) { |
|
81 | + if (time() > $this->exp_variant) { |
|
82 | 82 | $this->set_expiration(); |
83 | - delete_option( "_wp_session_expires_{$this->session_id}" ); |
|
84 | - add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
83 | + delete_option("_wp_session_expires_{$this->session_id}"); |
|
84 | + add_option("_wp_session_expires_{$this->session_id}", $this->expires, '', 'no'); |
|
85 | 85 | } |
86 | 86 | } else { |
87 | 87 | $this->session_id = WP_Session_Utils::generate_id(); |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | * @uses apply_filters Calls `wp_session_expiration` to get the standard expiration time for sessions. |
114 | 114 | */ |
115 | 115 | protected function set_expiration() { |
116 | - $this->exp_variant = time() + (int) apply_filters( 'wp_session_expiration_variant', 24 * 60 ); |
|
117 | - $this->expires = time() + (int) apply_filters( 'wp_session_expiration', 30 * 60 ); |
|
116 | + $this->exp_variant = time() + (int)apply_filters('wp_session_expiration_variant', 24 * 60); |
|
117 | + $this->expires = time() + (int)apply_filters('wp_session_expiration', 30 * 60); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -123,13 +123,13 @@ discard block |
||
123 | 123 | * @uses apply_filters Calls `wp_session_cookie_httponly` to set the $httponly parameter of setcookie() |
124 | 124 | */ |
125 | 125 | protected function set_cookie() { |
126 | - if ( !defined( 'WPI_TESTING_MODE' ) ) { |
|
126 | + if (!defined('WPI_TESTING_MODE')) { |
|
127 | 127 | try { |
128 | 128 | $secure = apply_filters('wp_session_cookie_secure', false); |
129 | 129 | $httponly = apply_filters('wp_session_cookie_httponly', false); |
130 | - setcookie( WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant , $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly ); |
|
131 | - } catch(Exception $e) { |
|
132 | - error_log( 'Set Cookie Error: ' . $e->getMessage() ); |
|
130 | + setcookie(WP_SESSION_COOKIE, $this->session_id . '||' . $this->expires . '||' . $this->exp_variant, $this->expires, COOKIEPATH, COOKIE_DOMAIN, $secure, $httponly); |
|
131 | + } catch (Exception $e) { |
|
132 | + error_log('Set Cookie Error: ' . $e->getMessage()); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @return array |
143 | 143 | */ |
144 | 144 | protected function read_data() { |
145 | - $this->container = get_option( "_wp_session_{$this->session_id}", array() ); |
|
145 | + $this->container = get_option("_wp_session_{$this->session_id}", array()); |
|
146 | 146 | |
147 | 147 | return $this->container; |
148 | 148 | } |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | public function write_data() { |
154 | 154 | $option_key = "_wp_session_{$this->session_id}"; |
155 | 155 | |
156 | - if ( false === get_option( $option_key ) ) { |
|
157 | - add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
158 | - add_option( "_wp_session_expires_{$this->session_id}", $this->expires, '', 'no' ); |
|
156 | + if (false === get_option($option_key)) { |
|
157 | + add_option("_wp_session_{$this->session_id}", $this->container, '', 'no'); |
|
158 | + add_option("_wp_session_expires_{$this->session_id}", $this->expires, '', 'no'); |
|
159 | 159 | } else { |
160 | - delete_option( "_wp_session_{$this->session_id}" ); |
|
161 | - add_option( "_wp_session_{$this->session_id}", $this->container, '', 'no' ); |
|
160 | + delete_option("_wp_session_{$this->session_id}"); |
|
161 | + add_option("_wp_session_{$this->session_id}", $this->container, '', 'no'); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @return string |
169 | 169 | */ |
170 | 170 | public function json_out() { |
171 | - return json_encode( $this->container ); |
|
171 | + return json_encode($this->container); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -178,10 +178,10 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @return bool |
180 | 180 | */ |
181 | - public function json_in( $data ) { |
|
182 | - $array = json_decode( $data ); |
|
181 | + public function json_in($data) { |
|
182 | + $array = json_decode($data); |
|
183 | 183 | |
184 | - if ( is_array( $array ) ) { |
|
184 | + if (is_array($array)) { |
|
185 | 185 | $this->container = $array; |
186 | 186 | return true; |
187 | 187 | } |
@@ -194,9 +194,9 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @param bool $delete_old Flag whether or not to delete the old session data from the server. |
196 | 196 | */ |
197 | - public function regenerate_id( $delete_old = false ) { |
|
198 | - if ( $delete_old ) { |
|
199 | - delete_option( "_wp_session_{$this->session_id}" ); |
|
197 | + public function regenerate_id($delete_old = false) { |
|
198 | + if ($delete_old) { |
|
199 | + delete_option("_wp_session_{$this->session_id}"); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | $this->session_id = WP_Session_Utils::generate_id(); |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @param array $data |
38 | 38 | */ |
39 | - protected function __construct( $data = array() ) { |
|
40 | - foreach ( $data as $key => $value ) { |
|
41 | - $this[ $key ] = $value; |
|
39 | + protected function __construct($data = array()) { |
|
40 | + foreach ($data as $key => $value) { |
|
41 | + $this[$key] = $value; |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | * Allow deep copies of objects |
47 | 47 | */ |
48 | 48 | public function __clone() { |
49 | - foreach ( $this->container as $key => $value ) { |
|
50 | - if ( $value instanceof self ) { |
|
51 | - $this[ $key ] = clone $value; |
|
49 | + foreach ($this->container as $key => $value) { |
|
50 | + if ($value instanceof self) { |
|
51 | + $this[$key] = clone $value; |
|
52 | 52 | } |
53 | 53 | } |
54 | 54 | } |
@@ -60,9 +60,9 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function toArray() { |
62 | 62 | $data = $this->container; |
63 | - foreach ( $data as $key => $value ) { |
|
64 | - if ( $value instanceof self ) { |
|
65 | - $data[ $key ] = $value->toArray(); |
|
63 | + foreach ($data as $key => $value) { |
|
64 | + if ($value instanceof self) { |
|
65 | + $data[$key] = $value->toArray(); |
|
66 | 66 | } |
67 | 67 | } |
68 | 68 | return $data; |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return boolean true on success or false on failure. |
83 | 83 | */ |
84 | - public function offsetExists( $offset ) { |
|
85 | - return isset( $this->container[ $offset ]) ; |
|
84 | + public function offsetExists($offset) { |
|
85 | + return isset($this->container[$offset]); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return mixed Can return all value types. |
96 | 96 | */ |
97 | - public function offsetGet( $offset ) { |
|
98 | - return isset( $this->container[ $offset ] ) ? $this->container[ $offset ] : null; |
|
97 | + public function offsetGet($offset) { |
|
98 | + return isset($this->container[$offset]) ? $this->container[$offset] : null; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return void |
110 | 110 | */ |
111 | - public function offsetSet( $offset, $data ) { |
|
112 | - if ( is_array( $data ) ) { |
|
113 | - $data = new self( $data ); |
|
111 | + public function offsetSet($offset, $data) { |
|
112 | + if (is_array($data)) { |
|
113 | + $data = new self($data); |
|
114 | 114 | } |
115 | - if ( $offset === null ) { // don't forget this! |
|
115 | + if ($offset === null) { // don't forget this! |
|
116 | 116 | $this->container[] = $data; |
117 | 117 | } else { |
118 | - $this->container[ $offset ] = $data; |
|
118 | + $this->container[$offset] = $data; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | $this->dirty = true; |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @return void |
132 | 132 | */ |
133 | - public function offsetUnset( $offset ) { |
|
134 | - unset( $this->container[ $offset ] ); |
|
133 | + public function offsetUnset($offset) { |
|
134 | + unset($this->container[$offset]); |
|
135 | 135 | |
136 | 136 | $this->dirty = true; |
137 | 137 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return mixed |
150 | 150 | */ |
151 | 151 | public function current() { |
152 | - return current( $this->container ); |
|
152 | + return current($this->container); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @return mixed |
161 | 161 | */ |
162 | 162 | public function key() { |
163 | - return key( $this->container ); |
|
163 | + return key($this->container); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @return void |
172 | 172 | */ |
173 | 173 | public function next() { |
174 | - next( $this->container ); |
|
174 | + next($this->container); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @return void |
183 | 183 | */ |
184 | 184 | public function rewind() { |
185 | - reset( $this->container ); |
|
185 | + reset($this->container); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @return bool |
194 | 194 | */ |
195 | 195 | public function valid() { |
196 | - return $this->offsetExists( $this->key() ); |
|
196 | + return $this->offsetExists($this->key()); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | /*****************************************************************/ |
@@ -208,6 +208,6 @@ discard block |
||
208 | 208 | * @return int |
209 | 209 | */ |
210 | 210 | public function count() { |
211 | - return count( $this->container ); |
|
211 | + return count($this->container); |
|
212 | 212 | } |
213 | 213 | } |