@@ -1,121 +1,121 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | function wpinv_use_taxes() { |
8 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
8 | + $ret = wpinv_get_option('enable_taxes', false); |
|
9 | 9 | |
10 | - return (bool) apply_filters( 'wpinv_use_taxes', $ret ); |
|
10 | + return (bool) apply_filters('wpinv_use_taxes', $ret); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | function wpinv_get_tax_rates() { |
14 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
14 | + $rates = get_option('wpinv_tax_rates', array()); |
|
15 | 15 | |
16 | - return apply_filters( 'wpinv_get_tax_rates', $rates ); |
|
16 | + return apply_filters('wpinv_get_tax_rates', $rates); |
|
17 | 17 | } |
18 | 18 | |
19 | -function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) { |
|
19 | +function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) { |
|
20 | 20 | global $wpinv_euvat, $wpi_tax_rates, $wpi_userID; |
21 | - $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array(); |
|
21 | + $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array(); |
|
22 | 22 | |
23 | - if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) { |
|
23 | + if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) { |
|
24 | 24 | return $wpi_tax_rates[$item_id]; |
25 | 25 | } |
26 | 26 | |
27 | - if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) { |
|
27 | + if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) { |
|
28 | 28 | $wpi_tax_rates[$item_id] = 0; |
29 | 29 | return 0; |
30 | 30 | } |
31 | 31 | |
32 | 32 | $is_global = false; |
33 | - if ( $item_id == 'global' ) { |
|
33 | + if ($item_id == 'global') { |
|
34 | 34 | $is_global = true; |
35 | 35 | $item_id = 0; |
36 | 36 | } |
37 | 37 | |
38 | - $rate = (float)wpinv_get_option( 'tax_rate', 0 ); |
|
39 | - $user_address = wpinv_get_user_address( $wpi_userID ); |
|
38 | + $rate = (float) wpinv_get_option('tax_rate', 0); |
|
39 | + $user_address = wpinv_get_user_address($wpi_userID); |
|
40 | 40 | |
41 | - if( empty( $country ) ) { |
|
42 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
41 | + if (empty($country)) { |
|
42 | + if (!empty($_POST['wpinv_country'])) { |
|
43 | 43 | $country = $_POST['wpinv_country']; |
44 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
44 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
45 | 45 | $country = $_POST['wpinv_country']; |
46 | - } elseif( !empty( $_POST['country'] ) ) { |
|
46 | + } elseif (!empty($_POST['country'])) { |
|
47 | 47 | $country = $_POST['country']; |
48 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
48 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
49 | 49 | $country = $user_address['country']; |
50 | 50 | } |
51 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
51 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
52 | 52 | } |
53 | 53 | |
54 | - if( empty( $state ) ) { |
|
55 | - if( !empty( $_POST['wpinv_state'] ) ) { |
|
54 | + if (empty($state)) { |
|
55 | + if (!empty($_POST['wpinv_state'])) { |
|
56 | 56 | $state = $_POST['wpinv_state']; |
57 | - } elseif( !empty( $_POST['wpinv_state'] ) ) { |
|
57 | + } elseif (!empty($_POST['wpinv_state'])) { |
|
58 | 58 | $state = $_POST['wpinv_state']; |
59 | - } elseif( !empty( $_POST['state'] ) ) { |
|
59 | + } elseif (!empty($_POST['state'])) { |
|
60 | 60 | $state = $_POST['state']; |
61 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
61 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
62 | 62 | $state = $user_address['state']; |
63 | 63 | } |
64 | - $state = !empty( $state ) ? $state : wpinv_get_default_state(); |
|
64 | + $state = !empty($state) ? $state : wpinv_get_default_state(); |
|
65 | 65 | } |
66 | 66 | |
67 | - if( !empty( $country ) ) { |
|
68 | - $tax_rates = wpinv_get_tax_rates(); |
|
67 | + if (!empty($country)) { |
|
68 | + $tax_rates = wpinv_get_tax_rates(); |
|
69 | 69 | |
70 | - if( !empty( $tax_rates ) ) { |
|
70 | + if (!empty($tax_rates)) { |
|
71 | 71 | // Locate the tax rate for this country / state, if it exists |
72 | - foreach( $tax_rates as $key => $tax_rate ) { |
|
73 | - if( $country != $tax_rate['country'] ) |
|
72 | + foreach ($tax_rates as $key => $tax_rate) { |
|
73 | + if ($country != $tax_rate['country']) |
|
74 | 74 | continue; |
75 | 75 | |
76 | - if( !empty( $tax_rate['global'] ) ) { |
|
77 | - if( !empty( $tax_rate['rate'] ) ) { |
|
78 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
76 | + if (!empty($tax_rate['global'])) { |
|
77 | + if (!empty($tax_rate['rate'])) { |
|
78 | + $rate = number_format($tax_rate['rate'], 4); |
|
79 | 79 | } |
80 | 80 | } else { |
81 | 81 | |
82 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
82 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
83 | 83 | continue; |
84 | 84 | |
85 | 85 | $state_rate = $tax_rate['rate']; |
86 | - if( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
87 | - $rate = number_format( $state_rate, 4 ); |
|
86 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
87 | + $rate = number_format($state_rate, 4); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id ); |
|
94 | + $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id); |
|
95 | 95 | |
96 | - if ( !empty( $item_id ) ) { |
|
96 | + if (!empty($item_id)) { |
|
97 | 97 | $wpi_tax_rates[$item_id] = $rate; |
98 | - } else if ( $is_global ) { |
|
98 | + } else if ($is_global) { |
|
99 | 99 | $wpi_tax_rates['global'] = $rate; |
100 | 100 | } |
101 | 101 | |
102 | 102 | return $rate; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) { |
|
106 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
107 | - $rate = round( $rate, 4 ); |
|
105 | +function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) { |
|
106 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
107 | + $rate = round($rate, 4); |
|
108 | 108 | $formatted = $rate .= '%'; |
109 | - return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id ); |
|
109 | + return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id); |
|
110 | 110 | } |
111 | 111 | |
112 | -function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) { |
|
113 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
112 | +function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) { |
|
113 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
114 | 114 | $tax = 0.00; |
115 | 115 | |
116 | - if ( wpinv_use_taxes() ) { |
|
117 | - if ( wpinv_prices_include_tax() ) { |
|
118 | - $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) ); |
|
116 | + if (wpinv_use_taxes()) { |
|
117 | + if (wpinv_prices_include_tax()) { |
|
118 | + $pre_tax = ($amount / ((1 + $rate) * 0.01)); |
|
119 | 119 | $tax = $amount - $pre_tax; |
120 | 120 | } else { |
121 | 121 | $tax = $amount * $rate * 0.01; |
@@ -123,46 +123,46 @@ discard block |
||
123 | 123 | |
124 | 124 | } |
125 | 125 | |
126 | - return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id ); |
|
126 | + return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | function wpinv_prices_include_tax() { |
130 | 130 | return false; // TODO |
131 | - $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
131 | + $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_prices_include_tax', $ret ); |
|
133 | + return apply_filters('wpinv_prices_include_tax', $ret); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
137 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
136 | +function wpinv_sales_tax_for_year($year = null) { |
|
137 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
140 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
141 | 141 | global $wpdb; |
142 | 142 | |
143 | 143 | // Start at zero |
144 | 144 | $tax = 0; |
145 | 145 | |
146 | - if ( ! empty( $year ) ) { |
|
146 | + if (!empty($year)) { |
|
147 | 147 | $args = array( |
148 | 148 | 'post_type' => 'wpi_invoice', |
149 | - 'post_status' => array( 'publish' ), |
|
149 | + 'post_status' => array('publish'), |
|
150 | 150 | 'posts_per_page' => -1, |
151 | 151 | 'year' => $year, |
152 | 152 | 'fields' => 'ids' |
153 | 153 | ); |
154 | 154 | |
155 | - $payments = get_posts( $args ); |
|
156 | - $payment_ids = implode( ',', $payments ); |
|
155 | + $payments = get_posts($args); |
|
156 | + $payment_ids = implode(',', $payments); |
|
157 | 157 | |
158 | - if ( count( $payments ) > 0 ) { |
|
158 | + if (count($payments) > 0) { |
|
159 | 159 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
160 | - $tax = $wpdb->get_var( $sql ); |
|
160 | + $tax = $wpdb->get_var($sql); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
165 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | function wpinv_is_cart_taxed() { |
@@ -171,33 +171,33 @@ discard block |
||
171 | 171 | |
172 | 172 | function wpinv_prices_show_tax_on_checkout() { |
173 | 173 | return false; // TODO |
174 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
174 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
175 | 175 | |
176 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
176 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | function wpinv_display_tax_rate() { |
180 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
180 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
181 | 181 | |
182 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
182 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | function wpinv_cart_needs_tax_address_fields() { |
186 | - if( !wpinv_is_cart_taxed() ) |
|
186 | + if (!wpinv_is_cart_taxed()) |
|
187 | 187 | return false; |
188 | 188 | |
189 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
189 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
190 | 190 | } |
191 | 191 | |
192 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
193 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
194 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
192 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
193 | + $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
194 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
197 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
198 | 198 | $currency = wpinv_get_currency(); |
199 | 199 | |
200 | - switch ( $currency ) { |
|
200 | + switch ($currency) { |
|
201 | 201 | case 'RIAL' : |
202 | 202 | case 'JPY' : |
203 | 203 | case 'TWD' : |
@@ -206,48 +206,48 @@ discard block |
||
206 | 206 | break; |
207 | 207 | } |
208 | 208 | |
209 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
209 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_tax_amount() { |
213 | 213 | $output = 0.00; |
214 | 214 | |
215 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
215 | + return apply_filters('wpinv_tax_amount', $output); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | function wpinv_recalculated_tax() { |
219 | - define( 'WPINV_RECALCTAX', true ); |
|
219 | + define('WPINV_RECALCTAX', true); |
|
220 | 220 | } |
221 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 ); |
|
221 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1); |
|
222 | 222 | |
223 | -function wpinv_recalculate_tax( $return = false ) { |
|
224 | - $invoice_id = (int)wpinv_get_invoice_cart_id(); |
|
225 | - if ( empty( $invoice_id ) ) { |
|
223 | +function wpinv_recalculate_tax($return = false) { |
|
224 | + $invoice_id = (int) wpinv_get_invoice_cart_id(); |
|
225 | + if (empty($invoice_id)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
229 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
230 | 230 | |
231 | - if ( empty( $invoice ) ) { |
|
231 | + if (empty($invoice)) { |
|
232 | 232 | return false; |
233 | 233 | } |
234 | 234 | |
235 | - if ( empty( $_POST['country'] ) ) { |
|
235 | + if (empty($_POST['country'])) { |
|
236 | 236 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
237 | 237 | } |
238 | 238 | |
239 | 239 | $invoice->country = sanitize_text_field($_POST['country']); |
240 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
240 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
241 | 241 | if (isset($_POST['state'])) { |
242 | 242 | $invoice->state = sanitize_text_field($_POST['state']); |
243 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
243 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | $invoice->cart_details = wpinv_get_cart_content_details(); |
247 | 247 | |
248 | - $subtotal = wpinv_get_cart_subtotal( $invoice->cart_details ); |
|
249 | - $tax = wpinv_get_cart_tax( $invoice->cart_details ); |
|
250 | - $total = wpinv_get_cart_total( $invoice->cart_details ); |
|
248 | + $subtotal = wpinv_get_cart_subtotal($invoice->cart_details); |
|
249 | + $tax = wpinv_get_cart_tax($invoice->cart_details); |
|
250 | + $total = wpinv_get_cart_total($invoice->cart_details); |
|
251 | 251 | |
252 | 252 | $invoice->tax = $tax; |
253 | 253 | $invoice->subtotal = $subtotal; |
@@ -255,61 +255,61 @@ discard block |
||
255 | 255 | |
256 | 256 | $invoice->save(); |
257 | 257 | |
258 | - if ( $invoice->is_free_trial() ) { |
|
258 | + if ($invoice->is_free_trial()) { |
|
259 | 259 | $total = 0; |
260 | 260 | } |
261 | 261 | |
262 | 262 | $response = array( |
263 | - 'total' => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ), |
|
263 | + 'total' => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'), |
|
264 | 264 | 'total_raw' => $total, |
265 | - 'free' => !( (float)$total > 0 ) && $invoice->is_free() ? true : false, |
|
266 | - 'html' => wpinv_checkout_cart( $invoice->cart_details, false ), |
|
265 | + 'free' => !((float) $total > 0) && $invoice->is_free() ? true : false, |
|
266 | + 'html' => wpinv_checkout_cart($invoice->cart_details, false), |
|
267 | 267 | ); |
268 | 268 | |
269 | - if ( $return ) { |
|
269 | + if ($return) { |
|
270 | 270 | return $response; |
271 | 271 | } |
272 | 272 | |
273 | - wp_send_json( $response ); |
|
273 | + wp_send_json($response); |
|
274 | 274 | } |
275 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
276 | -add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
275 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
276 | +add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
277 | 277 | |
278 | 278 | // VAT Settings |
279 | -function wpinv_vat_rate_add_callback( $args ) { |
|
279 | +function wpinv_vat_rate_add_callback($args) { |
|
280 | 280 | ?> |
281 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
281 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
282 | 282 | <?php |
283 | 283 | } |
284 | 284 | |
285 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
285 | +function wpinv_vat_rate_delete_callback($args) { |
|
286 | 286 | global $wpinv_euvat; |
287 | 287 | |
288 | 288 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
289 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
290 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
289 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
290 | + if (isset($vat_classes[$vat_class])) { |
|
291 | 291 | ?> |
292 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
292 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
293 | 293 | <?php |
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
297 | -function wpinv_vat_rates_callback( $args ) { |
|
297 | +function wpinv_vat_rates_callback($args) { |
|
298 | 298 | global $wpinv_euvat; |
299 | 299 | |
300 | 300 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
301 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
301 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
302 | 302 | |
303 | 303 | $eu_states = $wpinv_euvat->get_eu_states(); |
304 | 304 | $countries = wpinv_get_country_list(); |
305 | 305 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
306 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
306 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
307 | 307 | ob_start(); |
308 | 308 | ?> |
309 | 309 | </td><tr> |
310 | 310 | <td colspan="2" class="wpinv_vat_tdbox"> |
311 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
312 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
311 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
312 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
313 | 313 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
314 | 314 | <colgroup> |
315 | 315 | <col width="50px" /> |
@@ -321,43 +321,43 @@ discard block |
||
321 | 321 | </colgroup> |
322 | 322 | <thead> |
323 | 323 | <tr> |
324 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
325 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
326 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
327 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
328 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
324 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
325 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
326 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
327 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
328 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
329 | 329 | </tr> |
330 | 330 | </thead> |
331 | 331 | <tbody> |
332 | - <?php if( !empty( $eu_states ) ) { ?> |
|
332 | + <?php if (!empty($eu_states)) { ?> |
|
333 | 333 | <?php |
334 | - foreach ( $eu_states as $state ) { |
|
335 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
334 | + foreach ($eu_states as $state) { |
|
335 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
336 | 336 | |
337 | 337 | // Filter the rate for each country |
338 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
338 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
339 | 339 | |
340 | 340 | // If one does not exist create a default |
341 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
341 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
342 | 342 | |
343 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
344 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
345 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
346 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
343 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
344 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
345 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
346 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
347 | 347 | ?> |
348 | 348 | <tr> |
349 | 349 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
350 | 350 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
351 | 351 | <td class="wpinv_vat_global"> |
352 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
353 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
354 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
352 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
353 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
354 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
355 | 355 | </td> |
356 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
357 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
356 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
357 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
358 | 358 | <td class="wpinv_vat_group"> |
359 | 359 | <?php |
360 | - echo wpinv_html_select( array( |
|
360 | + echo wpinv_html_select(array( |
|
361 | 361 | 'name' => 'vat_rates[' . $state . '][group]', |
362 | 362 | 'selected' => $vat_group, |
363 | 363 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -366,14 +366,14 @@ discard block |
||
366 | 366 | 'multiple' => false, |
367 | 367 | 'show_option_all' => false, |
368 | 368 | 'show_option_none' => false |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | ?> |
371 | 371 | </td> |
372 | 372 | </tr> |
373 | 373 | <?php } ?> |
374 | 374 | <tr> |
375 | 375 | <td colspan="6" style="background-color:#fafafa;"> |
376 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
376 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
377 | 377 | </td> |
378 | 378 | </tr> |
379 | 379 | <?php } ?> |
@@ -385,35 +385,35 @@ discard block |
||
385 | 385 | echo $content; |
386 | 386 | } |
387 | 387 | |
388 | -function wpinv_vat_number_callback( $args ) { |
|
388 | +function wpinv_vat_number_callback($args) { |
|
389 | 389 | global $wpinv_euvat; |
390 | 390 | |
391 | 391 | $vat_number = $wpinv_euvat->get_vat_number(); |
392 | 392 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
393 | 393 | |
394 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
395 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
394 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
395 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
396 | 396 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
397 | 397 | |
398 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
399 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
400 | - $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
|
401 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
402 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
398 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
399 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
400 | + $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int) $vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
|
401 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
402 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
403 | 403 | |
404 | 404 | echo $html; |
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
407 | +function wpinv_eu_fallback_rate_callback($args) { |
|
408 | 408 | global $wpinv_options; |
409 | 409 | |
410 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
411 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
410 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
411 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
412 | 412 | |
413 | - $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
414 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
415 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
416 | - $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
413 | + $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
414 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
415 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
416 | + $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
417 | 417 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
418 | 418 | echo $html; |
419 | 419 | ?> |
@@ -421,36 +421,36 @@ discard block |
||
421 | 421 | <?php |
422 | 422 | } |
423 | 423 | |
424 | -function wpinv_vat_ip_lookup_callback( $args ) { |
|
424 | +function wpinv_vat_ip_lookup_callback($args) { |
|
425 | 425 | global $wpinv_options, $wpinv_euvat; |
426 | 426 | |
427 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : 'default' ); |
|
427 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default'); |
|
428 | 428 | |
429 | 429 | $options = array(); |
430 | - if ( function_exists( 'geoip_country_code_by_name' ) ) { |
|
431 | - $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' ); |
|
430 | + if (function_exists('geoip_country_code_by_name')) { |
|
431 | + $options['geoip'] = __('PHP GeoIP extension', 'invoicing'); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | $geoip2_database = $wpinv_euvat->geoip2_country_dbfile(); |
435 | 435 | |
436 | - if ( !function_exists( 'bcadd' ) ) { |
|
437 | - $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' ); |
|
436 | + if (!function_exists('bcadd')) { |
|
437 | + $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing'); |
|
438 | 438 | } else { |
439 | - $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : ''; |
|
439 | + $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : ''; |
|
440 | 440 | } |
441 | 441 | |
442 | - if ( $geoip2_database !== false && empty( $geoip2_message ) ) { |
|
443 | - $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' ); |
|
442 | + if ($geoip2_database !== false && empty($geoip2_message)) { |
|
443 | + $options['geoip2'] = __('GeoIP2 Database', 'invoicing'); |
|
444 | 444 | } |
445 | 445 | |
446 | - if ( function_exists( 'simplexml_load_file' ) ) { |
|
447 | - $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' ); |
|
446 | + if (function_exists('simplexml_load_file')) { |
|
447 | + $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing'); |
|
448 | 448 | } |
449 | 449 | |
450 | - $options['site'] = __( 'Use default country', 'invoicing' ); |
|
451 | - $options['default'] = __( 'Auto', 'invoicing' ); |
|
450 | + $options['site'] = __('Use default country', 'invoicing'); |
|
451 | + $options['default'] = __('Auto', 'invoicing'); |
|
452 | 452 | |
453 | - $html = wpinv_html_select( array( |
|
453 | + $html = wpinv_html_select(array( |
|
454 | 454 | 'name' => "wpinv_settings[{$args['id']}]", |
455 | 455 | 'selected' => $value, |
456 | 456 | 'id' => "wpinv_settings[{$args['id']}]", |
@@ -462,23 +462,23 @@ discard block |
||
462 | 462 | )); |
463 | 463 | |
464 | 464 | $desc = '<label for="wpinv_settings[' . $args['id'] . ']">'; |
465 | - $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' ); |
|
465 | + $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing'); |
|
466 | 466 | $desc .= '<p>'; |
467 | - if ( empty( $geoip2_message ) ) { |
|
468 | - if ( $geoip2_database ) { |
|
467 | + if (empty($geoip2_message)) { |
|
468 | + if ($geoip2_database) { |
|
469 | 469 | $last_updated = ''; |
470 | - if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) { |
|
471 | - $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated ); |
|
472 | - $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated ); |
|
470 | + if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) { |
|
471 | + $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated); |
|
472 | + $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated); |
|
473 | 473 | } |
474 | - $desc .= __( 'GeoIP2 database exists:', 'invoicing' ) . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>'; |
|
474 | + $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>'; |
|
475 | 475 | } else { |
476 | - $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __( 'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' ); |
|
476 | + $desc .= __('GeoIP2 database does not exist:', 'invoicing') . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing'); |
|
477 | 477 | } |
478 | 478 | } else { |
479 | 479 | $desc .= $geoip2_message; |
480 | 480 | } |
481 | - $desc .= '</p><p>'. __( 'geoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
481 | + $desc .= '</p><p>' . __('geoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
482 | 482 | $desc .= '</label>'; |
483 | 483 | |
484 | 484 | $html .= $desc; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | 6 | global $wpinv_euvat, $ajax_cart_details; |
@@ -10,153 +10,153 @@ discard block |
||
10 | 10 | $invoice_id = $invoice->ID; |
11 | 11 | $quantities_enabled = wpinv_item_quantities_enabled(); |
12 | 12 | $use_taxes = wpinv_use_taxes(); |
13 | -$zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
|
14 | -$tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
15 | -$tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
13 | +$zero_tax = !(float) $invoice->get_tax() > 0 ? true : false; |
|
14 | +$tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
15 | +$tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
16 | 16 | |
17 | -do_action( 'wpinv_before_email_items', $invoice ); ?> |
|
17 | +do_action('wpinv_before_email_items', $invoice); ?> |
|
18 | 18 | <div id="wpinv-email-items"> |
19 | - <h3 class="wpinv-items-t"><?php echo apply_filters( 'wpinv_email_items_title', __( 'Items', 'invoicing' ) ); ?></h3> |
|
19 | + <h3 class="wpinv-items-t"><?php echo apply_filters('wpinv_email_items_title', __('Items', 'invoicing')); ?></h3> |
|
20 | 20 | <table id="wpinv_checkout_cart" class="table table-bordered table-hover"> |
21 | 21 | <thead> |
22 | 22 | <tr class="wpinv_cart_header_row"> |
23 | - <?php do_action( 'wpinv_email_items_table_header_first' ); ?> |
|
24 | - <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th> |
|
25 | - <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th> |
|
26 | - <?php if ( $quantities_enabled ) { ?> |
|
27 | - <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th> |
|
23 | + <?php do_action('wpinv_email_items_table_header_first'); ?> |
|
24 | + <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th> |
|
25 | + <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th> |
|
26 | + <?php if ($quantities_enabled) { ?> |
|
27 | + <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th> |
|
28 | 28 | <?php } ?> |
29 | - <?php if ( !$zero_tax && $use_taxes ) { ?> |
|
29 | + <?php if (!$zero_tax && $use_taxes) { ?> |
|
30 | 30 | <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th> |
31 | 31 | <?php } ?> |
32 | - <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th> |
|
33 | - <?php do_action( 'wpinv_email_items_table_header_last' ); ?> |
|
32 | + <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th> |
|
33 | + <?php do_action('wpinv_email_items_table_header_last'); ?> |
|
34 | 34 | </tr> |
35 | 35 | </thead> |
36 | 36 | <tbody> |
37 | 37 | <?php |
38 | - do_action( 'wpinv_email_items_before' ); |
|
39 | - if ( $cart_items ) { |
|
40 | - foreach ( $cart_items as $key => $item ) { |
|
41 | - $wpi_item = $item['id'] ? new WPInv_Item( $item['id'] ) : NULL; |
|
38 | + do_action('wpinv_email_items_before'); |
|
39 | + if ($cart_items) { |
|
40 | + foreach ($cart_items as $key => $item) { |
|
41 | + $wpi_item = $item['id'] ? new WPInv_Item($item['id']) : NULL; |
|
42 | 42 | ?> |
43 | - <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>"> |
|
44 | - <?php do_action( 'wpinv_email_items_table_body_first', $item ); ?> |
|
43 | + <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>"> |
|
44 | + <?php do_action('wpinv_email_items_table_body_first', $item); ?> |
|
45 | 45 | <td class="wpinv_cart_item_name text-left"> |
46 | 46 | <?php |
47 | - if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) { |
|
47 | + if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) { |
|
48 | 48 | echo '<div class="wpinv_cart_item_image">'; |
49 | - echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) ); |
|
49 | + echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25))); |
|
50 | 50 | echo '</div>'; |
51 | 51 | } |
52 | - $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item ); |
|
52 | + $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item); |
|
53 | 53 | echo '<span class="wpinv_email_cart_item_title">' . $item_title . '</span>'; |
54 | 54 | |
55 | - $summary = apply_filters( 'wpinv_email_invoice_line_item_summary', '', $item, $wpi_item, $invoice ); |
|
56 | - if ( !empty( $summary ) ) { |
|
55 | + $summary = apply_filters('wpinv_email_invoice_line_item_summary', '', $item, $wpi_item, $invoice); |
|
56 | + if (!empty($summary)) { |
|
57 | 57 | echo '<p class="small">' . $summary . '</p>'; |
58 | 58 | } |
59 | 59 | |
60 | - do_action( 'wpinv_email_cart_item_title_after', $item, $key ); |
|
60 | + do_action('wpinv_email_cart_item_title_after', $item, $key); |
|
61 | 61 | ?> |
62 | 62 | </td> |
63 | 63 | <td class="wpinv_cart_item_price text-right"> |
64 | 64 | <?php |
65 | - echo wpinv_cart_item_price( $item ); |
|
66 | - do_action( 'wpinv_email_cart_item_price_after', $item, $key ); |
|
65 | + echo wpinv_cart_item_price($item); |
|
66 | + do_action('wpinv_email_cart_item_price_after', $item, $key); |
|
67 | 67 | ?> |
68 | 68 | </td> |
69 | - <?php if ( $quantities_enabled ) { ?> |
|
69 | + <?php if ($quantities_enabled) { ?> |
|
70 | 70 | <td class="wpinv_cart_item_qty text-right"> |
71 | 71 | <?php |
72 | - echo wpinv_get_cart_item_quantity( $item ); |
|
73 | - do_action( 'wpinv_email_item_quantitiy', $item, $key ); |
|
72 | + echo wpinv_get_cart_item_quantity($item); |
|
73 | + do_action('wpinv_email_item_quantitiy', $item, $key); |
|
74 | 74 | ?> |
75 | 75 | </td> |
76 | 76 | <?php } ?> |
77 | - <?php if ( !$zero_tax && $use_taxes ) { ?> |
|
77 | + <?php if (!$zero_tax && $use_taxes) { ?> |
|
78 | 78 | <td class="wpinv_cart_item_tax text-right"> |
79 | 79 | <?php |
80 | - echo wpinv_cart_item_tax( $item ); |
|
81 | - do_action( 'wpinv_email_item_tax', $item, $key ); |
|
80 | + echo wpinv_cart_item_tax($item); |
|
81 | + do_action('wpinv_email_item_tax', $item, $key); |
|
82 | 82 | ?> |
83 | 83 | </td> |
84 | 84 | <?php } ?> |
85 | 85 | <td class="wpinv_cart_item_subtotal text-right"> |
86 | 86 | <?php |
87 | - echo wpinv_cart_item_subtotal( $item ); |
|
88 | - do_action( 'wpinv_email_item_subtotal', $item, $key ); |
|
87 | + echo wpinv_cart_item_subtotal($item); |
|
88 | + do_action('wpinv_email_item_subtotal', $item, $key); |
|
89 | 89 | ?> |
90 | 90 | </td> |
91 | - <?php do_action( 'wpinv_email_items_table_body_last', $item, $key ); ?> |
|
91 | + <?php do_action('wpinv_email_items_table_body_last', $item, $key); ?> |
|
92 | 92 | </tr> |
93 | 93 | <?php } ?> |
94 | 94 | <?php } ?> |
95 | - <?php do_action( 'wpinv_email_items_middle' ); ?> |
|
96 | - <?php do_action( 'wpinv_email_items_after' ); ?> |
|
95 | + <?php do_action('wpinv_email_items_middle'); ?> |
|
96 | + <?php do_action('wpinv_email_items_after'); ?> |
|
97 | 97 | </tbody> |
98 | 98 | <tfoot> |
99 | - <?php $cart_columns = wpinv_checkout_cart_columns(); if ( $zero_tax && $use_taxes ) { $cart_columns--; } ?> |
|
100 | - <?php if ( has_action( 'wpinv_email_footer_buttons' ) ) { ?> |
|
99 | + <?php $cart_columns = wpinv_checkout_cart_columns(); if ($zero_tax && $use_taxes) { $cart_columns--; } ?> |
|
100 | + <?php if (has_action('wpinv_email_footer_buttons')) { ?> |
|
101 | 101 | <tr class="wpinv_cart_footer_row"> |
102 | - <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?> |
|
103 | - <td colspan="<?php echo ( $cart_columns ); ?>"> |
|
104 | - <?php do_action( 'wpinv_email_footer_buttons' ); ?> |
|
102 | + <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?> |
|
103 | + <td colspan="<?php echo ($cart_columns); ?>"> |
|
104 | + <?php do_action('wpinv_email_footer_buttons'); ?> |
|
105 | 105 | </td> |
106 | - <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?> |
|
106 | + <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?> |
|
107 | 107 | </tr> |
108 | 108 | <?php } ?> |
109 | 109 | |
110 | - <?php if ( !$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed() ) { ?> |
|
110 | + <?php if (!$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed()) { ?> |
|
111 | 111 | <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"> |
112 | - <?php do_action( 'wpinv_email_items_table_subtotal_first', $cart_items ); ?> |
|
113 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right"> |
|
114 | - <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong> |
|
112 | + <?php do_action('wpinv_email_items_table_subtotal_first', $cart_items); ?> |
|
113 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right"> |
|
114 | + <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong> |
|
115 | 115 | </td> |
116 | 116 | <td class="wpinv_cart_subtotal text-right"> |
117 | - <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal( true ); ?></span> |
|
117 | + <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal(true); ?></span> |
|
118 | 118 | </td> |
119 | - <?php do_action( 'wpinv_email_items_table_subtotal_last', $cart_items, $invoice ); ?> |
|
119 | + <?php do_action('wpinv_email_items_table_subtotal_last', $cart_items, $invoice); ?> |
|
120 | 120 | </tr> |
121 | 121 | <?php } ?> |
122 | 122 | |
123 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
123 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
124 | 124 | <tr class="wpinv_cart_footer_row wpinv_cart_discount_row"> |
125 | - <?php do_action( 'wpinv_receipt_items_table_discount_first', $cart_items, $invoice ); ?> |
|
126 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_discount_label text-right"> |
|
127 | - <strong><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</strong> |
|
125 | + <?php do_action('wpinv_receipt_items_table_discount_first', $cart_items, $invoice); ?> |
|
126 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_discount_label text-right"> |
|
127 | + <strong><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</strong> |
|
128 | 128 | </td> |
129 | 129 | <td class="wpinv_cart_discount text-right"> |
130 | - <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount( $invoice_id, true, true ); ?></span> |
|
130 | + <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount($invoice_id, true, true); ?></span> |
|
131 | 131 | </td> |
132 | - <?php do_action( 'wpinv_receipt_items_table_discount_last', $cart_items, $invoice ); ?> |
|
132 | + <?php do_action('wpinv_receipt_items_table_discount_last', $cart_items, $invoice); ?> |
|
133 | 133 | </tr> |
134 | 134 | <?php } ?> |
135 | 135 | |
136 | - <?php if ( !$zero_tax && $use_taxes && wpinv_is_cart_taxed() ) { ?> |
|
136 | + <?php if (!$zero_tax && $use_taxes && wpinv_is_cart_taxed()) { ?> |
|
137 | 137 | <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"> |
138 | - <?php do_action( 'wpinv_email_items_table_tax_first', $cart_items, $invoice ); ?> |
|
139 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right"> |
|
138 | + <?php do_action('wpinv_email_items_table_tax_first', $cart_items, $invoice); ?> |
|
139 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right"> |
|
140 | 140 | <strong><?php echo $tax_label; ?>:</strong> |
141 | 141 | </td> |
142 | 142 | <td class="wpinv_cart_tax text-right"> |
143 | - <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax( true ); ?></span> |
|
143 | + <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax(true); ?></span> |
|
144 | 144 | </td> |
145 | - <?php do_action( 'wpinv_email_items_table_tax_last', $cart_items, $invoice ); ?> |
|
145 | + <?php do_action('wpinv_email_items_table_tax_last', $cart_items, $invoice); ?> |
|
146 | 146 | </tr> |
147 | 147 | <?php } ?> |
148 | 148 | |
149 | 149 | <tr class="wpinv_cart_footer_row"> |
150 | - <?php do_action( 'wpinv_email_items_table_footer_first', $cart_items, $invoice ); ?> |
|
151 | - <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right"> |
|
152 | - <?php echo apply_filters( 'wpinv_email_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?> |
|
150 | + <?php do_action('wpinv_email_items_table_footer_first', $cart_items, $invoice); ?> |
|
151 | + <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right"> |
|
152 | + <?php echo apply_filters('wpinv_email_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?> |
|
153 | 153 | </td> |
154 | 154 | <td class="wpinv_cart_total text-right"> |
155 | - <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total( true ); ?></span> |
|
155 | + <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total(true); ?></span> |
|
156 | 156 | </td> |
157 | - <?php do_action( 'wpinv_email_items_table_footer_last', $cart_items, $invoice ); ?> |
|
157 | + <?php do_action('wpinv_email_items_table_footer_last', $cart_items, $invoice); ?> |
|
158 | 158 | </tr> |
159 | 159 | </tfoot> |
160 | 160 | </table> |
161 | 161 | </div> |
162 | -<?php do_action( 'wpinv_after_email_items', $invoice ); ?> |
|
163 | 162 | \ No newline at end of file |
163 | +<?php do_action('wpinv_after_email_items', $invoice); ?> |
|
164 | 164 | \ No newline at end of file |
@@ -4,17 +4,17 @@ discard block |
||
4 | 4 | */ |
5 | 5 | global $wpinv_receipt_args; |
6 | 6 | |
7 | -$invoice = get_post( $wpinv_receipt_args['id'] ); |
|
7 | +$invoice = get_post($wpinv_receipt_args['id']); |
|
8 | 8 | |
9 | -if( empty( $invoice ) ) { |
|
9 | +if (empty($invoice)) { |
|
10 | 10 | ?> |
11 | 11 | <div class="wpinv_errors alert wpi-alert-error"> |
12 | - <?php _e( 'The specified receipt ID appears to be invalid', 'invoicing' ); ?> |
|
12 | + <?php _e('The specified receipt ID appears to be invalid', 'invoicing'); ?> |
|
13 | 13 | </div> |
14 | 14 | <?php |
15 | 15 | return; |
16 | 16 | } |
17 | -$invoice = wpinv_get_invoice( $invoice->ID ); |
|
17 | +$invoice = wpinv_get_invoice($invoice->ID); |
|
18 | 18 | |
19 | 19 | global $ajax_cart_details; |
20 | 20 | $ajax_cart_details = $invoice->get_cart_details(); |
@@ -23,19 +23,19 @@ discard block |
||
23 | 23 | $invoice_id = $invoice->ID; |
24 | 24 | $quantities_enabled = wpinv_item_quantities_enabled(); |
25 | 25 | $use_taxes = wpinv_use_taxes(); |
26 | -$zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
|
27 | -$tax_label = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? __( '(Tax Incl.)', 'invoicing' ) : __( '(Tax Excl.)', 'invoicing' ) ) : ''; |
|
26 | +$zero_tax = !(float) $invoice->get_tax() > 0 ? true : false; |
|
27 | +$tax_label = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? __('(Tax Incl.)', 'invoicing') : __('(Tax Excl.)', 'invoicing')) : ''; |
|
28 | 28 | ?> |
29 | -<?php do_action( 'wpinv_before_receipt', $invoice ); ?> |
|
29 | +<?php do_action('wpinv_before_receipt', $invoice); ?> |
|
30 | 30 | <div class="wpinv-receipt"> |
31 | - <?php do_action( 'wpinv_receipt_start', $invoice ); ?> |
|
32 | - <div class="wpinv-receipt-message"><?php _e( 'Thank you for your payment!', 'invoicing' ); ?></div> |
|
33 | - <?php do_action( 'wpinv_before_receipt_details', $invoice ); ?> |
|
31 | + <?php do_action('wpinv_receipt_start', $invoice); ?> |
|
32 | + <div class="wpinv-receipt-message"><?php _e('Thank you for your payment!', 'invoicing'); ?></div> |
|
33 | + <?php do_action('wpinv_before_receipt_details', $invoice); ?> |
|
34 | 34 | <div class="wpinv-receipt-details"> |
35 | - <h3 class="wpinv-details-t"><?php echo apply_filters( 'wpinv_receipt_details_title', __( 'Invoice Details', 'invoicing' ) ); ?></h3> |
|
36 | - <?php wpinv_display_invoice_details( $invoice ); ?> |
|
35 | + <h3 class="wpinv-details-t"><?php echo apply_filters('wpinv_receipt_details_title', __('Invoice Details', 'invoicing')); ?></h3> |
|
36 | + <?php wpinv_display_invoice_details($invoice); ?> |
|
37 | 37 | </div> |
38 | - <?php do_action( 'wpinv_after_receipt_details', $invoice ); ?> |
|
39 | - <?php do_action( 'wpinv_receipt_end', $invoice ); ?> |
|
38 | + <?php do_action('wpinv_after_receipt_details', $invoice); ?> |
|
39 | + <?php do_action('wpinv_receipt_end', $invoice); ?> |
|
40 | 40 | </div> |
41 | -<?php do_action( 'wpinv_after_receipt', $invoice ); ?> |
|
42 | 41 | \ No newline at end of file |
42 | +<?php do_action('wpinv_after_receipt', $invoice); ?> |
|
43 | 43 | \ No newline at end of file |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 1.0.13 |
9 | 9 | */ |
10 | 10 | |
11 | -if ( !defined( 'WPINC' ) ) { |
|
11 | +if (!defined('WPINC')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @param string $namespace Api Namespace |
43 | 43 | */ |
44 | - public function __construct( $namespace ) { |
|
44 | + public function __construct($namespace) { |
|
45 | 45 | |
46 | 46 | // Set api namespace... |
47 | 47 | $this->namespace = $namespace; |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | array( |
69 | 69 | array( |
70 | 70 | 'methods' => WP_REST_Server::READABLE, |
71 | - 'callback' => array( $this, 'get_item_types' ), |
|
71 | + 'callback' => array($this, 'get_item_types'), |
|
72 | 72 | ), |
73 | 73 | ) |
74 | 74 | ); |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | * @param WP_REST_Request $request Full details about the request. |
85 | 85 | * @return true|WP_Error True if the request has read access, WP_Error object otherwise. |
86 | 86 | */ |
87 | - public function get_items_permissions_check( $request ) { |
|
87 | + public function get_items_permissions_check($request) { |
|
88 | 88 | |
89 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_invoicing' ) ) { |
|
89 | + if (current_user_can('manage_options') || current_user_can('manage_invoicing')) { |
|
90 | 90 | return true; |
91 | 91 | } |
92 | 92 | |
93 | - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to view invoice items.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
93 | + return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to view invoice items.', 'invoicing'), array('status' => rest_authorization_required_code())); |
|
94 | 94 | |
95 | 95 | } |
96 | 96 | |
@@ -102,17 +102,17 @@ discard block |
||
102 | 102 | * @param WP_REST_Request $request Full details about the request. |
103 | 103 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
104 | 104 | */ |
105 | - public function get_items( $request ) { |
|
105 | + public function get_items($request) { |
|
106 | 106 | |
107 | 107 | // Retrieve the list of registered item query parameters. |
108 | 108 | $registered = $this->get_collection_params(); |
109 | 109 | |
110 | 110 | $args = array(); |
111 | 111 | |
112 | - foreach( array_keys( $registered ) as $key ) { |
|
112 | + foreach (array_keys($registered) as $key) { |
|
113 | 113 | |
114 | - if( isset( $request[ $key] ) ) { |
|
115 | - $args[ $key ] = $request[ $key]; |
|
114 | + if (isset($request[$key])) { |
|
115 | + $args[$key] = $request[$key]; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | } |
@@ -127,32 +127,32 @@ discard block |
||
127 | 127 | * @param array $args Key value array of query var to query value. |
128 | 128 | * @param WP_REST_Request $request The request used. |
129 | 129 | */ |
130 | - $args = apply_filters( "wpinv_rest_get_items_arguments", $args, $request, $this ); |
|
130 | + $args = apply_filters("wpinv_rest_get_items_arguments", $args, $request, $this); |
|
131 | 131 | |
132 | 132 | // Special args |
133 | - $args[ 'return' ] = 'objects'; |
|
134 | - $args[ 'paginate' ] = true; |
|
133 | + $args['return'] = 'objects'; |
|
134 | + $args['paginate'] = true; |
|
135 | 135 | |
136 | 136 | // Run the query. |
137 | - $query = wpinv_get_all_items( $args ); |
|
137 | + $query = wpinv_get_all_items($args); |
|
138 | 138 | |
139 | 139 | // Prepare the retrieved items |
140 | 140 | $items = array(); |
141 | - foreach( $query->items as $item ) { |
|
141 | + foreach ($query->items as $item) { |
|
142 | 142 | |
143 | - if ( ! $this->check_read_permission( $item ) ) { |
|
143 | + if (!$this->check_read_permission($item)) { |
|
144 | 144 | continue; |
145 | 145 | } |
146 | 146 | |
147 | - $data = $this->prepare_item_for_response( $item, $request ); |
|
148 | - $items[] = $this->prepare_response_for_collection( $data ); |
|
147 | + $data = $this->prepare_item_for_response($item, $request); |
|
148 | + $items[] = $this->prepare_response_for_collection($data); |
|
149 | 149 | |
150 | 150 | } |
151 | 151 | |
152 | 152 | // Prepare the response. |
153 | - $response = rest_ensure_response( $items ); |
|
154 | - $response->header( 'X-WP-Total', (int) $query->total ); |
|
155 | - $response->header( 'X-WP-TotalPages', (int) $query->max_num_pages ); |
|
153 | + $response = rest_ensure_response($items); |
|
154 | + $response->header('X-WP-Total', (int) $query->total); |
|
155 | + $response->header('X-WP-TotalPages', (int) $query->max_num_pages); |
|
156 | 156 | |
157 | 157 | /** |
158 | 158 | * Filters the responses for item requests. |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | * @param WP_REST_Request $request The request used. |
166 | 166 | * @param array $args Array of args used to retrieve the items |
167 | 167 | */ |
168 | - $response = apply_filters( "wpinv_rest_items_response", $response, $request, $args ); |
|
168 | + $response = apply_filters("wpinv_rest_items_response", $response, $request, $args); |
|
169 | 169 | |
170 | - return rest_ensure_response( $response ); |
|
170 | + return rest_ensure_response($response); |
|
171 | 171 | |
172 | 172 | } |
173 | 173 | |
@@ -179,17 +179,17 @@ discard block |
||
179 | 179 | * @param int $item_id Supplied ID. |
180 | 180 | * @return WPInv_Item|WP_Error Item object if ID is valid, WP_Error otherwise. |
181 | 181 | */ |
182 | - protected function get_post( $item_id ) { |
|
182 | + protected function get_post($item_id) { |
|
183 | 183 | |
184 | - $error = new WP_Error( 'rest_item_invalid_id', __( 'Invalid item ID.', 'invoicing' ), array( 'status' => 404 ) ); |
|
184 | + $error = new WP_Error('rest_item_invalid_id', __('Invalid item ID.', 'invoicing'), array('status' => 404)); |
|
185 | 185 | |
186 | 186 | // Ids start from 1 |
187 | - if ( (int) $item_id <= 0 ) { |
|
187 | + if ((int) $item_id <= 0) { |
|
188 | 188 | return $error; |
189 | 189 | } |
190 | 190 | |
191 | - $item = wpinv_get_item_by( 'id', (int) $item_id ); |
|
192 | - if ( empty( $item ) ) { |
|
191 | + $item = wpinv_get_item_by('id', (int) $item_id); |
|
192 | + if (empty($item)) { |
|
193 | 193 | return $error; |
194 | 194 | } |
195 | 195 | |
@@ -205,29 +205,29 @@ discard block |
||
205 | 205 | * @param WP_REST_Request $request Full details about the request. |
206 | 206 | * @return bool|WP_Error True if the request has read access for the invoice item, WP_Error object otherwise. |
207 | 207 | */ |
208 | - public function get_item_permissions_check( $request ) { |
|
208 | + public function get_item_permissions_check($request) { |
|
209 | 209 | |
210 | 210 | // Retrieve the item object. |
211 | - $item = $this->get_post( $request['id'] ); |
|
211 | + $item = $this->get_post($request['id']); |
|
212 | 212 | |
213 | 213 | // Ensure it is valid. |
214 | - if ( is_wp_error( $item ) ) { |
|
214 | + if (is_wp_error($item)) { |
|
215 | 215 | return $item; |
216 | 216 | } |
217 | 217 | |
218 | - $post_type = get_post_type_object( $this->post_type ); |
|
218 | + $post_type = get_post_type_object($this->post_type); |
|
219 | 219 | |
220 | - if ( ! current_user_can( $post_type->cap->read_post, $item->ID ) ) { |
|
220 | + if (!current_user_can($post_type->cap->read_post, $item->ID)) { |
|
221 | 221 | return new WP_Error( |
222 | 222 | 'rest_cannot_edit', |
223 | - __( 'Sorry, you are not allowed to view this item.', 'invoicing' ), |
|
223 | + __('Sorry, you are not allowed to view this item.', 'invoicing'), |
|
224 | 224 | array( |
225 | 225 | 'status' => rest_authorization_required_code(), |
226 | 226 | ) |
227 | 227 | ); |
228 | 228 | } |
229 | 229 | |
230 | - return $this->check_read_permission( $item ); |
|
230 | + return $this->check_read_permission($item); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | /** |
@@ -241,10 +241,10 @@ discard block |
||
241 | 241 | * @param WPInv_Item $item WPInv_Item object. |
242 | 242 | * @return bool Whether the post can be read. |
243 | 243 | */ |
244 | - public function check_read_permission( $item ) { |
|
244 | + public function check_read_permission($item) { |
|
245 | 245 | |
246 | 246 | // An item can be read by an admin... |
247 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_invoicing' ) ) { |
|
247 | + if (current_user_can('manage_options') || current_user_can('manage_invoicing')) { |
|
248 | 248 | return true; |
249 | 249 | } |
250 | 250 | |
@@ -259,18 +259,18 @@ discard block |
||
259 | 259 | * @param WP_REST_Request $request Full details about the request. |
260 | 260 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
261 | 261 | */ |
262 | - public function get_item( $request ) { |
|
262 | + public function get_item($request) { |
|
263 | 263 | |
264 | 264 | // Fetch the item. |
265 | - $item = $this->get_post( $request['id'] ); |
|
265 | + $item = $this->get_post($request['id']); |
|
266 | 266 | |
267 | 267 | // Abort early if it does not exist |
268 | - if ( is_wp_error( $item ) ) { |
|
268 | + if (is_wp_error($item)) { |
|
269 | 269 | return $item; |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Prepare the response |
273 | - $response = $this->prepare_item_for_response( $item, $request ); |
|
273 | + $response = $this->prepare_item_for_response($item, $request); |
|
274 | 274 | |
275 | 275 | /** |
276 | 276 | * Filters the responses for single invoice item requests. |
@@ -282,9 +282,9 @@ discard block |
||
282 | 282 | * @param WP_HTTP_Response $response Response. |
283 | 283 | * @param WP_REST_Request $request The request used. |
284 | 284 | */ |
285 | - $response = apply_filters( "wpinv_rest_get_item_response", $response, $request ); |
|
285 | + $response = apply_filters("wpinv_rest_get_item_response", $response, $request); |
|
286 | 286 | |
287 | - return rest_ensure_response( $response ); |
|
287 | + return rest_ensure_response($response); |
|
288 | 288 | |
289 | 289 | } |
290 | 290 | |
@@ -296,21 +296,21 @@ discard block |
||
296 | 296 | * @param WP_REST_Request $request Full details about the request. |
297 | 297 | * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise. |
298 | 298 | */ |
299 | - public function create_item_permissions_check( $request ) { |
|
299 | + public function create_item_permissions_check($request) { |
|
300 | 300 | |
301 | - if ( ! empty( $request['id'] ) ) { |
|
302 | - return new WP_Error( 'rest_item_exists', __( 'Cannot create existing item.', 'invoicing' ), array( 'status' => 400 ) ); |
|
301 | + if (!empty($request['id'])) { |
|
302 | + return new WP_Error('rest_item_exists', __('Cannot create existing item.', 'invoicing'), array('status' => 400)); |
|
303 | 303 | } |
304 | 304 | |
305 | - if ( current_user_can( 'manage_options' ) || current_user_can( 'manage_invoicing' ) ) { |
|
305 | + if (current_user_can('manage_options') || current_user_can('manage_invoicing')) { |
|
306 | 306 | return true; |
307 | 307 | } |
308 | 308 | |
309 | - $post_type = get_post_type_object( $this->post_type ); |
|
310 | - if ( ! current_user_can( $post_type->cap->create_posts ) ) { |
|
309 | + $post_type = get_post_type_object($this->post_type); |
|
310 | + if (!current_user_can($post_type->cap->create_posts)) { |
|
311 | 311 | return new WP_Error( |
312 | 312 | 'rest_cannot_create', |
313 | - __( 'Sorry, you are not allowed to create invoice items as this user.', 'invoicing' ), |
|
313 | + __('Sorry, you are not allowed to create invoice items as this user.', 'invoicing'), |
|
314 | 314 | array( |
315 | 315 | 'status' => rest_authorization_required_code(), |
316 | 316 | ) |
@@ -328,30 +328,30 @@ discard block |
||
328 | 328 | * @param WP_REST_Request $request Full details about the request. |
329 | 329 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
330 | 330 | */ |
331 | - public function create_item( $request ) { |
|
331 | + public function create_item($request) { |
|
332 | 332 | |
333 | - if ( ! empty( $request['id'] ) ) { |
|
334 | - return new WP_Error( 'rest_item_exists', __( 'Cannot create existing invoice item.', 'invoicing' ), array( 'status' => 400 ) ); |
|
333 | + if (!empty($request['id'])) { |
|
334 | + return new WP_Error('rest_item_exists', __('Cannot create existing invoice item.', 'invoicing'), array('status' => 400)); |
|
335 | 335 | } |
336 | 336 | |
337 | - $request->set_param( 'context', 'edit' ); |
|
337 | + $request->set_param('context', 'edit'); |
|
338 | 338 | |
339 | 339 | // Prepare the updated data. |
340 | - $item_data = $this->prepare_item_for_database( $request ); |
|
340 | + $item_data = $this->prepare_item_for_database($request); |
|
341 | 341 | |
342 | - if ( is_wp_error( $item_data ) ) { |
|
342 | + if (is_wp_error($item_data)) { |
|
343 | 343 | return $item_data; |
344 | 344 | } |
345 | 345 | |
346 | 346 | // Try creating the item. |
347 | - $item = wpinv_create_item( $item_data, true ); |
|
347 | + $item = wpinv_create_item($item_data, true); |
|
348 | 348 | |
349 | - if ( is_wp_error( $item ) ) { |
|
349 | + if (is_wp_error($item)) { |
|
350 | 350 | return $item; |
351 | 351 | } |
352 | 352 | |
353 | 353 | // Prepare the response |
354 | - $response = $this->prepare_item_for_response( $item, $request ); |
|
354 | + $response = $this->prepare_item_for_response($item, $request); |
|
355 | 355 | |
356 | 356 | /** |
357 | 357 | * Fires after a single invoice item is created or updated via the REST API. |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | * @param WP_REST_Request $request Request object. |
363 | 363 | * @param bool $creating True when creating a post, false when updating. |
364 | 364 | */ |
365 | - do_action( "wpinv_rest_insert_item", $item, $request, true ); |
|
365 | + do_action("wpinv_rest_insert_item", $item, $request, true); |
|
366 | 366 | |
367 | 367 | /** |
368 | 368 | * Filters the responses for creating single item requests. |
@@ -374,9 +374,9 @@ discard block |
||
374 | 374 | * @param array $item_data Invoice properties. |
375 | 375 | * @param WP_REST_Request $request The request used. |
376 | 376 | */ |
377 | - $response = apply_filters( "wpinv_rest_create_item_response", $response, $request ); |
|
377 | + $response = apply_filters("wpinv_rest_create_item_response", $response, $request); |
|
378 | 378 | |
379 | - return rest_ensure_response( $response ); |
|
379 | + return rest_ensure_response($response); |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | /** |
@@ -387,21 +387,21 @@ discard block |
||
387 | 387 | * @param WP_REST_Request $request Full details about the request. |
388 | 388 | * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise. |
389 | 389 | */ |
390 | - public function update_item_permissions_check( $request ) { |
|
390 | + public function update_item_permissions_check($request) { |
|
391 | 391 | |
392 | 392 | // Retrieve the item. |
393 | - $item = $this->get_post( $request['id'] ); |
|
394 | - if ( is_wp_error( $item ) ) { |
|
393 | + $item = $this->get_post($request['id']); |
|
394 | + if (is_wp_error($item)) { |
|
395 | 395 | return $item; |
396 | 396 | } |
397 | 397 | |
398 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
398 | + if (wpinv_current_user_can_manage_invoicing()) { |
|
399 | 399 | return true; |
400 | 400 | } |
401 | 401 | |
402 | 402 | return new WP_Error( |
403 | 403 | 'rest_cannot_edit', |
404 | - __( 'Sorry, you are not allowed to update this item.', 'invoicing' ), |
|
404 | + __('Sorry, you are not allowed to update this item.', 'invoicing'), |
|
405 | 405 | array( |
406 | 406 | 'status' => rest_authorization_required_code(), |
407 | 407 | ) |
@@ -417,46 +417,46 @@ discard block |
||
417 | 417 | * @param WP_REST_Request $request Full details about the request. |
418 | 418 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
419 | 419 | */ |
420 | - public function update_item( $request ) { |
|
420 | + public function update_item($request) { |
|
421 | 421 | |
422 | 422 | // Ensure the item exists. |
423 | - $valid_check = $this->get_post( $request['id'] ); |
|
423 | + $valid_check = $this->get_post($request['id']); |
|
424 | 424 | |
425 | 425 | // Abort early if it does not exist |
426 | - if ( is_wp_error( $valid_check ) ) { |
|
426 | + if (is_wp_error($valid_check)) { |
|
427 | 427 | return $valid_check; |
428 | 428 | } |
429 | 429 | |
430 | - $request->set_param( 'context', 'edit' ); |
|
430 | + $request->set_param('context', 'edit'); |
|
431 | 431 | |
432 | 432 | // Prepare the updated data. |
433 | - $data_to_update = $this->prepare_item_for_database( $request ); |
|
433 | + $data_to_update = $this->prepare_item_for_database($request); |
|
434 | 434 | |
435 | - if ( is_wp_error( $data_to_update ) ) { |
|
435 | + if (is_wp_error($data_to_update)) { |
|
436 | 436 | return $data_to_update; |
437 | 437 | } |
438 | 438 | |
439 | 439 | // Abort if no item data is provided |
440 | - if( empty( $data_to_update ) ) { |
|
441 | - return new WP_Error( 'missing_data', __( 'An update request cannot be empty.', 'invoicing' ) ); |
|
440 | + if (empty($data_to_update)) { |
|
441 | + return new WP_Error('missing_data', __('An update request cannot be empty.', 'invoicing')); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | // Include the item ID |
445 | 445 | $data_to_update['ID'] = $request['id']; |
446 | 446 | |
447 | 447 | // Update the item |
448 | - $updated_item = wpinv_update_item( $data_to_update, true ); |
|
448 | + $updated_item = wpinv_update_item($data_to_update, true); |
|
449 | 449 | |
450 | 450 | // Incase the update operation failed... |
451 | - if ( is_wp_error( $updated_item ) ) { |
|
451 | + if (is_wp_error($updated_item)) { |
|
452 | 452 | return $updated_item; |
453 | 453 | } |
454 | 454 | |
455 | 455 | // Prepare the response |
456 | - $response = $this->prepare_item_for_response( $updated_item, $request ); |
|
456 | + $response = $this->prepare_item_for_response($updated_item, $request); |
|
457 | 457 | |
458 | 458 | /** This action is documented in includes/class-wpinv-rest-item-controller.php */ |
459 | - do_action( "wpinv_rest_insert_item", $updated_item, $request, false ); |
|
459 | + do_action("wpinv_rest_insert_item", $updated_item, $request, false); |
|
460 | 460 | |
461 | 461 | /** |
462 | 462 | * Filters the responses for updating single item requests. |
@@ -468,9 +468,9 @@ discard block |
||
468 | 468 | * @param array $data_to_update Item properties. |
469 | 469 | * @param WP_REST_Request $request The request used. |
470 | 470 | */ |
471 | - $response = apply_filters( "wpinv_rest_update_item_response", $response, $data_to_update, $request ); |
|
471 | + $response = apply_filters("wpinv_rest_update_item_response", $response, $data_to_update, $request); |
|
472 | 472 | |
473 | - return rest_ensure_response( $response ); |
|
473 | + return rest_ensure_response($response); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
@@ -481,21 +481,21 @@ discard block |
||
481 | 481 | * @param WP_REST_Request $request Full details about the request. |
482 | 482 | * @return true|WP_Error True if the request has access to delete the item, WP_Error object otherwise. |
483 | 483 | */ |
484 | - public function delete_item_permissions_check( $request ) { |
|
484 | + public function delete_item_permissions_check($request) { |
|
485 | 485 | |
486 | 486 | // Retrieve the item. |
487 | - $item = $this->get_post( $request['id'] ); |
|
488 | - if ( is_wp_error( $item ) ) { |
|
487 | + $item = $this->get_post($request['id']); |
|
488 | + if (is_wp_error($item)) { |
|
489 | 489 | return $item; |
490 | 490 | } |
491 | 491 | |
492 | 492 | // |
493 | 493 | |
494 | 494 | // Ensure the current user can delete the item |
495 | - if (! wpinv_can_delete_item( $request['id'] ) ) { |
|
495 | + if (!wpinv_can_delete_item($request['id'])) { |
|
496 | 496 | return new WP_Error( |
497 | 497 | 'rest_cannot_delete', |
498 | - __( 'Sorry, you are not allowed to delete this item.', 'invoicing' ), |
|
498 | + __('Sorry, you are not allowed to delete this item.', 'invoicing'), |
|
499 | 499 | array( |
500 | 500 | 'status' => rest_authorization_required_code(), |
501 | 501 | ) |
@@ -513,31 +513,31 @@ discard block |
||
513 | 513 | * @param WP_REST_Request $request Full details about the request. |
514 | 514 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
515 | 515 | */ |
516 | - public function delete_item( $request ) { |
|
516 | + public function delete_item($request) { |
|
517 | 517 | |
518 | 518 | // Retrieve the item. |
519 | - $item = $this->get_post( $request['id'] ); |
|
520 | - if ( is_wp_error( $item ) ) { |
|
519 | + $item = $this->get_post($request['id']); |
|
520 | + if (is_wp_error($item)) { |
|
521 | 521 | return $item; |
522 | 522 | } |
523 | 523 | |
524 | - $request->set_param( 'context', 'edit' ); |
|
524 | + $request->set_param('context', 'edit'); |
|
525 | 525 | |
526 | 526 | // Prepare the item id |
527 | - $id = $item->ID; |
|
527 | + $id = $item->ID; |
|
528 | 528 | |
529 | 529 | // Prepare the response |
530 | - $response = $this->prepare_item_for_response( $item, $request ); |
|
530 | + $response = $this->prepare_item_for_response($item, $request); |
|
531 | 531 | |
532 | 532 | // Check if the user wants to bypass the trash... |
533 | 533 | $force_delete = (bool) $request['force']; |
534 | 534 | |
535 | 535 | // Try deleting the item. |
536 | - $deleted = wp_delete_post( $id, $force_delete ); |
|
536 | + $deleted = wp_delete_post($id, $force_delete); |
|
537 | 537 | |
538 | 538 | // Abort early if we can't delete the item. |
539 | - if ( ! $deleted ) { |
|
540 | - return new WP_Error( 'rest_cannot_delete', __( 'The item cannot be deleted.', 'invoicing' ), array( 'status' => 500 ) ); |
|
539 | + if (!$deleted) { |
|
540 | + return new WP_Error('rest_cannot_delete', __('The item cannot be deleted.', 'invoicing'), array('status' => 500)); |
|
541 | 541 | } |
542 | 542 | |
543 | 543 | /** |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | * @param WPInv_Item $item The deleted or trashed item. |
550 | 550 | * @param WP_REST_Request $request The request sent to the API. |
551 | 551 | */ |
552 | - do_action( "wpinv_rest_delete_item", $item, $request ); |
|
552 | + do_action("wpinv_rest_delete_item", $item, $request); |
|
553 | 553 | |
554 | 554 | return $response; |
555 | 555 | |
@@ -565,19 +565,19 @@ discard block |
||
565 | 565 | */ |
566 | 566 | public function get_collection_params() { |
567 | 567 | |
568 | - $query_params = array( |
|
568 | + $query_params = array( |
|
569 | 569 | |
570 | 570 | // Item status. |
571 | 571 | 'status' => array( |
572 | 572 | 'default' => 'publish', |
573 | - 'description' => __( 'Limit result set to items assigned one or more statuses.', 'invoicing' ), |
|
573 | + 'description' => __('Limit result set to items assigned one or more statuses.', 'invoicing'), |
|
574 | 574 | 'type' => 'array', |
575 | - 'sanitize_callback' => array( $this, 'sanitize_post_statuses' ), |
|
575 | + 'sanitize_callback' => array($this, 'sanitize_post_statuses'), |
|
576 | 576 | ), |
577 | 577 | |
578 | 578 | // Item types |
579 | 579 | 'type' => array( |
580 | - 'description' => __( 'Type of items to fetch.', 'invoicing' ), |
|
580 | + 'description' => __('Type of items to fetch.', 'invoicing'), |
|
581 | 581 | 'type' => 'array', |
582 | 582 | 'default' => wpinv_item_types(), |
583 | 583 | 'items' => array( |
@@ -588,21 +588,21 @@ discard block |
||
588 | 588 | |
589 | 589 | // Number of results per page |
590 | 590 | 'limit' => array( |
591 | - 'description' => __( 'Number of items to fetch.', 'invoicing' ), |
|
591 | + 'description' => __('Number of items to fetch.', 'invoicing'), |
|
592 | 592 | 'type' => 'integer', |
593 | - 'default' => (int) get_option( 'posts_per_page' ), |
|
593 | + 'default' => (int) get_option('posts_per_page'), |
|
594 | 594 | ), |
595 | 595 | |
596 | 596 | // Pagination |
597 | 597 | 'page' => array( |
598 | - 'description' => __( 'Current page to fetch.', 'invoicing' ), |
|
598 | + 'description' => __('Current page to fetch.', 'invoicing'), |
|
599 | 599 | 'type' => 'integer', |
600 | 600 | 'default' => 1, |
601 | 601 | ), |
602 | 602 | |
603 | 603 | // Exclude certain items |
604 | 604 | 'exclude' => array( |
605 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'invoicing' ), |
|
605 | + 'description' => __('Ensure result set excludes specific IDs.', 'invoicing'), |
|
606 | 606 | 'type' => 'array', |
607 | 607 | 'items' => array( |
608 | 608 | 'type' => 'integer', |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | |
613 | 613 | // Order items by |
614 | 614 | 'orderby' => array( |
615 | - 'description' => __( 'Sort items by object attribute.', 'invoicing' ), |
|
615 | + 'description' => __('Sort items by object attribute.', 'invoicing'), |
|
616 | 616 | 'type' => 'string', |
617 | 617 | 'default' => 'date', |
618 | 618 | 'enum' => array( |
@@ -628,15 +628,15 @@ discard block |
||
628 | 628 | |
629 | 629 | // How to order |
630 | 630 | 'order' => array( |
631 | - 'description' => __( 'Order sort attribute ascending or descending.', 'invoicing' ), |
|
631 | + 'description' => __('Order sort attribute ascending or descending.', 'invoicing'), |
|
632 | 632 | 'type' => 'string', |
633 | 633 | 'default' => 'DESC', |
634 | - 'enum' => array( 'ASC', 'DESC' ), |
|
634 | + 'enum' => array('ASC', 'DESC'), |
|
635 | 635 | ), |
636 | 636 | |
637 | 637 | // Search term |
638 | 638 | 'search' => array( |
639 | - 'description' => __( 'Return items that match the search term.', 'invoicing' ), |
|
639 | + 'description' => __('Return items that match the search term.', 'invoicing'), |
|
640 | 640 | 'type' => 'string', |
641 | 641 | ), |
642 | 642 | ); |
@@ -649,7 +649,7 @@ discard block |
||
649 | 649 | * |
650 | 650 | * @param array $query_params JSON Schema-formatted collection parameters. |
651 | 651 | */ |
652 | - return apply_filters( "wpinv_rest_items_collection_params", $query_params ); |
|
652 | + return apply_filters("wpinv_rest_items_collection_params", $query_params); |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | /** |
@@ -660,7 +660,7 @@ discard block |
||
660 | 660 | * @param object|string $post_type Post type name or object. |
661 | 661 | * @return bool Whether the post type is allowed in REST. |
662 | 662 | */ |
663 | - protected function check_is_post_type_allowed( $post_type ) { |
|
663 | + protected function check_is_post_type_allowed($post_type) { |
|
664 | 664 | return true; |
665 | 665 | } |
666 | 666 | |
@@ -672,84 +672,84 @@ discard block |
||
672 | 672 | * @param WP_REST_Request $request Request object. |
673 | 673 | * @return array|WP_Error Invoice Properties or WP_Error. |
674 | 674 | */ |
675 | - protected function prepare_item_for_database( $request ) { |
|
675 | + protected function prepare_item_for_database($request) { |
|
676 | 676 | $prepared_item = new stdClass(); |
677 | 677 | |
678 | 678 | // Post ID. |
679 | - if ( isset( $request['id'] ) ) { |
|
680 | - $existing_item = $this->get_post( $request['id'] ); |
|
681 | - if ( is_wp_error( $existing_item ) ) { |
|
679 | + if (isset($request['id'])) { |
|
680 | + $existing_item = $this->get_post($request['id']); |
|
681 | + if (is_wp_error($existing_item)) { |
|
682 | 682 | return $existing_item; |
683 | 683 | } |
684 | 684 | |
685 | - $prepared_item->ID = $existing_item->ID; |
|
685 | + $prepared_item->ID = $existing_item->ID; |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | $schema = $this->get_item_schema(); |
689 | 689 | |
690 | 690 | // item title. |
691 | - if ( ! empty( $schema['properties']['name'] ) && isset( $request['name'] ) ) { |
|
692 | - $prepared_item->title = sanitize_text_field( $request['name'] ); |
|
691 | + if (!empty($schema['properties']['name']) && isset($request['name'])) { |
|
692 | + $prepared_item->title = sanitize_text_field($request['name']); |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | // item summary. |
696 | - if ( ! empty( $schema['properties']['summary'] ) && isset( $request['summary'] ) ) { |
|
697 | - $prepared_item->excerpt = wp_kses_post( $request['summary'] ); |
|
696 | + if (!empty($schema['properties']['summary']) && isset($request['summary'])) { |
|
697 | + $prepared_item->excerpt = wp_kses_post($request['summary']); |
|
698 | 698 | } |
699 | 699 | |
700 | 700 | // item price. |
701 | - if ( ! empty( $schema['properties']['price'] ) && isset( $request['price'] ) ) { |
|
702 | - $prepared_item->price = floatval( $request['price'] ); |
|
701 | + if (!empty($schema['properties']['price']) && isset($request['price'])) { |
|
702 | + $prepared_item->price = floatval($request['price']); |
|
703 | 703 | } |
704 | 704 | |
705 | 705 | // minimum price (for dynamc items). |
706 | - if ( ! empty( $schema['properties']['minimum_price'] ) && isset( $request['minimum_price'] ) ) { |
|
707 | - $prepared_item->minimum_price = floatval( $request['minimum_price'] ); |
|
706 | + if (!empty($schema['properties']['minimum_price']) && isset($request['minimum_price'])) { |
|
707 | + $prepared_item->minimum_price = floatval($request['minimum_price']); |
|
708 | 708 | } |
709 | 709 | |
710 | 710 | // item status. |
711 | - if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) ) { |
|
711 | + if (!empty($schema['properties']['status']) && isset($request['status'])) { |
|
712 | 712 | $prepared_item->status = 'publish' === $request['status'] ? 'publish' : 'pending'; |
713 | 713 | } |
714 | 714 | |
715 | 715 | // item type. |
716 | - if ( ! empty( $schema['properties']['type'] ) && isset( $request['type'] ) ) { |
|
717 | - $prepared_item->type = in_array( $request['type'], wpinv_item_types() ) ? trim( strtolower( $request['type'] ) ) : 'custom'; |
|
716 | + if (!empty($schema['properties']['type']) && isset($request['type'])) { |
|
717 | + $prepared_item->type = in_array($request['type'], wpinv_item_types()) ? trim(strtolower($request['type'])) : 'custom'; |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | // VAT rule. |
721 | - if ( ! empty( $schema['properties']['vat_rule'] ) && isset( $request['vat_rule'] ) ) { |
|
721 | + if (!empty($schema['properties']['vat_rule']) && isset($request['vat_rule'])) { |
|
722 | 722 | $prepared_item->vat_rule = 'digital' === $request['vat_rule'] ? 'digital' : 'physical'; |
723 | 723 | } |
724 | 724 | |
725 | 725 | // Simple strings. |
726 | - foreach( array( 'custom_id', 'custom_name', 'custom_singular_name' ) as $property ) { |
|
726 | + foreach (array('custom_id', 'custom_name', 'custom_singular_name') as $property) { |
|
727 | 727 | |
728 | - if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) { |
|
729 | - $prepared_item->$property = sanitize_text_field( $request[$property] ); |
|
728 | + if (!empty($schema['properties'][$property]) && isset($request[$property])) { |
|
729 | + $prepared_item->$property = sanitize_text_field($request[$property]); |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | } |
733 | 733 | |
734 | 734 | // Simple integers. |
735 | - foreach( array( 'is_recurring', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_interval', 'dynamic_pricing', 'editable' ) as $property ) { |
|
735 | + foreach (array('is_recurring', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_interval', 'dynamic_pricing', 'editable') as $property) { |
|
736 | 736 | |
737 | - if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) { |
|
738 | - $prepared_item->$property = intval( $request[$property] ); |
|
737 | + if (!empty($schema['properties'][$property]) && isset($request[$property])) { |
|
738 | + $prepared_item->$property = intval($request[$property]); |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | } |
742 | 742 | |
743 | 743 | // Time periods. |
744 | - foreach( array( 'recurring_period', 'trial_period' ) as $property ) { |
|
744 | + foreach (array('recurring_period', 'trial_period') as $property) { |
|
745 | 745 | |
746 | - if ( ! empty( $schema['properties'][$property] ) && isset( $request[$property] ) ) { |
|
747 | - $prepared_item->$property = in_array( $request[$property], array( 'D', 'W', 'M', 'Y' ) ) ? trim( strtoupper( $request[$property] ) ) : 'D'; |
|
746 | + if (!empty($schema['properties'][$property]) && isset($request[$property])) { |
|
747 | + $prepared_item->$property = in_array($request[$property], array('D', 'W', 'M', 'Y')) ? trim(strtoupper($request[$property])) : 'D'; |
|
748 | 748 | } |
749 | 749 | |
750 | 750 | } |
751 | 751 | |
752 | - $item_data = (array) wp_unslash( $prepared_item ); |
|
752 | + $item_data = (array) wp_unslash($prepared_item); |
|
753 | 753 | |
754 | 754 | /** |
755 | 755 | * Filters an item before it is inserted via the REST API. |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | * @param array $item_data An array of item data |
760 | 760 | * @param WP_REST_Request $request Request object. |
761 | 761 | */ |
762 | - return apply_filters( "wpinv_rest_pre_insert_item", $item_data, $request ); |
|
762 | + return apply_filters("wpinv_rest_pre_insert_item", $item_data, $request); |
|
763 | 763 | |
764 | 764 | } |
765 | 765 | |
@@ -772,20 +772,20 @@ discard block |
||
772 | 772 | * @param WP_REST_Request $request Request object. |
773 | 773 | * @return WP_REST_Response Response object. |
774 | 774 | */ |
775 | - public function prepare_item_for_response( $item, $request ) { |
|
775 | + public function prepare_item_for_response($item, $request) { |
|
776 | 776 | |
777 | - $GLOBALS['post'] = get_post( $item->get_ID() ); |
|
777 | + $GLOBALS['post'] = get_post($item->get_ID()); |
|
778 | 778 | |
779 | - setup_postdata( $item->get_ID() ); |
|
779 | + setup_postdata($item->get_ID()); |
|
780 | 780 | |
781 | 781 | // Fetch the fields to include in this response. |
782 | - $fields = $this->get_fields_for_response( $request ); |
|
782 | + $fields = $this->get_fields_for_response($request); |
|
783 | 783 | |
784 | 784 | // Base fields for every item. |
785 | 785 | $data = array(); |
786 | 786 | |
787 | 787 | // Set up ID |
788 | - if ( rest_is_field_included( 'id', $fields ) ) { |
|
788 | + if (rest_is_field_included('id', $fields)) { |
|
789 | 789 | $data['id'] = $item->get_ID(); |
790 | 790 | } |
791 | 791 | |
@@ -798,49 +798,49 @@ discard block |
||
798 | 798 | 'editable' |
799 | 799 | ); |
800 | 800 | |
801 | - foreach( $item_properties as $property ) { |
|
801 | + foreach ($item_properties as $property) { |
|
802 | 802 | |
803 | - if ( rest_is_field_included( $property, $fields ) && method_exists( $item, 'get_' . $property ) ) { |
|
804 | - $data[$property] = call_user_func( array( $item, 'get_' . $property ) ); |
|
803 | + if (rest_is_field_included($property, $fields) && method_exists($item, 'get_' . $property)) { |
|
804 | + $data[$property] = call_user_func(array($item, 'get_' . $property)); |
|
805 | 805 | } |
806 | 806 | |
807 | 807 | } |
808 | 808 | |
809 | 809 | // Dynamic pricing. |
810 | - if( $item->supports_dynamic_pricing() ) { |
|
810 | + if ($item->supports_dynamic_pricing()) { |
|
811 | 811 | |
812 | - if( rest_is_field_included( 'dynamic_pricing', $fields ) ) { |
|
812 | + if (rest_is_field_included('dynamic_pricing', $fields)) { |
|
813 | 813 | $data['dynamic_pricing'] = $item->get_is_dynamic_pricing(); |
814 | 814 | } |
815 | 815 | |
816 | - if( rest_is_field_included( 'minimum_price', $fields ) ) { |
|
816 | + if (rest_is_field_included('minimum_price', $fields)) { |
|
817 | 817 | $data['minimum_price'] = $item->get_minimum_price(); |
818 | 818 | } |
819 | 819 | } |
820 | 820 | |
821 | 821 | // Subscriptions. |
822 | - if( rest_is_field_included( 'is_recurring', $fields ) ) { |
|
822 | + if (rest_is_field_included('is_recurring', $fields)) { |
|
823 | 823 | $data['is_recurring'] = $item->get_is_recurring(); |
824 | 824 | } |
825 | 825 | |
826 | - if( $item->is_recurring() ) { |
|
826 | + if ($item->is_recurring()) { |
|
827 | 827 | |
828 | - $recurring_fields = array( 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial' ); |
|
829 | - foreach( $recurring_fields as $field ) { |
|
828 | + $recurring_fields = array('is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial'); |
|
829 | + foreach ($recurring_fields as $field) { |
|
830 | 830 | |
831 | - if ( rest_is_field_included( $field, $fields ) && method_exists( $item, 'get_' . $field ) ) { |
|
832 | - $data[$field] = call_user_func( array( $item, 'get_' . $field ) ); |
|
831 | + if (rest_is_field_included($field, $fields) && method_exists($item, 'get_' . $field)) { |
|
832 | + $data[$field] = call_user_func(array($item, 'get_' . $field)); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | } |
836 | 836 | |
837 | - if( $item->has_free_trial() ) { |
|
837 | + if ($item->has_free_trial()) { |
|
838 | 838 | |
839 | - $trial_fields = array( 'trial_period', 'trial_interval' ); |
|
840 | - foreach( $trial_fields as $field ) { |
|
839 | + $trial_fields = array('trial_period', 'trial_interval'); |
|
840 | + foreach ($trial_fields as $field) { |
|
841 | 841 | |
842 | - if ( rest_is_field_included( $field, $fields ) && method_exists( $item, 'get_' . $field ) ) { |
|
843 | - $data[$field] = call_user_func( array( $item, 'get_' . $field ) ); |
|
842 | + if (rest_is_field_included($field, $fields) && method_exists($item, 'get_' . $field)) { |
|
843 | + $data[$field] = call_user_func(array($item, 'get_' . $field)); |
|
844 | 844 | } |
845 | 845 | |
846 | 846 | } |
@@ -849,23 +849,23 @@ discard block |
||
849 | 849 | |
850 | 850 | } |
851 | 851 | |
852 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
853 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
854 | - $data = $this->filter_response_by_context( $data, $context ); |
|
852 | + $context = !empty($request['context']) ? $request['context'] : 'view'; |
|
853 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
854 | + $data = $this->filter_response_by_context($data, $context); |
|
855 | 855 | |
856 | 856 | // Wrap the data in a response object. |
857 | - $response = rest_ensure_response( $data ); |
|
857 | + $response = rest_ensure_response($data); |
|
858 | 858 | |
859 | - $links = $this->prepare_links( $item ); |
|
860 | - $response->add_links( $links ); |
|
859 | + $links = $this->prepare_links($item); |
|
860 | + $response->add_links($links); |
|
861 | 861 | |
862 | - if ( ! empty( $links['self']['href'] ) ) { |
|
863 | - $actions = $this->get_available_actions( $item, $request ); |
|
862 | + if (!empty($links['self']['href'])) { |
|
863 | + $actions = $this->get_available_actions($item, $request); |
|
864 | 864 | |
865 | 865 | $self = $links['self']['href']; |
866 | 866 | |
867 | - foreach ( $actions as $rel ) { |
|
868 | - $response->add_link( $rel, $self ); |
|
867 | + foreach ($actions as $rel) { |
|
868 | + $response->add_link($rel, $self); |
|
869 | 869 | } |
870 | 870 | } |
871 | 871 | |
@@ -878,7 +878,7 @@ discard block |
||
878 | 878 | * @param WPInv_Item $item The item object. |
879 | 879 | * @param WP_REST_Request $request Request object. |
880 | 880 | */ |
881 | - return apply_filters( "wpinv_rest_prepare_item", $response, $item, $request ); |
|
881 | + return apply_filters("wpinv_rest_prepare_item", $response, $item, $request); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | /** |
@@ -891,57 +891,57 @@ discard block |
||
891 | 891 | * @param WP_REST_Request $request Full details about the request. |
892 | 892 | * @return array Fields to be included in the response. |
893 | 893 | */ |
894 | - public function get_fields_for_response( $request ) { |
|
894 | + public function get_fields_for_response($request) { |
|
895 | 895 | $schema = $this->get_item_schema(); |
896 | - $properties = isset( $schema['properties'] ) ? $schema['properties'] : array(); |
|
896 | + $properties = isset($schema['properties']) ? $schema['properties'] : array(); |
|
897 | 897 | |
898 | 898 | $additional_fields = $this->get_additional_fields(); |
899 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
899 | + foreach ($additional_fields as $field_name => $field_options) { |
|
900 | 900 | // For back-compat, include any field with an empty schema |
901 | 901 | // because it won't be present in $this->get_item_schema(). |
902 | - if ( is_null( $field_options['schema'] ) ) { |
|
903 | - $properties[ $field_name ] = $field_options; |
|
902 | + if (is_null($field_options['schema'])) { |
|
903 | + $properties[$field_name] = $field_options; |
|
904 | 904 | } |
905 | 905 | } |
906 | 906 | |
907 | 907 | // Exclude fields that specify a different context than the request context. |
908 | 908 | $context = $request['context']; |
909 | - if ( $context ) { |
|
910 | - foreach ( $properties as $name => $options ) { |
|
911 | - if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) { |
|
912 | - unset( $properties[ $name ] ); |
|
909 | + if ($context) { |
|
910 | + foreach ($properties as $name => $options) { |
|
911 | + if (!empty($options['context']) && !in_array($context, $options['context'], true)) { |
|
912 | + unset($properties[$name]); |
|
913 | 913 | } |
914 | 914 | } |
915 | 915 | } |
916 | 916 | |
917 | - $fields = array_keys( $properties ); |
|
917 | + $fields = array_keys($properties); |
|
918 | 918 | |
919 | - if ( ! isset( $request['_fields'] ) ) { |
|
919 | + if (!isset($request['_fields'])) { |
|
920 | 920 | return $fields; |
921 | 921 | } |
922 | - $requested_fields = wpinv_parse_list( $request['_fields'] ); |
|
923 | - if ( 0 === count( $requested_fields ) ) { |
|
922 | + $requested_fields = wpinv_parse_list($request['_fields']); |
|
923 | + if (0 === count($requested_fields)) { |
|
924 | 924 | return $fields; |
925 | 925 | } |
926 | 926 | // Trim off outside whitespace from the comma delimited list. |
927 | - $requested_fields = array_map( 'trim', $requested_fields ); |
|
927 | + $requested_fields = array_map('trim', $requested_fields); |
|
928 | 928 | // Always persist 'id', because it can be needed for add_additional_fields_to_object(). |
929 | - if ( in_array( 'id', $fields, true ) ) { |
|
929 | + if (in_array('id', $fields, true)) { |
|
930 | 930 | $requested_fields[] = 'id'; |
931 | 931 | } |
932 | 932 | // Return the list of all requested fields which appear in the schema. |
933 | 933 | return array_reduce( |
934 | 934 | $requested_fields, |
935 | - function( $response_fields, $field ) use ( $fields ) { |
|
936 | - if ( in_array( $field, $fields, true ) ) { |
|
935 | + function($response_fields, $field) use ($fields) { |
|
936 | + if (in_array($field, $fields, true)) { |
|
937 | 937 | $response_fields[] = $field; |
938 | 938 | return $response_fields; |
939 | 939 | } |
940 | 940 | // Check for nested fields if $field is not a direct match. |
941 | - $nested_fields = explode( '.', $field ); |
|
941 | + $nested_fields = explode('.', $field); |
|
942 | 942 | // A nested field is included so long as its top-level property is |
943 | 943 | // present in the schema. |
944 | - if ( in_array( $nested_fields[0], $fields, true ) ) { |
|
944 | + if (in_array($nested_fields[0], $fields, true)) { |
|
945 | 945 | $response_fields[] = $field; |
946 | 946 | } |
947 | 947 | return $response_fields; |
@@ -960,8 +960,8 @@ discard block |
||
960 | 960 | public function get_item_schema() { |
961 | 961 | |
962 | 962 | // Maybe retrieve the schema from cache. |
963 | - if ( $this->schema ) { |
|
964 | - return $this->add_additional_fields_schema( $this->schema ); |
|
963 | + if ($this->schema) { |
|
964 | + return $this->add_additional_fields_schema($this->schema); |
|
965 | 965 | } |
966 | 966 | |
967 | 967 | $schema = array( |
@@ -973,136 +973,136 @@ discard block |
||
973 | 973 | 'properties' => array( |
974 | 974 | |
975 | 975 | 'id' => array( |
976 | - 'description' => __( 'Unique identifier for the item.', 'invoicing' ), |
|
976 | + 'description' => __('Unique identifier for the item.', 'invoicing'), |
|
977 | 977 | 'type' => 'integer', |
978 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
978 | + 'context' => array('view', 'edit', 'embed'), |
|
979 | 979 | 'readonly' => true, |
980 | 980 | ), |
981 | 981 | |
982 | 982 | 'name' => array( |
983 | - 'description' => __( 'The name for the item.', 'invoicing' ), |
|
983 | + 'description' => __('The name for the item.', 'invoicing'), |
|
984 | 984 | 'type' => 'string', |
985 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
985 | + 'context' => array('view', 'edit', 'embed'), |
|
986 | 986 | ), |
987 | 987 | |
988 | 988 | 'summary' => array( |
989 | - 'description' => __( 'A summary for the item.', 'invoicing' ), |
|
989 | + 'description' => __('A summary for the item.', 'invoicing'), |
|
990 | 990 | 'type' => 'string', |
991 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
991 | + 'context' => array('view', 'edit', 'embed'), |
|
992 | 992 | ), |
993 | 993 | |
994 | 994 | 'price' => array( |
995 | - 'description' => __( 'The price for the item.', 'invoicing' ), |
|
995 | + 'description' => __('The price for the item.', 'invoicing'), |
|
996 | 996 | 'type' => 'number', |
997 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
997 | + 'context' => array('view', 'edit', 'embed'), |
|
998 | 998 | ), |
999 | 999 | |
1000 | 1000 | 'status' => array( |
1001 | - 'description' => __( 'A named status for the item.', 'invoicing' ), |
|
1001 | + 'description' => __('A named status for the item.', 'invoicing'), |
|
1002 | 1002 | 'type' => 'string', |
1003 | - 'enum' => array_keys( get_post_stati( array( 'internal' => false ) ) ), |
|
1004 | - 'context' => array( 'view', 'edit' ), |
|
1003 | + 'enum' => array_keys(get_post_stati(array('internal' => false))), |
|
1004 | + 'context' => array('view', 'edit'), |
|
1005 | 1005 | ), |
1006 | 1006 | |
1007 | 1007 | 'type' => array( |
1008 | - 'description' => __( 'The item type.', 'invoicing' ), |
|
1008 | + 'description' => __('The item type.', 'invoicing'), |
|
1009 | 1009 | 'type' => 'string', |
1010 | 1010 | 'enum' => wpinv_item_types(), |
1011 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1011 | + 'context' => array('view', 'edit', 'embed'), |
|
1012 | 1012 | ), |
1013 | 1013 | |
1014 | 1014 | 'vat_rule' => array( |
1015 | - 'description' => __( 'VAT rule applied to the item.', 'invoicing' ), |
|
1015 | + 'description' => __('VAT rule applied to the item.', 'invoicing'), |
|
1016 | 1016 | 'type' => 'string', |
1017 | - 'enum' => array( 'digital', 'physical' ), |
|
1018 | - 'context' => array( 'view', 'edit' ), |
|
1017 | + 'enum' => array('digital', 'physical'), |
|
1018 | + 'context' => array('view', 'edit'), |
|
1019 | 1019 | ), |
1020 | 1020 | |
1021 | 1021 | 'vat_class' => array( |
1022 | - 'description' => __( 'VAT class for the item.', 'invoicing' ), |
|
1022 | + 'description' => __('VAT class for the item.', 'invoicing'), |
|
1023 | 1023 | 'type' => 'string', |
1024 | - 'context' => array( 'view', 'edit' ), |
|
1024 | + 'context' => array('view', 'edit'), |
|
1025 | 1025 | 'readonly' => true, |
1026 | 1026 | ), |
1027 | 1027 | |
1028 | 1028 | 'custom_id' => array( |
1029 | - 'description' => __( 'Custom id for the item.', 'invoicing' ), |
|
1029 | + 'description' => __('Custom id for the item.', 'invoicing'), |
|
1030 | 1030 | 'type' => 'string', |
1031 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1031 | + 'context' => array('view', 'edit', 'embed'), |
|
1032 | 1032 | ), |
1033 | 1033 | |
1034 | 1034 | 'custom_name' => array( |
1035 | - 'description' => __( 'Custom name for the item.', 'invoicing' ), |
|
1035 | + 'description' => __('Custom name for the item.', 'invoicing'), |
|
1036 | 1036 | 'type' => 'string', |
1037 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1037 | + 'context' => array('view', 'edit', 'embed'), |
|
1038 | 1038 | ), |
1039 | 1039 | |
1040 | 1040 | 'custom_singular_name' => array( |
1041 | - 'description' => __( 'Custom singular name for the item.', 'invoicing' ), |
|
1041 | + 'description' => __('Custom singular name for the item.', 'invoicing'), |
|
1042 | 1042 | 'type' => 'string', |
1043 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1043 | + 'context' => array('view', 'edit', 'embed'), |
|
1044 | 1044 | ), |
1045 | 1045 | |
1046 | 1046 | 'dynamic_pricing' => array( |
1047 | - 'description' => __( 'Whether the item allows a user to set their own price.', 'invoicing' ), |
|
1047 | + 'description' => __('Whether the item allows a user to set their own price.', 'invoicing'), |
|
1048 | 1048 | 'type' => 'integer', |
1049 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1049 | + 'context' => array('view', 'edit', 'embed'), |
|
1050 | 1050 | ), |
1051 | 1051 | |
1052 | 1052 | 'minimum_price' => array( |
1053 | - 'description' => __( 'For dynamic prices, this is the minimum price that a user can set.', 'invoicing' ), |
|
1053 | + 'description' => __('For dynamic prices, this is the minimum price that a user can set.', 'invoicing'), |
|
1054 | 1054 | 'type' => 'number', |
1055 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1055 | + 'context' => array('view', 'edit', 'embed'), |
|
1056 | 1056 | ), |
1057 | 1057 | |
1058 | 1058 | 'is_recurring' => array( |
1059 | - 'description' => __( 'Whether the item is a subscription item.', 'invoicing' ), |
|
1059 | + 'description' => __('Whether the item is a subscription item.', 'invoicing'), |
|
1060 | 1060 | 'type' => 'integer', |
1061 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1061 | + 'context' => array('view', 'edit', 'embed'), |
|
1062 | 1062 | ), |
1063 | 1063 | |
1064 | 1064 | 'recurring_period' => array( |
1065 | - 'description' => __( 'The recurring period for a recurring item.', 'invoicing' ), |
|
1065 | + 'description' => __('The recurring period for a recurring item.', 'invoicing'), |
|
1066 | 1066 | 'type' => 'string', |
1067 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1068 | - 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
1067 | + 'context' => array('view', 'edit', 'embed'), |
|
1068 | + 'enum' => array('D', 'W', 'M', 'Y'), |
|
1069 | 1069 | ), |
1070 | 1070 | |
1071 | 1071 | 'recurring_interval' => array( |
1072 | - 'description' => __( 'The recurring interval for a subscription item.', 'invoicing' ), |
|
1072 | + 'description' => __('The recurring interval for a subscription item.', 'invoicing'), |
|
1073 | 1073 | 'type' => 'integer', |
1074 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1074 | + 'context' => array('view', 'edit', 'embed'), |
|
1075 | 1075 | ), |
1076 | 1076 | |
1077 | 1077 | 'recurring_limit' => array( |
1078 | - 'description' => __( 'The maximum number of renewals for a subscription item.', 'invoicing' ), |
|
1078 | + 'description' => __('The maximum number of renewals for a subscription item.', 'invoicing'), |
|
1079 | 1079 | 'type' => 'integer', |
1080 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1080 | + 'context' => array('view', 'edit', 'embed'), |
|
1081 | 1081 | ), |
1082 | 1082 | |
1083 | 1083 | 'free_trial' => array( |
1084 | - 'description' => __( 'Whether the item has a free trial period.', 'invoicing' ), |
|
1084 | + 'description' => __('Whether the item has a free trial period.', 'invoicing'), |
|
1085 | 1085 | 'type' => 'integer', |
1086 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1086 | + 'context' => array('view', 'edit', 'embed'), |
|
1087 | 1087 | ), |
1088 | 1088 | |
1089 | 1089 | 'trial_period' => array( |
1090 | - 'description' => __( 'The trial period of a recurring item.', 'invoicing' ), |
|
1090 | + 'description' => __('The trial period of a recurring item.', 'invoicing'), |
|
1091 | 1091 | 'type' => 'string', |
1092 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1093 | - 'enum' => array( 'D', 'W', 'M', 'Y' ), |
|
1092 | + 'context' => array('view', 'edit', 'embed'), |
|
1093 | + 'enum' => array('D', 'W', 'M', 'Y'), |
|
1094 | 1094 | ), |
1095 | 1095 | |
1096 | 1096 | 'trial_interval' => array( |
1097 | - 'description' => __( 'The trial interval for a subscription item.', 'invoicing' ), |
|
1097 | + 'description' => __('The trial interval for a subscription item.', 'invoicing'), |
|
1098 | 1098 | 'type' => 'integer', |
1099 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1099 | + 'context' => array('view', 'edit', 'embed'), |
|
1100 | 1100 | ), |
1101 | 1101 | |
1102 | 1102 | 'editable' => array( |
1103 | - 'description' => __( 'Whether or not the item is editable.', 'invoicing' ), |
|
1103 | + 'description' => __('Whether or not the item is editable.', 'invoicing'), |
|
1104 | 1104 | 'type' => 'integer', |
1105 | - 'context' => array( 'view', 'edit' ), |
|
1105 | + 'context' => array('view', 'edit'), |
|
1106 | 1106 | ), |
1107 | 1107 | |
1108 | 1108 | ), |
@@ -1120,12 +1120,12 @@ discard block |
||
1120 | 1120 | * |
1121 | 1121 | * @param array $schema The item schema. |
1122 | 1122 | */ |
1123 | - $schema = apply_filters( "wpinv_rest_item_schema", $schema ); |
|
1123 | + $schema = apply_filters("wpinv_rest_item_schema", $schema); |
|
1124 | 1124 | |
1125 | 1125 | // Cache the item schema. |
1126 | 1126 | $this->schema = $schema; |
1127 | 1127 | |
1128 | - return $this->add_additional_fields_schema( $this->schema ); |
|
1128 | + return $this->add_additional_fields_schema($this->schema); |
|
1129 | 1129 | } |
1130 | 1130 | |
1131 | 1131 | /** |
@@ -1137,20 +1137,20 @@ discard block |
||
1137 | 1137 | */ |
1138 | 1138 | protected function get_schema_links() { |
1139 | 1139 | |
1140 | - $href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" ); |
|
1140 | + $href = rest_url("{$this->namespace}/{$this->rest_base}/{id}"); |
|
1141 | 1141 | |
1142 | 1142 | $links = array(); |
1143 | 1143 | |
1144 | 1144 | $links[] = array( |
1145 | 1145 | 'rel' => 'https://api.w.org/action-publish', |
1146 | - 'title' => __( 'The current user can publish this item.' ), |
|
1146 | + 'title' => __('The current user can publish this item.'), |
|
1147 | 1147 | 'href' => $href, |
1148 | 1148 | 'targetSchema' => array( |
1149 | 1149 | 'type' => 'object', |
1150 | 1150 | 'properties' => array( |
1151 | 1151 | 'status' => array( |
1152 | 1152 | 'type' => 'string', |
1153 | - 'enum' => array( 'publish', 'future' ), |
|
1153 | + 'enum' => array('publish', 'future'), |
|
1154 | 1154 | ), |
1155 | 1155 | ), |
1156 | 1156 | ), |
@@ -1167,18 +1167,18 @@ discard block |
||
1167 | 1167 | * @param WPInv_Item $item Item Object. |
1168 | 1168 | * @return array Links for the given item. |
1169 | 1169 | */ |
1170 | - protected function prepare_links( $item ) { |
|
1170 | + protected function prepare_links($item) { |
|
1171 | 1171 | |
1172 | 1172 | // Prepare the base REST API endpoint for items. |
1173 | - $base = sprintf( '%s/%s', $this->namespace, $this->rest_base ); |
|
1173 | + $base = sprintf('%s/%s', $this->namespace, $this->rest_base); |
|
1174 | 1174 | |
1175 | 1175 | // Entity meta. |
1176 | 1176 | $links = array( |
1177 | 1177 | 'self' => array( |
1178 | - 'href' => rest_url( trailingslashit( $base ) . $item->ID ), |
|
1178 | + 'href' => rest_url(trailingslashit($base) . $item->ID), |
|
1179 | 1179 | ), |
1180 | 1180 | 'collection' => array( |
1181 | - 'href' => rest_url( $base ), |
|
1181 | + 'href' => rest_url($base), |
|
1182 | 1182 | ), |
1183 | 1183 | ); |
1184 | 1184 | |
@@ -1191,7 +1191,7 @@ discard block |
||
1191 | 1191 | * |
1192 | 1192 | * @param array $links Rest links. |
1193 | 1193 | */ |
1194 | - return apply_filters( "wpinv_rest_item_links", $links ); |
|
1194 | + return apply_filters("wpinv_rest_item_links", $links); |
|
1195 | 1195 | |
1196 | 1196 | } |
1197 | 1197 | |
@@ -1204,19 +1204,19 @@ discard block |
||
1204 | 1204 | * @param WP_REST_Request $request Request object. |
1205 | 1205 | * @return array List of link relations. |
1206 | 1206 | */ |
1207 | - protected function get_available_actions( $item, $request ) { |
|
1207 | + protected function get_available_actions($item, $request) { |
|
1208 | 1208 | |
1209 | - if ( 'edit' !== $request['context'] ) { |
|
1209 | + if ('edit' !== $request['context']) { |
|
1210 | 1210 | return array(); |
1211 | 1211 | } |
1212 | 1212 | |
1213 | 1213 | $rels = array(); |
1214 | 1214 | |
1215 | 1215 | // Retrieve the post type object. |
1216 | - $post_type = get_post_type_object( $item->post_type ); |
|
1216 | + $post_type = get_post_type_object($item->post_type); |
|
1217 | 1217 | |
1218 | 1218 | // Mark item as published. |
1219 | - if ( current_user_can( $post_type->cap->publish_posts ) ) { |
|
1219 | + if (current_user_can($post_type->cap->publish_posts)) { |
|
1220 | 1220 | $rels[] = 'https://api.w.org/action-publish'; |
1221 | 1221 | } |
1222 | 1222 | |
@@ -1229,7 +1229,7 @@ discard block |
||
1229 | 1229 | * |
1230 | 1230 | * @param array $rels Available link relations. |
1231 | 1231 | */ |
1232 | - return apply_filters( "wpinv_rest_item_link_relations", $rels ); |
|
1232 | + return apply_filters("wpinv_rest_item_link_relations", $rels); |
|
1233 | 1233 | } |
1234 | 1234 | |
1235 | 1235 | /** |
@@ -1241,7 +1241,7 @@ discard block |
||
1241 | 1241 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
1242 | 1242 | */ |
1243 | 1243 | public function get_item_types() { |
1244 | - return rest_ensure_response( wpinv_get_item_types() ); |
|
1244 | + return rest_ensure_response(wpinv_get_item_types()); |
|
1245 | 1245 | } |
1246 | 1246 | |
1247 | 1247 |
@@ -7,245 +7,245 @@ 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 | -function wpinv_columns( $columns ) { |
|
14 | +function wpinv_columns($columns) { |
|
15 | 15 | $columns = array( |
16 | 16 | 'cb' => $columns['cb'], |
17 | - 'number' => __( 'Number', 'invoicing' ), |
|
18 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
19 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
20 | - 'invoice_date' => __( 'Created Date', 'invoicing' ), |
|
21 | - 'payment_date' => __( 'Payment Date', 'invoicing' ), |
|
22 | - 'status' => __( 'Status', 'invoicing' ), |
|
23 | - 'ID' => __( 'ID', 'invoicing' ), |
|
24 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
17 | + 'number' => __('Number', 'invoicing'), |
|
18 | + 'customer' => __('Customer', 'invoicing'), |
|
19 | + 'amount' => __('Amount', 'invoicing'), |
|
20 | + 'invoice_date' => __('Created Date', 'invoicing'), |
|
21 | + 'payment_date' => __('Payment Date', 'invoicing'), |
|
22 | + 'status' => __('Status', 'invoicing'), |
|
23 | + 'ID' => __('ID', 'invoicing'), |
|
24 | + 'wpi_actions' => __('Actions', 'invoicing'), |
|
25 | 25 | ); |
26 | 26 | |
27 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
27 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
28 | 28 | } |
29 | -add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' ); |
|
29 | +add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns'); |
|
30 | 30 | |
31 | -function wpinv_bulk_actions( $actions ) { |
|
32 | - if ( isset( $actions['edit'] ) ) { |
|
33 | - unset( $actions['edit'] ); |
|
31 | +function wpinv_bulk_actions($actions) { |
|
32 | + if (isset($actions['edit'])) { |
|
33 | + unset($actions['edit']); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | return $actions; |
37 | 37 | } |
38 | -add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' ); |
|
39 | -add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' ); |
|
38 | +add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions'); |
|
39 | +add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions'); |
|
40 | 40 | |
41 | -function wpinv_sortable_columns( $columns ) { |
|
41 | +function wpinv_sortable_columns($columns) { |
|
42 | 42 | $columns = array( |
43 | - 'ID' => array( 'ID', true ), |
|
44 | - 'number' => array( 'number', false ), |
|
45 | - 'amount' => array( 'amount', false ), |
|
46 | - 'invoice_date' => array( 'date', false ), |
|
47 | - 'payment_date' => array( 'payment_date', true ), |
|
48 | - 'customer' => array( 'customer', false ), |
|
49 | - 'status' => array( 'status', false ), |
|
43 | + 'ID' => array('ID', true), |
|
44 | + 'number' => array('number', false), |
|
45 | + 'amount' => array('amount', false), |
|
46 | + 'invoice_date' => array('date', false), |
|
47 | + 'payment_date' => array('payment_date', true), |
|
48 | + 'customer' => array('customer', false), |
|
49 | + 'status' => array('status', false), |
|
50 | 50 | ); |
51 | 51 | |
52 | - return apply_filters( 'wpi_invoice_table_sortable_columns', $columns ); |
|
52 | + return apply_filters('wpi_invoice_table_sortable_columns', $columns); |
|
53 | 53 | } |
54 | -add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' ); |
|
54 | +add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns'); |
|
55 | 55 | |
56 | -add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
57 | -function wpinv_posts_custom_column( $column_name, $post_id = 0 ) { |
|
56 | +add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
57 | +function wpinv_posts_custom_column($column_name, $post_id = 0) { |
|
58 | 58 | global $post, $wpi_invoice; |
59 | 59 | |
60 | - if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) { |
|
61 | - $wpi_invoice = new WPInv_Invoice( $post->ID ); |
|
60 | + if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) { |
|
61 | + $wpi_invoice = new WPInv_Invoice($post->ID); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | $value = NULL; |
65 | 65 | |
66 | - switch ( $column_name ) { |
|
66 | + switch ($column_name) { |
|
67 | 67 | case 'email' : |
68 | - $value = $wpi_invoice->get_email(); |
|
68 | + $value = $wpi_invoice->get_email(); |
|
69 | 69 | break; |
70 | 70 | case 'customer' : |
71 | 71 | $customer_name = $wpi_invoice->get_user_full_name(); |
72 | - $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' ); |
|
73 | - $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>'; |
|
74 | - if ( $email = $wpi_invoice->get_email() ) { |
|
72 | + $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing'); |
|
73 | + $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>'; |
|
74 | + if ($email = $wpi_invoice->get_email()) { |
|
75 | 75 | $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>'; |
76 | 76 | } |
77 | 77 | break; |
78 | 78 | case 'amount' : |
79 | - echo $wpi_invoice->get_total( true ); |
|
79 | + echo $wpi_invoice->get_total(true); |
|
80 | 80 | break; |
81 | 81 | case 'invoice_date' : |
82 | - $date_format = get_option( 'date_format' ); |
|
82 | + $date_format = get_option('date_format'); |
|
83 | 83 | |
84 | 84 | $m_time = $post->post_date; |
85 | - $h_time = mysql2date( $date_format, $m_time ); |
|
85 | + $h_time = mysql2date($date_format, $m_time); |
|
86 | 86 | |
87 | - $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
87 | + $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
88 | 88 | break; |
89 | 89 | case 'payment_date' : |
90 | - if ( $date_completed = $wpi_invoice->get_meta( '_wpinv_completed_date', true ) ) { |
|
91 | - $date_format = get_option( 'date_format' ); |
|
90 | + if ($date_completed = $wpi_invoice->get_meta('_wpinv_completed_date', true)) { |
|
91 | + $date_format = get_option('date_format'); |
|
92 | 92 | |
93 | 93 | $m_time = $date_completed; |
94 | - $h_time = mysql2date( $date_format, $m_time ); |
|
94 | + $h_time = mysql2date($date_format, $m_time); |
|
95 | 95 | |
96 | - $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
96 | + $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
97 | 97 | } else { |
98 | 98 | $value = '-'; |
99 | 99 | } |
100 | 100 | break; |
101 | 101 | case 'status' : |
102 | - $value = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' ); |
|
103 | - $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID ); |
|
104 | - $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() ); |
|
102 | + $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''); |
|
103 | + $is_viewed = wpinv_is_invoice_viewed($wpi_invoice->ID); |
|
104 | + $gateway_title = wpinv_get_gateway_admin_label($wpi_invoice->get_gateway()); |
|
105 | 105 | $offline_gateways = apply_filters('wpinv_offline_payments', array('bank_transfer', 'cheque', 'cod')); |
106 | 106 | $is_offline_payment = in_array($wpi_invoice->get_gateway(), $offline_gateways) ? true : false; |
107 | 107 | |
108 | - if ( 1 == $is_viewed ) { |
|
109 | - $value .= ' <i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
108 | + if (1 == $is_viewed) { |
|
109 | + $value .= ' <i class="fa fa-eye" title="' . __('Viewed by Customer', 'invoicing') . '"></i>'; |
|
110 | 110 | } |
111 | - if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() || $is_offline_payment ) && ( isset( $gateway_title ) ) ) { |
|
112 | - $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>'; |
|
111 | + if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded() || $is_offline_payment) && (isset($gateway_title))) { |
|
112 | + $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>'; |
|
113 | 113 | } |
114 | 114 | break; |
115 | 115 | case 'number' : |
116 | - $edit_link = get_edit_post_link( $post->ID ); |
|
117 | - $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>'; |
|
116 | + $edit_link = get_edit_post_link($post->ID); |
|
117 | + $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>'; |
|
118 | 118 | break; |
119 | 119 | case 'wpi_actions' : |
120 | 120 | $value = ''; |
121 | - if ( !empty( $post->post_name ) ) { |
|
122 | - $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>'; |
|
121 | + if (!empty($post->post_name)) { |
|
122 | + $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>'; |
|
123 | 123 | } |
124 | 124 | |
125 | - if ( $email = $wpi_invoice->get_email() ) { |
|
126 | - $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>'; |
|
125 | + if ($email = $wpi_invoice->get_email()) { |
|
126 | + $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>'; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | break; |
130 | 130 | default: |
131 | - $value = isset( $post->$column_name ) ? $post->$column_name : ''; |
|
131 | + $value = isset($post->$column_name) ? $post->$column_name : ''; |
|
132 | 132 | break; |
133 | 133 | |
134 | 134 | } |
135 | - $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name ); |
|
135 | + $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name); |
|
136 | 136 | |
137 | - if ( $value !== NULL ) { |
|
137 | + if ($value !== NULL) { |
|
138 | 138 | echo $value; |
139 | 139 | } |
140 | 140 | } |
141 | 141 | |
142 | -function wpinv_admin_post_id( $id = 0 ) { |
|
142 | +function wpinv_admin_post_id($id = 0) { |
|
143 | 143 | global $post; |
144 | 144 | |
145 | - if ( isset( $id ) && ! empty( $id ) ) { |
|
146 | - return (int)$id; |
|
147 | - } else if ( get_the_ID() ) { |
|
145 | + if (isset($id) && !empty($id)) { |
|
146 | + return (int) $id; |
|
147 | + } else if (get_the_ID()) { |
|
148 | 148 | return (int) get_the_ID(); |
149 | - } else if ( isset( $post->ID ) && !empty( $post->ID ) ) { |
|
149 | + } else if (isset($post->ID) && !empty($post->ID)) { |
|
150 | 150 | return (int) $post->ID; |
151 | - } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) { |
|
151 | + } else if (isset($_GET['post']) && !empty($_GET['post'])) { |
|
152 | 152 | return (int) $_GET['post']; |
153 | - } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) { |
|
153 | + } else if (isset($_GET['id']) && !empty($_GET['id'])) { |
|
154 | 154 | return (int) $_GET['id']; |
155 | - } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) { |
|
155 | + } else if (isset($_POST['id']) && !empty($_POST['id'])) { |
|
156 | 156 | return (int) $_POST['id']; |
157 | 157 | } |
158 | 158 | |
159 | 159 | return null; |
160 | 160 | } |
161 | 161 | |
162 | -function wpinv_admin_post_type( $id = 0 ) { |
|
163 | - if ( !$id ) { |
|
162 | +function wpinv_admin_post_type($id = 0) { |
|
163 | + if (!$id) { |
|
164 | 164 | $id = wpinv_admin_post_id(); |
165 | 165 | } |
166 | 166 | |
167 | - $type = get_post_type( $id ); |
|
167 | + $type = get_post_type($id); |
|
168 | 168 | |
169 | - if ( !$type ) { |
|
170 | - $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null; |
|
169 | + if (!$type) { |
|
170 | + $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null; |
|
171 | 171 | } |
172 | 172 | |
173 | - return apply_filters( 'wpinv_admin_post_type', $type, $id ); |
|
173 | + return apply_filters('wpinv_admin_post_type', $type, $id); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | function wpinv_admin_messages() { |
177 | 177 | global $wpinv_options, $pagenow, $post; |
178 | 178 | |
179 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
180 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
179 | + if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
180 | + add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated'); |
|
181 | 181 | } |
182 | 182 | |
183 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
184 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
183 | + if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
184 | + add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error'); |
|
185 | 185 | } |
186 | 186 | |
187 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
188 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
187 | + if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
188 | + add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error'); |
|
189 | 189 | } |
190 | 190 | |
191 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
192 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
191 | + if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
192 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated'); |
|
193 | 193 | } |
194 | 194 | |
195 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
196 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
195 | + if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
196 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error'); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
200 | - add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
199 | + if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
200 | + add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated'); |
|
201 | 201 | } |
202 | 202 | |
203 | - if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
204 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
203 | + if (isset($_GET['wpinv-message']) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
204 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Email notification is disabled. Please check settings.', 'invoicing'), 'error'); |
|
205 | 205 | } |
206 | 206 | |
207 | - if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
208 | - add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
207 | + if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
208 | + add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated'); |
|
209 | 209 | } |
210 | 210 | |
211 | - if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
212 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
211 | + if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
212 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error'); |
|
213 | 213 | } |
214 | 214 | |
215 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
216 | - add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
|
215 | + if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
216 | + add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated'); |
|
217 | 217 | } |
218 | 218 | |
219 | - if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
220 | - add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
219 | + if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
220 | + add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated'); |
|
221 | 221 | } |
222 | 222 | |
223 | - if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
224 | - add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
223 | + if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
224 | + add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated'); |
|
225 | 225 | } |
226 | 226 | |
227 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) { |
|
228 | - add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
227 | + if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) { |
|
228 | + add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated'); |
|
229 | 229 | } |
230 | 230 | |
231 | - if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
232 | - $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
231 | + if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) { |
|
232 | + $message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID); |
|
233 | 233 | |
234 | - if ( !empty( $message ) ) { |
|
235 | - add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
234 | + if (!empty($message)) { |
|
235 | + add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated'); |
|
236 | 236 | } |
237 | 237 | } |
238 | 238 | |
239 | - settings_errors( 'wpinv-notices' ); |
|
239 | + settings_errors('wpinv-notices'); |
|
240 | 240 | } |
241 | -add_action( 'admin_notices', 'wpinv_admin_messages' ); |
|
241 | +add_action('admin_notices', 'wpinv_admin_messages'); |
|
242 | 242 | |
243 | -add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' ); |
|
244 | -function wpinv_show_test_payment_gateway_notice(){ |
|
245 | - add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' ); |
|
243 | +add_action('admin_init', 'wpinv_show_test_payment_gateway_notice'); |
|
244 | +function wpinv_show_test_payment_gateway_notice() { |
|
245 | + add_action('admin_notices', 'wpinv_test_payment_gateway_messages'); |
|
246 | 246 | } |
247 | 247 | |
248 | -function wpinv_test_payment_gateway_messages(){ |
|
248 | +function wpinv_test_payment_gateway_messages() { |
|
249 | 249 | $gateways = wpinv_get_enabled_payment_gateways(); |
250 | 250 | $name = array(); $test_gateways = ''; |
251 | 251 | if ($gateways) { |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | } |
257 | 257 | $test_gateways = implode(', ', $name); |
258 | 258 | } |
259 | - if(isset($test_gateways) && !empty($test_gateways)){ |
|
259 | + if (isset($test_gateways) && !empty($test_gateways)) { |
|
260 | 260 | $link = admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
261 | - $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link ); |
|
261 | + $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link); |
|
262 | 262 | ?> |
263 | 263 | <div class="notice notice-warning is-dismissible"> |
264 | 264 | <p><?php echo $notice; ?></p> |
@@ -267,29 +267,29 @@ discard block |
||
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
270 | -function wpinv_items_columns( $existing_columns ) { |
|
270 | +function wpinv_items_columns($existing_columns) { |
|
271 | 271 | global $wpinv_euvat; |
272 | 272 | |
273 | 273 | $columns = array(); |
274 | 274 | $columns['cb'] = $existing_columns['cb']; |
275 | - $columns['title'] = __( 'Title', 'invoicing' ); |
|
276 | - $columns['price'] = __( 'Price', 'invoicing' ); |
|
277 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
278 | - $columns['vat_rule'] = __( 'VAT rule type', 'invoicing' ); |
|
275 | + $columns['title'] = __('Title', 'invoicing'); |
|
276 | + $columns['price'] = __('Price', 'invoicing'); |
|
277 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
278 | + $columns['vat_rule'] = __('VAT rule type', 'invoicing'); |
|
279 | 279 | } |
280 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
281 | - $columns['vat_class'] = __( 'VAT class', 'invoicing' ); |
|
280 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
281 | + $columns['vat_class'] = __('VAT class', 'invoicing'); |
|
282 | 282 | } |
283 | - $columns['type'] = __( 'Type', 'invoicing' ); |
|
284 | - $columns['recurring'] = __( 'Recurring', 'invoicing' ); |
|
285 | - $columns['date'] = __( 'Date', 'invoicing' ); |
|
286 | - $columns['id'] = __( 'ID', 'invoicing' ); |
|
283 | + $columns['type'] = __('Type', 'invoicing'); |
|
284 | + $columns['recurring'] = __('Recurring', 'invoicing'); |
|
285 | + $columns['date'] = __('Date', 'invoicing'); |
|
286 | + $columns['id'] = __('ID', 'invoicing'); |
|
287 | 287 | |
288 | - return apply_filters( 'wpinv_items_columns', $columns ); |
|
288 | + return apply_filters('wpinv_items_columns', $columns); |
|
289 | 289 | } |
290 | -add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' ); |
|
290 | +add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns'); |
|
291 | 291 | |
292 | -function wpinv_items_sortable_columns( $columns ) { |
|
292 | +function wpinv_items_sortable_columns($columns) { |
|
293 | 293 | $columns['price'] = 'price'; |
294 | 294 | $columns['vat_rule'] = 'vat_rule'; |
295 | 295 | $columns['vat_class'] = 'vat_class'; |
@@ -299,175 +299,175 @@ discard block |
||
299 | 299 | |
300 | 300 | return $columns; |
301 | 301 | } |
302 | -add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' ); |
|
302 | +add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns'); |
|
303 | 303 | |
304 | -function wpinv_items_table_custom_column( $column ) { |
|
304 | +function wpinv_items_table_custom_column($column) { |
|
305 | 305 | global $wpinv_euvat, $post, $wpi_item; |
306 | 306 | |
307 | - if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) { |
|
308 | - $wpi_item = new WPInv_Item( $post->ID ); |
|
307 | + if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) { |
|
308 | + $wpi_item = new WPInv_Item($post->ID); |
|
309 | 309 | } |
310 | 310 | |
311 | - switch ( $column ) { |
|
311 | + switch ($column) { |
|
312 | 312 | case 'price' : |
313 | - echo wpinv_item_price( $post->ID ); |
|
313 | + echo wpinv_item_price($post->ID); |
|
314 | 314 | break; |
315 | 315 | case 'vat_rule' : |
316 | - echo $wpinv_euvat->item_rule_label( $post->ID ); |
|
316 | + echo $wpinv_euvat->item_rule_label($post->ID); |
|
317 | 317 | break; |
318 | 318 | case 'vat_class' : |
319 | - echo $wpinv_euvat->item_class_label( $post->ID ); |
|
319 | + echo $wpinv_euvat->item_class_label($post->ID); |
|
320 | 320 | break; |
321 | 321 | case 'type' : |
322 | - echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>'; |
|
322 | + echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>'; |
|
323 | 323 | break; |
324 | 324 | case 'recurring' : |
325 | - echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' ); |
|
325 | + echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>'); |
|
326 | 326 | break; |
327 | 327 | case 'id' : |
328 | 328 | echo $post->ID; |
329 | 329 | echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
330 | - <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>'; |
|
331 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
332 | - echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>'; |
|
330 | + <div class="price">' . wpinv_get_item_price($post->ID) . '</div>'; |
|
331 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
332 | + echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>'; |
|
333 | 333 | } |
334 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
335 | - echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>'; |
|
334 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
335 | + echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>'; |
|
336 | 336 | } |
337 | - echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div> |
|
337 | + echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div> |
|
338 | 338 | </div>'; |
339 | 339 | break; |
340 | 340 | } |
341 | 341 | |
342 | - do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post ); |
|
342 | + do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post); |
|
343 | 343 | } |
344 | -add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' ); |
|
344 | +add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column'); |
|
345 | 345 | |
346 | 346 | function wpinv_add_items_filters() { |
347 | 347 | global $wpinv_euvat, $typenow; |
348 | 348 | |
349 | 349 | // Checks if the current post type is 'item' |
350 | - if ( $typenow == 'wpi_item') { |
|
351 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
350 | + if ($typenow == 'wpi_item') { |
|
351 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
352 | 352 | |
353 | 353 | // Sanitize selected vat rule. |
354 | - $vat_rule = ''; |
|
355 | - if( isset( $_GET['vat_rule'] ) && array_key_exists( $_GET['type'], $wpinv_euvat->get_rules() ) ) { |
|
356 | - $class = $_GET['type']; |
|
354 | + $vat_rule = ''; |
|
355 | + if (isset($_GET['vat_rule']) && array_key_exists($_GET['type'], $wpinv_euvat->get_rules())) { |
|
356 | + $class = $_GET['type']; |
|
357 | 357 | } |
358 | 358 | |
359 | - echo wpinv_html_select( array( |
|
360 | - 'options' => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ), |
|
359 | + echo wpinv_html_select(array( |
|
360 | + 'options' => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()), |
|
361 | 361 | 'name' => 'vat_rule', |
362 | 362 | 'id' => 'vat_rule', |
363 | - 'selected' => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ), |
|
363 | + 'selected' => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''), |
|
364 | 364 | 'show_option_all' => false, |
365 | 365 | 'show_option_none' => false, |
366 | 366 | 'class' => 'gdmbx2-text-medium wpi_select2', |
367 | - 'placeholder' => __( 'Select VAT rule', 'invoicing' ), |
|
368 | - ) ); |
|
367 | + 'placeholder' => __('Select VAT rule', 'invoicing'), |
|
368 | + )); |
|
369 | 369 | } |
370 | 370 | |
371 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
371 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
372 | 372 | |
373 | 373 | $classes = $wpinv_euvat->get_all_classes(); |
374 | 374 | |
375 | 375 | // Sanitize selected vat class. |
376 | 376 | $class = ''; |
377 | - if( isset( $_GET['vat_class'] ) && array_key_exists( $_GET['vat_class'], $classes ) ) { |
|
378 | - $class = $_GET['vat_class']; |
|
377 | + if (isset($_GET['vat_class']) && array_key_exists($_GET['vat_class'], $classes)) { |
|
378 | + $class = $_GET['vat_class']; |
|
379 | 379 | } |
380 | 380 | |
381 | - echo wpinv_html_select( array( |
|
382 | - 'options' => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $classes ), |
|
381 | + echo wpinv_html_select(array( |
|
382 | + 'options' => array_merge(array('' => __('All VAT classes', 'invoicing')), $classes), |
|
383 | 383 | 'name' => 'vat_class', |
384 | 384 | 'id' => 'vat_class', |
385 | 385 | 'selected' => $class, |
386 | 386 | 'show_option_all' => false, |
387 | 387 | 'show_option_none' => false, |
388 | 388 | 'class' => 'gdmbx2-text-medium wpi_select2', |
389 | - 'placeholder' => __( 'Select VAT class', 'invoicing' ), |
|
390 | - ) ); |
|
389 | + 'placeholder' => __('Select VAT class', 'invoicing'), |
|
390 | + )); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | // Sanitize selected item type. |
394 | - $type = ''; |
|
395 | - if( isset( $_GET['type'] ) && array_key_exists( $_GET['type'], wpinv_get_item_types() ) ) { |
|
396 | - $class = $_GET['type']; |
|
394 | + $type = ''; |
|
395 | + if (isset($_GET['type']) && array_key_exists($_GET['type'], wpinv_get_item_types())) { |
|
396 | + $class = $_GET['type']; |
|
397 | 397 | } |
398 | 398 | |
399 | - echo wpinv_html_select( array( |
|
400 | - 'options' => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ), |
|
399 | + echo wpinv_html_select(array( |
|
400 | + 'options' => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()), |
|
401 | 401 | 'name' => 'type', |
402 | 402 | 'id' => 'type', |
403 | 403 | 'selected' => $type, |
404 | 404 | 'show_option_all' => false, |
405 | 405 | 'show_option_none' => false, |
406 | 406 | 'class' => 'gdmbx2-text-medium', |
407 | - ) ); |
|
407 | + )); |
|
408 | 408 | |
409 | - if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) { |
|
409 | + if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) { |
|
410 | 410 | echo '<input type="hidden" name="all_posts" value="1" />'; |
411 | 411 | } |
412 | 412 | } |
413 | 413 | } |
414 | -add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 ); |
|
414 | +add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100); |
|
415 | 415 | |
416 | -function wpinv_send_invoice_after_save( $invoice ) { |
|
417 | - if ( empty( $_POST['wpi_save_send'] ) ) { |
|
416 | +function wpinv_send_invoice_after_save($invoice) { |
|
417 | + if (empty($_POST['wpi_save_send'])) { |
|
418 | 418 | return; |
419 | 419 | } |
420 | 420 | |
421 | - if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) { |
|
422 | - wpinv_user_invoice_notification( $invoice->ID ); |
|
421 | + if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) { |
|
422 | + wpinv_user_invoice_notification($invoice->ID); |
|
423 | 423 | } |
424 | 424 | } |
425 | -add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 ); |
|
425 | +add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1); |
|
426 | 426 | |
427 | -function wpinv_send_register_new_user( $data, $postarr ) { |
|
428 | - if ( wpinv_current_user_can_manage_invoicing() && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) { |
|
429 | - $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false; |
|
430 | - $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL; |
|
427 | +function wpinv_send_register_new_user($data, $postarr) { |
|
428 | + if (wpinv_current_user_can_manage_invoicing() && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) { |
|
429 | + $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false; |
|
430 | + $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL; |
|
431 | 431 | |
432 | - if ( $is_new_user && $email && !email_exists( $email ) ) { |
|
433 | - $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : ''; |
|
434 | - $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : ''; |
|
435 | - $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : ''; |
|
436 | - $user_nicename = $display_name ? trim( $display_name ) : $email; |
|
437 | - $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : ''; |
|
432 | + if ($is_new_user && $email && !email_exists($email)) { |
|
433 | + $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : ''; |
|
434 | + $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : ''; |
|
435 | + $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : ''; |
|
436 | + $user_nicename = $display_name ? trim($display_name) : $email; |
|
437 | + $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : ''; |
|
438 | 438 | |
439 | - $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true ); |
|
440 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
439 | + $user_login = sanitize_user(str_replace(' ', '', $display_name), true); |
|
440 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
441 | 441 | $new_user_login = strstr($email, '@', true); |
442 | - if ( validate_username( $user_login ) && username_exists( $user_login ) ) { |
|
443 | - $user_login = sanitize_user($new_user_login, true ); |
|
442 | + if (validate_username($user_login) && username_exists($user_login)) { |
|
443 | + $user_login = sanitize_user($new_user_login, true); |
|
444 | 444 | } |
445 | - if ( validate_username( $user_login ) && username_exists( $user_login ) ) { |
|
446 | - $user_append_text = rand(10,1000); |
|
447 | - $user_login = sanitize_user($new_user_login.$user_append_text, true ); |
|
445 | + if (validate_username($user_login) && username_exists($user_login)) { |
|
446 | + $user_append_text = rand(10, 1000); |
|
447 | + $user_login = sanitize_user($new_user_login . $user_append_text, true); |
|
448 | 448 | } |
449 | 449 | |
450 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
450 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
451 | 451 | $user_login = $email; |
452 | 452 | } |
453 | 453 | } |
454 | 454 | |
455 | 455 | $userdata = array( |
456 | 456 | 'user_login' => $user_login, |
457 | - 'user_pass' => wp_generate_password( 12, false ), |
|
458 | - 'user_email' => sanitize_text_field( $email ), |
|
457 | + 'user_pass' => wp_generate_password(12, false), |
|
458 | + 'user_email' => sanitize_text_field($email), |
|
459 | 459 | 'first_name' => $first_name, |
460 | 460 | 'last_name' => $last_name, |
461 | - 'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ), |
|
461 | + 'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50), |
|
462 | 462 | 'nickname' => $display_name, |
463 | 463 | 'display_name' => $display_name, |
464 | 464 | ); |
465 | 465 | |
466 | - $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata ); |
|
466 | + $userdata = apply_filters('wpinv_register_new_user_data', $userdata); |
|
467 | 467 | |
468 | - $new_user_id = wp_insert_user( $userdata ); |
|
468 | + $new_user_id = wp_insert_user($userdata); |
|
469 | 469 | |
470 | - if ( !is_wp_error( $new_user_id ) ) { |
|
470 | + if (!is_wp_error($new_user_id)) { |
|
471 | 471 | $data['post_author'] = $new_user_id; |
472 | 472 | $_POST['post_author'] = $new_user_id; |
473 | 473 | $_POST['post_author_override'] = $new_user_id; |
@@ -488,72 +488,72 @@ discard block |
||
488 | 488 | |
489 | 489 | $meta = array(); |
490 | 490 | ///$meta['_wpinv_user_id'] = $new_user_id; |
491 | - foreach ( $meta_fields as $field ) { |
|
492 | - $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : ''; |
|
491 | + foreach ($meta_fields as $field) { |
|
492 | + $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : ''; |
|
493 | 493 | } |
494 | 494 | |
495 | - $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id ); |
|
495 | + $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id); |
|
496 | 496 | |
497 | 497 | // Update user meta. |
498 | - foreach ( $meta as $key => $value ) { |
|
499 | - update_user_meta( $new_user_id, $key, $value ); |
|
498 | + foreach ($meta as $key => $value) { |
|
499 | + update_user_meta($new_user_id, $key, $value); |
|
500 | 500 | } |
501 | 501 | |
502 | - if ( function_exists( 'wp_send_new_user_notifications' ) ) { |
|
502 | + if (function_exists('wp_send_new_user_notifications')) { |
|
503 | 503 | // Send email notifications related to the creation of new user. |
504 | - wp_send_new_user_notifications( $new_user_id, 'user' ); |
|
504 | + wp_send_new_user_notifications($new_user_id, 'user'); |
|
505 | 505 | } |
506 | 506 | } else { |
507 | - wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ ); |
|
507 | + wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__); |
|
508 | 508 | } |
509 | 509 | } |
510 | 510 | } |
511 | 511 | |
512 | 512 | return $data; |
513 | 513 | } |
514 | -add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 ); |
|
514 | +add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2); |
|
515 | 515 | |
516 | -function wpinv_show_recurring_supported_gateways( $item_ID ) { |
|
516 | +function wpinv_show_recurring_supported_gateways($item_ID) { |
|
517 | 517 | $all_gateways = wpinv_get_payment_gateways(); |
518 | 518 | |
519 | - if ( !empty( $all_gateways ) ) { |
|
519 | + if (!empty($all_gateways)) { |
|
520 | 520 | $gateways = array(); |
521 | 521 | |
522 | - foreach ( $all_gateways as $key => $gateway ) { |
|
523 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
522 | + foreach ($all_gateways as $key => $gateway) { |
|
523 | + if (wpinv_gateway_support_subscription($key)) { |
|
524 | 524 | $gateways[] = $gateway['admin_label']; |
525 | 525 | } |
526 | 526 | } |
527 | 527 | |
528 | - if ( !empty( $gateways ) ) { |
|
528 | + if (!empty($gateways)) { |
|
529 | 529 | ?> |
530 | - <span class="description"><?php echo wp_sprintf( __( 'Recurring payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ); ?></span> |
|
530 | + <span class="description"><?php echo wp_sprintf(__('Recurring payments only supported by: %s', 'invoicing'), implode(', ', $gateways)); ?></span> |
|
531 | 531 | <?php |
532 | 532 | } |
533 | 533 | } |
534 | 534 | } |
535 | -add_action( 'wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1 ); |
|
535 | +add_action('wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1); |
|
536 | 536 | |
537 | -function wpinv_post_updated_messages( $messages ) { |
|
537 | +function wpinv_post_updated_messages($messages) { |
|
538 | 538 | global $post, $post_ID; |
539 | 539 | |
540 | 540 | $messages['wpi_discount'] = array( |
541 | 541 | 0 => '', |
542 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
543 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
544 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
545 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
546 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
547 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
548 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
549 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
550 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
551 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
542 | + 1 => __('Discount updated.', 'invoicing'), |
|
543 | + 2 => __('Custom field updated.', 'invoicing'), |
|
544 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
545 | + 4 => __('Discount updated.', 'invoicing'), |
|
546 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false, |
|
547 | + 6 => __('Discount updated.', 'invoicing'), |
|
548 | + 7 => __('Discount saved.', 'invoicing'), |
|
549 | + 8 => __('Discount submitted.', 'invoicing'), |
|
550 | + 9 => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
551 | + 10 => __('Discount draft updated.', 'invoicing'), |
|
552 | 552 | ); |
553 | 553 | |
554 | 554 | return $messages; |
555 | 555 | } |
556 | -add_filter( 'post_updated_messages', 'wpinv_post_updated_messages', 10, 1 ); |
|
556 | +add_filter('post_updated_messages', 'wpinv_post_updated_messages', 10, 1); |
|
557 | 557 | |
558 | 558 | add_action('admin_init', 'admin_init_example_type'); |
559 | 559 | |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | function admin_init_example_type() { |
564 | 564 | global $typenow; |
565 | 565 | |
566 | - if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) { |
|
566 | + if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') { |
|
567 | 567 | add_filter('posts_search', 'posts_search_example_type', 10, 2); |
568 | 568 | } |
569 | 569 | } |
@@ -578,9 +578,9 @@ discard block |
||
578 | 578 | global $wpdb; |
579 | 579 | |
580 | 580 | if ($query->is_main_query() && !empty($query->query['s'])) { |
581 | - $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )"; |
|
582 | - if ( ! empty( $search ) ) { |
|
583 | - $search = preg_replace( '/^ AND /', '', $search ); |
|
581 | + $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )"; |
|
582 | + if (!empty($search)) { |
|
583 | + $search = preg_replace('/^ AND /', '', $search); |
|
584 | 584 | $search = " AND ( {$search} OR ( {$conditions_str} ) )"; |
585 | 585 | } else { |
586 | 586 | $search = " AND ( {$conditions_str} )"; |
@@ -590,9 +590,9 @@ discard block |
||
590 | 590 | return $search; |
591 | 591 | } |
592 | 592 | |
593 | -add_action( 'admin_init', 'wpinv_reset_invoice_count' ); |
|
594 | -function wpinv_reset_invoice_count(){ |
|
595 | - if(isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) { |
|
593 | +add_action('admin_init', 'wpinv_reset_invoice_count'); |
|
594 | +function wpinv_reset_invoice_count() { |
|
595 | + if (isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) { |
|
596 | 596 | wpinv_update_option('invoice_sequence_start', 1); |
597 | 597 | delete_option('wpinv_last_invoice_number'); |
598 | 598 | $url = add_query_arg(array('reset_invoice_done' => 1)); |
@@ -603,8 +603,8 @@ discard block |
||
603 | 603 | } |
604 | 604 | |
605 | 605 | add_action('admin_notices', 'wpinv_invoice_count_reset_message'); |
606 | -function wpinv_invoice_count_reset_message(){ |
|
607 | - if(isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) { |
|
606 | +function wpinv_invoice_count_reset_message() { |
|
607 | + if (isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) { |
|
608 | 608 | $notice = __('Invoice number sequence reset successfully.', 'invoicing'); |
609 | 609 | ?> |
610 | 610 | <div class="notice notice-success is-dismissible"> |
@@ -7,28 +7,28 @@ 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 | class WPInv_Ajax { |
15 | 15 | public static function init() { |
16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
18 | 18 | self::add_ajax_events(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function define_ajax() { |
22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
24 | - define( 'DOING_AJAX', true ); |
|
22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
23 | + if (!defined('DOING_AJAX')) { |
|
24 | + define('DOING_AJAX', true); |
|
25 | 25 | } |
26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
27 | - define( 'WC_DOING_AJAX', true ); |
|
26 | + if (!defined('WC_DOING_AJAX')) { |
|
27 | + define('WC_DOING_AJAX', true); |
|
28 | 28 | } |
29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
31 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
32 | 32 | } |
33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | public static function do_wpinv_ajax() { |
38 | 38 | global $wp_query; |
39 | 39 | |
40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
45 | 45 | self::wpinv_ajax_headers(); |
46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
47 | 47 | die(); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function wpinv_ajax_headers() { |
52 | 52 | send_origin_headers(); |
53 | - /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' ); |
|
53 | + /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex'); |
|
55 | 55 | send_nosniff_header(); |
56 | 56 | nocache_headers(); |
57 | - status_header( 200 ); |
|
57 | + status_header(200); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public static function add_ajax_events() { |
@@ -77,39 +77,39 @@ discard block |
||
77 | 77 | 'buy_items' => true, |
78 | 78 | ); |
79 | 79 | |
80 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
81 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
80 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
81 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
82 | 82 | |
83 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
84 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
83 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
84 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
85 | 85 | } |
86 | 86 | |
87 | - if ( $nopriv ) { |
|
88 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
87 | + if ($nopriv) { |
|
88 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
89 | 89 | |
90 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
90 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | 95 | public static function add_note() { |
96 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
96 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
97 | 97 | |
98 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
98 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
99 | 99 | die(-1); |
100 | 100 | } |
101 | 101 | |
102 | - $post_id = absint( $_POST['post_id'] ); |
|
103 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
104 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
102 | + $post_id = absint($_POST['post_id']); |
|
103 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
104 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
105 | 105 | |
106 | 106 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
107 | 107 | |
108 | - if ( $post_id > 0 ) { |
|
109 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
108 | + if ($post_id > 0) { |
|
109 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
110 | 110 | |
111 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
112 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
111 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
112 | + wpinv_get_invoice_note_line_item($note_id); |
|
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
@@ -117,16 +117,16 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | public static function delete_note() { |
120 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
120 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
121 | 121 | |
122 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
122 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
123 | 123 | die(-1); |
124 | 124 | } |
125 | 125 | |
126 | - $note_id = (int)$_POST['note_id']; |
|
126 | + $note_id = (int) $_POST['note_id']; |
|
127 | 127 | |
128 | - if ( $note_id > 0 ) { |
|
129 | - wp_delete_comment( $note_id, true ); |
|
128 | + if ($note_id > 0) { |
|
129 | + wp_delete_comment($note_id, true); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | die(); |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | } |
140 | 140 | |
141 | 141 | public static function checkout() { |
142 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
143 | - define( 'WPINV_CHECKOUT', true ); |
|
142 | + if (!defined('WPINV_CHECKOUT')) { |
|
143 | + define('WPINV_CHECKOUT', true); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | wpinv_process_checkout(); |
@@ -149,53 +149,53 @@ discard block |
||
149 | 149 | |
150 | 150 | public static function add_invoice_item() { |
151 | 151 | global $wpi_userID, $wpinv_ip_address_country; |
152 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
153 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
152 | + check_ajax_referer('invoice-item', '_nonce'); |
|
153 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
154 | 154 | die(-1); |
155 | 155 | } |
156 | 156 | |
157 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
158 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
157 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
158 | + $invoice_id = absint($_POST['invoice_id']); |
|
159 | 159 | |
160 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
160 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
161 | 161 | die(); |
162 | 162 | } |
163 | 163 | |
164 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
165 | - if ( empty( $invoice ) ) { |
|
164 | + $invoice = wpinv_get_invoice($invoice_id); |
|
165 | + if (empty($invoice)) { |
|
166 | 166 | die(); |
167 | 167 | } |
168 | 168 | |
169 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
169 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
170 | 170 | die(); // Don't allow modify items for paid invoice. |
171 | 171 | } |
172 | 172 | |
173 | - if ( !empty( $_POST['user_id'] ) ) { |
|
174 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
173 | + if (!empty($_POST['user_id'])) { |
|
174 | + $wpi_userID = absint($_POST['user_id']); |
|
175 | 175 | } |
176 | 176 | |
177 | - $item = new WPInv_Item( $item_id ); |
|
178 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
177 | + $item = new WPInv_Item($item_id); |
|
178 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
179 | 179 | die(); |
180 | 180 | } |
181 | 181 | |
182 | 182 | // Validate item before adding to invoice because recurring item must be paid individually. |
183 | - if ( !empty( $invoice->cart_details ) ) { |
|
183 | + if (!empty($invoice->cart_details)) { |
|
184 | 184 | $valid = true; |
185 | 185 | |
186 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
187 | - if ( $recurring_item != $item_id ) { |
|
186 | + if ($recurring_item = $invoice->get_recurring()) { |
|
187 | + if ($recurring_item != $item_id) { |
|
188 | 188 | $valid = false; |
189 | 189 | } |
190 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
190 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
191 | 191 | $valid = false; |
192 | 192 | } |
193 | 193 | |
194 | - if ( !$valid ) { |
|
194 | + if (!$valid) { |
|
195 | 195 | $response = array(); |
196 | 196 | $response['success'] = false; |
197 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
198 | - wp_send_json( $response ); |
|
197 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
198 | + wp_send_json($response); |
|
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
@@ -203,11 +203,11 @@ discard block |
||
203 | 203 | |
204 | 204 | $data = array(); |
205 | 205 | $data['invoice_id'] = $invoice_id; |
206 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
206 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
207 | 207 | |
208 | - wpinv_set_checkout_session( $data ); |
|
208 | + wpinv_set_checkout_session($data); |
|
209 | 209 | |
210 | - $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
|
210 | + $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1; |
|
211 | 211 | |
212 | 212 | $args = array( |
213 | 213 | 'id' => $item_id, |
@@ -220,21 +220,21 @@ discard block |
||
220 | 220 | 'fees' => array() |
221 | 221 | ); |
222 | 222 | |
223 | - $invoice->add_item( $item_id, $args ); |
|
223 | + $invoice->add_item($item_id, $args); |
|
224 | 224 | $invoice->save(); |
225 | 225 | |
226 | - if ( empty( $_POST['country'] ) ) { |
|
226 | + if (empty($_POST['country'])) { |
|
227 | 227 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
228 | 228 | } |
229 | - if ( empty( $_POST['state'] ) ) { |
|
229 | + if (empty($_POST['state'])) { |
|
230 | 230 | $_POST['state'] = $invoice->state; |
231 | 231 | } |
232 | 232 | |
233 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
234 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
233 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
234 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
235 | 235 | |
236 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
237 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
236 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
237 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
238 | 238 | |
239 | 239 | $wpinv_ip_address_country = $invoice->country; |
240 | 240 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | |
243 | 243 | $response = array(); |
244 | 244 | $response['success'] = true; |
245 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
245 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
246 | 246 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
247 | 247 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
248 | 248 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -254,40 +254,40 @@ discard block |
||
254 | 254 | |
255 | 255 | wpinv_set_checkout_session($checkout_session); |
256 | 256 | |
257 | - wp_send_json( $response ); |
|
257 | + wp_send_json($response); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | public static function remove_invoice_item() { |
261 | 261 | global $wpi_userID, $wpinv_ip_address_country; |
262 | 262 | |
263 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
264 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
263 | + check_ajax_referer('invoice-item', '_nonce'); |
|
264 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
265 | 265 | die(-1); |
266 | 266 | } |
267 | 267 | |
268 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
269 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
270 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
268 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
269 | + $invoice_id = absint($_POST['invoice_id']); |
|
270 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
271 | 271 | |
272 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
272 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
273 | 273 | die(); |
274 | 274 | } |
275 | 275 | |
276 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
277 | - if ( empty( $invoice ) ) { |
|
276 | + $invoice = wpinv_get_invoice($invoice_id); |
|
277 | + if (empty($invoice)) { |
|
278 | 278 | die(); |
279 | 279 | } |
280 | 280 | |
281 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
281 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
282 | 282 | die(); // Don't allow modify items for paid invoice. |
283 | 283 | } |
284 | 284 | |
285 | - if ( !empty( $_POST['user_id'] ) ) { |
|
286 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
285 | + if (!empty($_POST['user_id'])) { |
|
286 | + $wpi_userID = absint($_POST['user_id']); |
|
287 | 287 | } |
288 | 288 | |
289 | - $item = new WPInv_Item( $item_id ); |
|
290 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
289 | + $item = new WPInv_Item($item_id); |
|
290 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
291 | 291 | die(); |
292 | 292 | } |
293 | 293 | |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | |
296 | 296 | $data = array(); |
297 | 297 | $data['invoice_id'] = $invoice_id; |
298 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
298 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
299 | 299 | |
300 | - wpinv_set_checkout_session( $data ); |
|
300 | + wpinv_set_checkout_session($data); |
|
301 | 301 | |
302 | 302 | $args = array( |
303 | 303 | 'id' => $item_id, |
@@ -305,21 +305,21 @@ discard block |
||
305 | 305 | 'cart_index' => $cart_index |
306 | 306 | ); |
307 | 307 | |
308 | - $invoice->remove_item( $item_id, $args ); |
|
308 | + $invoice->remove_item($item_id, $args); |
|
309 | 309 | $invoice->save(); |
310 | 310 | |
311 | - if ( empty( $_POST['country'] ) ) { |
|
311 | + if (empty($_POST['country'])) { |
|
312 | 312 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
313 | 313 | } |
314 | - if ( empty( $_POST['state'] ) ) { |
|
314 | + if (empty($_POST['state'])) { |
|
315 | 315 | $_POST['state'] = $invoice->state; |
316 | 316 | } |
317 | 317 | |
318 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
319 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
318 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
319 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
320 | 320 | |
321 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
322 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
321 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
322 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
323 | 323 | |
324 | 324 | $wpinv_ip_address_country = $invoice->country; |
325 | 325 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | |
328 | 328 | $response = array(); |
329 | 329 | $response['success'] = true; |
330 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
330 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
331 | 331 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
332 | 332 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
333 | 333 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -339,40 +339,40 @@ discard block |
||
339 | 339 | |
340 | 340 | wpinv_set_checkout_session($checkout_session); |
341 | 341 | |
342 | - wp_send_json( $response ); |
|
342 | + wp_send_json($response); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | public static function create_invoice_item() { |
346 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
347 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
346 | + check_ajax_referer('invoice-item', '_nonce'); |
|
347 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
348 | 348 | die(-1); |
349 | 349 | } |
350 | 350 | |
351 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
351 | + $invoice_id = absint($_POST['invoice_id']); |
|
352 | 352 | |
353 | 353 | // Find the item |
354 | - if ( !is_numeric( $invoice_id ) ) { |
|
354 | + if (!is_numeric($invoice_id)) { |
|
355 | 355 | die(); |
356 | 356 | } |
357 | 357 | |
358 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
359 | - if ( empty( $invoice ) ) { |
|
358 | + $invoice = wpinv_get_invoice($invoice_id); |
|
359 | + if (empty($invoice)) { |
|
360 | 360 | die(); |
361 | 361 | } |
362 | 362 | |
363 | 363 | // Validate item before adding to invoice because recurring item must be paid individually. |
364 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
364 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
365 | 365 | $response = array(); |
366 | 366 | $response['success'] = false; |
367 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
368 | - wp_send_json( $response ); |
|
367 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
368 | + wp_send_json($response); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | $save_item = $_POST['_wpinv_quick']; |
372 | 372 | |
373 | 373 | $meta = array(); |
374 | 374 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
375 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
375 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
376 | 376 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
377 | 377 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
378 | 378 | |
@@ -382,11 +382,11 @@ discard block |
||
382 | 382 | $data['meta'] = $meta; |
383 | 383 | |
384 | 384 | $item = new WPInv_Item(); |
385 | - $item->create( $data ); |
|
385 | + $item->create($data); |
|
386 | 386 | |
387 | - if ( !empty( $item ) ) { |
|
387 | + if (!empty($item)) { |
|
388 | 388 | $_POST['item_id'] = $item->ID; |
389 | - $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
|
389 | + $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1; |
|
390 | 390 | |
391 | 391 | self::add_invoice_item(); |
392 | 392 | } |
@@ -394,15 +394,15 @@ discard block |
||
394 | 394 | } |
395 | 395 | |
396 | 396 | public static function get_billing_details() { |
397 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
397 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
398 | 398 | |
399 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
399 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
400 | 400 | die(-1); |
401 | 401 | } |
402 | 402 | |
403 | - $user_id = (int)$_POST['user_id']; |
|
403 | + $user_id = (int) $_POST['user_id']; |
|
404 | 404 | $billing_details = wpinv_get_user_address($user_id); |
405 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
405 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
406 | 406 | |
407 | 407 | if (isset($billing_details['user_id'])) { |
408 | 408 | unset($billing_details['user_id']); |
@@ -416,20 +416,20 @@ discard block |
||
416 | 416 | $response['success'] = true; |
417 | 417 | $response['data']['billing_details'] = $billing_details; |
418 | 418 | |
419 | - wp_send_json( $response ); |
|
419 | + wp_send_json($response); |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | public static function admin_recalculate_totals() { |
423 | 423 | global $wpi_userID, $wpinv_ip_address_country; |
424 | 424 | |
425 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
426 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
425 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
426 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
427 | 427 | die(-1); |
428 | 428 | } |
429 | 429 | |
430 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
431 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
432 | - if ( empty( $invoice ) ) { |
|
430 | + $invoice_id = absint($_POST['invoice_id']); |
|
431 | + $invoice = wpinv_get_invoice($invoice_id); |
|
432 | + if (empty($invoice)) { |
|
433 | 433 | die(); |
434 | 434 | } |
435 | 435 | |
@@ -437,23 +437,23 @@ discard block |
||
437 | 437 | |
438 | 438 | $data = array(); |
439 | 439 | $data['invoice_id'] = $invoice_id; |
440 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
440 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
441 | 441 | |
442 | - wpinv_set_checkout_session( $data ); |
|
442 | + wpinv_set_checkout_session($data); |
|
443 | 443 | |
444 | - if ( !empty( $_POST['user_id'] ) ) { |
|
445 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
444 | + if (!empty($_POST['user_id'])) { |
|
445 | + $wpi_userID = absint($_POST['user_id']); |
|
446 | 446 | } |
447 | 447 | |
448 | - if ( empty( $_POST['country'] ) ) { |
|
448 | + if (empty($_POST['country'])) { |
|
449 | 449 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
450 | 450 | } |
451 | 451 | |
452 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
453 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
454 | - if ( isset( $_POST['state'] ) ) { |
|
455 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
456 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
452 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
453 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
454 | + if (isset($_POST['state'])) { |
|
455 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
456 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | $wpinv_ip_address_country = $invoice->country; |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | |
463 | 463 | $response = array(); |
464 | 464 | $response['success'] = true; |
465 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
465 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
466 | 466 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
467 | 467 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
468 | 468 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -474,25 +474,25 @@ discard block |
||
474 | 474 | |
475 | 475 | wpinv_set_checkout_session($checkout_session); |
476 | 476 | |
477 | - wp_send_json( $response ); |
|
477 | + wp_send_json($response); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | public static function admin_apply_discount() { |
481 | 481 | global $wpi_userID; |
482 | 482 | |
483 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
484 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
483 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
484 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
485 | 485 | die(-1); |
486 | 486 | } |
487 | 487 | |
488 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
489 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
490 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
488 | + $invoice_id = absint($_POST['invoice_id']); |
|
489 | + $discount_code = sanitize_text_field($_POST['code']); |
|
490 | + if (empty($invoice_id) || empty($discount_code)) { |
|
491 | 491 | die(); |
492 | 492 | } |
493 | 493 | |
494 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
495 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
494 | + $invoice = wpinv_get_invoice($invoice_id); |
|
495 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
496 | 496 | die(); |
497 | 497 | } |
498 | 498 | |
@@ -500,49 +500,49 @@ discard block |
||
500 | 500 | |
501 | 501 | $data = array(); |
502 | 502 | $data['invoice_id'] = $invoice_id; |
503 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
503 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
504 | 504 | |
505 | - wpinv_set_checkout_session( $data ); |
|
505 | + wpinv_set_checkout_session($data); |
|
506 | 506 | |
507 | 507 | $response = array(); |
508 | 508 | $response['success'] = false; |
509 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
509 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
510 | 510 | $response['data']['code'] = $discount_code; |
511 | 511 | |
512 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
513 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
512 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
513 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
514 | 514 | |
515 | 515 | $response['success'] = true; |
516 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
517 | - } else { |
|
516 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
517 | + } else { |
|
518 | 518 | $errors = wpinv_get_errors(); |
519 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
519 | + if (!empty($errors['wpinv-discount-error'])) { |
|
520 | 520 | $response['msg'] = $errors['wpinv-discount-error']; |
521 | 521 | } |
522 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
522 | + wpinv_unset_error('wpinv-discount-error'); |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | wpinv_set_checkout_session($checkout_session); |
526 | 526 | |
527 | - wp_send_json( $response ); |
|
527 | + wp_send_json($response); |
|
528 | 528 | } |
529 | 529 | |
530 | 530 | public static function admin_remove_discount() { |
531 | 531 | global $wpi_userID; |
532 | 532 | |
533 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
534 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
533 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
534 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
535 | 535 | die(-1); |
536 | 536 | } |
537 | 537 | |
538 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
539 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
540 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
538 | + $invoice_id = absint($_POST['invoice_id']); |
|
539 | + $discount_code = sanitize_text_field($_POST['code']); |
|
540 | + if (empty($invoice_id) || empty($discount_code)) { |
|
541 | 541 | die(); |
542 | 542 | } |
543 | 543 | |
544 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
545 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
544 | + $invoice = wpinv_get_invoice($invoice_id); |
|
545 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
546 | 546 | die(); |
547 | 547 | } |
548 | 548 | |
@@ -550,38 +550,38 @@ discard block |
||
550 | 550 | |
551 | 551 | $data = array(); |
552 | 552 | $data['invoice_id'] = $invoice_id; |
553 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
553 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
554 | 554 | |
555 | - wpinv_set_checkout_session( $data ); |
|
555 | + wpinv_set_checkout_session($data); |
|
556 | 556 | |
557 | 557 | $response = array(); |
558 | 558 | $response['success'] = false; |
559 | 559 | $response['msg'] = NULL; |
560 | 560 | |
561 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
561 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
562 | 562 | $response['success'] = true; |
563 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
563 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
564 | 564 | |
565 | 565 | wpinv_set_checkout_session($checkout_session); |
566 | 566 | |
567 | - wp_send_json( $response ); |
|
567 | + wp_send_json($response); |
|
568 | 568 | } |
569 | 569 | |
570 | 570 | public static function check_email() { |
571 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
572 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
571 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
572 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
573 | 573 | die(-1); |
574 | 574 | } |
575 | 575 | |
576 | - $email = sanitize_text_field( $_POST['email'] ); |
|
576 | + $email = sanitize_text_field($_POST['email']); |
|
577 | 577 | |
578 | 578 | $response = array(); |
579 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
579 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
580 | 580 | $user_id = $user_data->ID; |
581 | 581 | $user_login = $user_data->user_login; |
582 | 582 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
583 | 583 | $billing_details = wpinv_get_user_address($user_id); |
584 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
584 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
585 | 585 | |
586 | 586 | if (isset($billing_details['user_id'])) { |
587 | 587 | unset($billing_details['user_id']); |
@@ -597,54 +597,54 @@ discard block |
||
597 | 597 | $response['data']['billing_details'] = $billing_details; |
598 | 598 | } |
599 | 599 | |
600 | - wp_send_json( $response ); |
|
600 | + wp_send_json($response); |
|
601 | 601 | } |
602 | 602 | |
603 | 603 | public static function run_tool() { |
604 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
605 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
604 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
605 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
606 | 606 | die(-1); |
607 | 607 | } |
608 | 608 | |
609 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
609 | + $tool = sanitize_text_field($_POST['tool']); |
|
610 | 610 | |
611 | - do_action( 'wpinv_run_tool' ); |
|
611 | + do_action('wpinv_run_tool'); |
|
612 | 612 | |
613 | - if ( !empty( $tool ) ) { |
|
614 | - do_action( 'wpinv_tool_' . $tool ); |
|
613 | + if (!empty($tool)) { |
|
614 | + do_action('wpinv_tool_' . $tool); |
|
615 | 615 | } |
616 | 616 | } |
617 | 617 | |
618 | 618 | public static function apply_discount() { |
619 | 619 | global $wpi_userID; |
620 | 620 | |
621 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
621 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
622 | 622 | |
623 | 623 | $response = array(); |
624 | 624 | |
625 | - if ( isset( $_POST['code'] ) ) { |
|
626 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
625 | + if (isset($_POST['code'])) { |
|
626 | + $discount_code = sanitize_text_field($_POST['code']); |
|
627 | 627 | |
628 | 628 | $response['success'] = false; |
629 | 629 | $response['msg'] = ''; |
630 | 630 | $response['data']['code'] = $discount_code; |
631 | 631 | |
632 | 632 | $invoice = wpinv_get_invoice_cart(); |
633 | - if ( empty( $invoice->ID ) ) { |
|
634 | - $response['msg'] = __( 'Invalid checkout request.', 'invoicing' ); |
|
635 | - wp_send_json( $response ); |
|
633 | + if (empty($invoice->ID)) { |
|
634 | + $response['msg'] = __('Invalid checkout request.', 'invoicing'); |
|
635 | + wp_send_json($response); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | $wpi_userID = $invoice->get_user_id(); |
639 | 639 | |
640 | - if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) { |
|
641 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
642 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
643 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
644 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
645 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
640 | + if (wpinv_is_discount_valid($discount_code, $wpi_userID)) { |
|
641 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
642 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
643 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
644 | + $total = wpinv_get_cart_total(null, $discounts); |
|
645 | + $cart_totals = wpinv_recalculate_tax(true); |
|
646 | 646 | |
647 | - if ( !empty( $cart_totals ) ) { |
|
647 | + if (!empty($cart_totals)) { |
|
648 | 648 | $response['success'] = true; |
649 | 649 | $response['data'] = $cart_totals; |
650 | 650 | $response['data']['code'] = $discount_code; |
@@ -653,29 +653,29 @@ discard block |
||
653 | 653 | } |
654 | 654 | } else { |
655 | 655 | $errors = wpinv_get_errors(); |
656 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
657 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
656 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
657 | + wpinv_unset_error('wpinv-discount-error'); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // Allow for custom discount code handling |
661 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
661 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
662 | 662 | } |
663 | 663 | |
664 | - wp_send_json( $response ); |
|
664 | + wp_send_json($response); |
|
665 | 665 | } |
666 | 666 | |
667 | 667 | public static function remove_discount() { |
668 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
668 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
669 | 669 | |
670 | 670 | $response = array(); |
671 | 671 | |
672 | - if ( isset( $_POST['code'] ) ) { |
|
673 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
674 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
675 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
676 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
672 | + if (isset($_POST['code'])) { |
|
673 | + $discount_code = sanitize_text_field($_POST['code']); |
|
674 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
675 | + $total = wpinv_get_cart_total(null, $discounts); |
|
676 | + $cart_totals = wpinv_recalculate_tax(true); |
|
677 | 677 | |
678 | - if ( !empty( $cart_totals ) ) { |
|
678 | + if (!empty($cart_totals)) { |
|
679 | 679 | $response['success'] = true; |
680 | 680 | $response['data'] = $cart_totals; |
681 | 681 | $response['data']['code'] = $discount_code; |
@@ -684,10 +684,10 @@ discard block |
||
684 | 684 | } |
685 | 685 | |
686 | 686 | // Allow for custom discount code handling |
687 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
687 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
688 | 688 | } |
689 | 689 | |
690 | - wp_send_json( $response ); |
|
690 | + wp_send_json($response); |
|
691 | 691 | } |
692 | 692 | |
693 | 693 | |
@@ -699,53 +699,53 @@ discard block |
||
699 | 699 | public static function buy_items() { |
700 | 700 | $user_id = get_current_user_id(); |
701 | 701 | |
702 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
703 | - wp_send_json( array( |
|
704 | - 'success' => wp_login_url( wp_get_referer() ) |
|
705 | - ) ); |
|
702 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
703 | + wp_send_json(array( |
|
704 | + 'success' => wp_login_url(wp_get_referer()) |
|
705 | + )); |
|
706 | 706 | } else { |
707 | 707 | // Only check nonce if logged in as it could be cached when logged out. |
708 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
709 | - wp_send_json( array( |
|
710 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
711 | - ) ); |
|
708 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
709 | + wp_send_json(array( |
|
710 | + 'error' => __('Security checks failed.', 'invoicing') |
|
711 | + )); |
|
712 | 712 | wp_die(); |
713 | 713 | } |
714 | 714 | |
715 | 715 | // allow to set a custom price through post_id |
716 | 716 | $items = $_POST['items']; |
717 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
718 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
717 | + $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0; |
|
718 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
719 | 719 | |
720 | 720 | $cart_items = array(); |
721 | - if ( $items ) { |
|
722 | - $items = explode( ',', $items ); |
|
721 | + if ($items) { |
|
722 | + $items = explode(',', $items); |
|
723 | 723 | |
724 | - foreach( $items as $item ) { |
|
724 | + foreach ($items as $item) { |
|
725 | 725 | $item_id = $item; |
726 | 726 | $quantity = 1; |
727 | 727 | |
728 | - if ( strpos( $item, '|' ) !== false ) { |
|
729 | - $item_parts = explode( '|', $item ); |
|
728 | + if (strpos($item, '|') !== false) { |
|
729 | + $item_parts = explode('|', $item); |
|
730 | 730 | $item_id = $item_parts[0]; |
731 | 731 | $quantity = $item_parts[1]; |
732 | 732 | } |
733 | 733 | |
734 | - if ( $item_id && $quantity ) { |
|
734 | + if ($item_id && $quantity) { |
|
735 | 735 | $cart_items_arr = array( |
736 | - 'id' => (int)$item_id, |
|
737 | - 'quantity' => (int)$quantity |
|
736 | + 'id' => (int) $item_id, |
|
737 | + 'quantity' => (int) $quantity |
|
738 | 738 | ); |
739 | 739 | |
740 | 740 | // If there is a related post id then add it to meta |
741 | - if ( $related_post_id ) { |
|
741 | + if ($related_post_id) { |
|
742 | 742 | $cart_items_arr['meta'] = array( |
743 | 743 | 'post_id' => $related_post_id |
744 | 744 | ); |
745 | 745 | } |
746 | 746 | |
747 | 747 | // If there is a custom price then set it. |
748 | - if ( $custom_item_price ) { |
|
748 | + if ($custom_item_price) { |
|
749 | 749 | $cart_items_arr['custom_price'] = $custom_item_price; |
750 | 750 | } |
751 | 751 | |
@@ -761,37 +761,37 @@ discard block |
||
761 | 761 | * @param int $related_post_id The related post id if any. |
762 | 762 | * @since 1.0.0 |
763 | 763 | */ |
764 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
764 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
765 | 765 | |
766 | 766 | // Make sure its not in the cart already, if it is then redirect to checkout. |
767 | 767 | $cart_invoice = wpinv_get_invoice_cart(); |
768 | 768 | |
769 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
770 | - wp_send_json( array( |
|
769 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
770 | + wp_send_json(array( |
|
771 | 771 | 'success' => $cart_invoice->get_checkout_payment_url() |
772 | - ) ); |
|
772 | + )); |
|
773 | 773 | wp_die(); |
774 | 774 | } |
775 | 775 | |
776 | 776 | // Check if user has invoice with same items waiting to be paid. |
777 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
778 | - if ( !empty( $user_invoices ) ) { |
|
779 | - foreach( $user_invoices as $user_invoice ) { |
|
777 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
778 | + if (!empty($user_invoices)) { |
|
779 | + foreach ($user_invoices as $user_invoice) { |
|
780 | 780 | $user_cart_details = array(); |
781 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
781 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
782 | 782 | $cart_details = $invoice->get_cart_details(); |
783 | 783 | |
784 | - if ( !empty( $cart_details ) ) { |
|
785 | - foreach ( $cart_details as $invoice_item ) { |
|
784 | + if (!empty($cart_details)) { |
|
785 | + foreach ($cart_details as $invoice_item) { |
|
786 | 786 | $ii_arr = array(); |
787 | - $ii_arr['id'] = (int)$invoice_item['id']; |
|
788 | - $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
|
787 | + $ii_arr['id'] = (int) $invoice_item['id']; |
|
788 | + $ii_arr['quantity'] = (int) $invoice_item['quantity']; |
|
789 | 789 | |
790 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
790 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
791 | 791 | $ii_arr['meta'] = $invoice_item['meta']; |
792 | 792 | } |
793 | 793 | |
794 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
794 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
795 | 795 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
796 | 796 | } |
797 | 797 | |
@@ -799,17 +799,17 @@ discard block |
||
799 | 799 | } |
800 | 800 | } |
801 | 801 | |
802 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
803 | - wp_send_json( array( |
|
802 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
803 | + wp_send_json(array( |
|
804 | 804 | 'success' => $invoice->get_checkout_payment_url() |
805 | - ) ); |
|
805 | + )); |
|
806 | 806 | wp_die(); |
807 | 807 | } |
808 | 808 | } |
809 | 809 | } |
810 | 810 | |
811 | 811 | // Create invoice and send user to checkout |
812 | - if ( !empty( $cart_items ) ) { |
|
812 | + if (!empty($cart_items)) { |
|
813 | 813 | $invoice_data = array( |
814 | 814 | 'status' => 'wpi-pending', |
815 | 815 | 'created_via' => 'wpi', |
@@ -817,21 +817,21 @@ discard block |
||
817 | 817 | 'cart_details' => $cart_items, |
818 | 818 | ); |
819 | 819 | |
820 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
820 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
821 | 821 | |
822 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
823 | - wp_send_json( array( |
|
822 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
823 | + wp_send_json(array( |
|
824 | 824 | 'success' => $invoice->get_checkout_payment_url() |
825 | - ) ); |
|
825 | + )); |
|
826 | 826 | } else { |
827 | - wp_send_json( array( |
|
828 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
829 | - ) ); |
|
827 | + wp_send_json(array( |
|
828 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
829 | + )); |
|
830 | 830 | } |
831 | 831 | } else { |
832 | - wp_send_json( array( |
|
833 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
834 | - ) ); |
|
832 | + wp_send_json(array( |
|
833 | + 'error' => __('Items not valid.', 'invoicing') |
|
834 | + )); |
|
835 | 835 | } |
836 | 836 | } |
837 | 837 |
@@ -7,206 +7,206 @@ 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_get_payment_gateways() { |
15 | 15 | // Default, built-in gateways |
16 | 16 | $gateways = array( |
17 | 17 | 'paypal' => array( |
18 | - 'admin_label' => __( 'PayPal Standard', 'invoicing' ), |
|
19 | - 'checkout_label' => __( 'PayPal Standard', 'invoicing' ), |
|
18 | + 'admin_label' => __('PayPal Standard', 'invoicing'), |
|
19 | + 'checkout_label' => __('PayPal Standard', 'invoicing'), |
|
20 | 20 | 'ordering' => 1, |
21 | 21 | ), |
22 | 22 | 'authorizenet' => array( |
23 | - 'admin_label' => __( 'Authorize.Net (AIM)', 'invoicing' ), |
|
24 | - 'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ), |
|
23 | + 'admin_label' => __('Authorize.Net (AIM)', 'invoicing'), |
|
24 | + 'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'), |
|
25 | 25 | 'ordering' => 4, |
26 | 26 | ), |
27 | 27 | 'worldpay' => array( |
28 | - 'admin_label' => __( 'Worldpay', 'invoicing' ), |
|
29 | - 'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ), |
|
28 | + 'admin_label' => __('Worldpay', 'invoicing'), |
|
29 | + 'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'), |
|
30 | 30 | 'ordering' => 5, |
31 | 31 | ), |
32 | 32 | 'bank_transfer' => array( |
33 | - 'admin_label' => __( 'Pre Bank Transfer', 'invoicing' ), |
|
34 | - 'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ), |
|
33 | + 'admin_label' => __('Pre Bank Transfer', 'invoicing'), |
|
34 | + 'checkout_label' => __('Pre Bank Transfer', 'invoicing'), |
|
35 | 35 | 'ordering' => 11, |
36 | 36 | ), |
37 | 37 | 'manual' => array( |
38 | - 'admin_label' => __( 'Test Payment', 'invoicing' ), |
|
39 | - 'checkout_label' => __( 'Test Payment', 'invoicing' ), |
|
38 | + 'admin_label' => __('Test Payment', 'invoicing'), |
|
39 | + 'checkout_label' => __('Test Payment', 'invoicing'), |
|
40 | 40 | 'ordering' => 12, |
41 | 41 | ), |
42 | 42 | ); |
43 | 43 | |
44 | - return apply_filters( 'wpinv_payment_gateways', $gateways ); |
|
44 | + return apply_filters('wpinv_payment_gateways', $gateways); |
|
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_payment_gateway_titles( $all_gateways ) { |
|
47 | +function wpinv_payment_gateway_titles($all_gateways) { |
|
48 | 48 | global $wpinv_options; |
49 | 49 | |
50 | 50 | $gateways = array(); |
51 | - foreach ( $all_gateways as $key => $gateway ) { |
|
52 | - if ( !empty( $wpinv_options[$key . '_title'] ) ) { |
|
53 | - $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' ); |
|
51 | + foreach ($all_gateways as $key => $gateway) { |
|
52 | + if (!empty($wpinv_options[$key . '_title'])) { |
|
53 | + $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing'); |
|
54 | 54 | } |
55 | 55 | |
56 | - $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' ); |
|
56 | + $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : ''); |
|
57 | 57 | } |
58 | 58 | |
59 | - asort( $gateways ); |
|
59 | + asort($gateways); |
|
60 | 60 | |
61 | - foreach ( $gateways as $gateway => $key ) { |
|
61 | + foreach ($gateways as $gateway => $key) { |
|
62 | 62 | $gateways[$gateway] = $all_gateways[$gateway]; |
63 | 63 | } |
64 | 64 | |
65 | 65 | return $gateways; |
66 | 66 | } |
67 | -add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 ); |
|
67 | +add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1); |
|
68 | 68 | |
69 | -function wpinv_get_enabled_payment_gateways( $sort = false ) { |
|
69 | +function wpinv_get_enabled_payment_gateways($sort = false) { |
|
70 | 70 | $gateways = wpinv_get_payment_gateways(); |
71 | - $enabled = wpinv_get_option( 'gateways', false ); |
|
71 | + $enabled = wpinv_get_option('gateways', false); |
|
72 | 72 | |
73 | 73 | $gateway_list = array(); |
74 | 74 | |
75 | - foreach ( $gateways as $key => $gateway ) { |
|
76 | - if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) { |
|
77 | - $gateway_list[ $key ] = $gateway; |
|
75 | + foreach ($gateways as $key => $gateway) { |
|
76 | + if (isset($enabled[$key]) && $enabled[$key] == 1) { |
|
77 | + $gateway_list[$key] = $gateway; |
|
78 | 78 | } |
79 | 79 | } |
80 | 80 | |
81 | - if ( true === $sort ) { |
|
82 | - uasort( $gateway_list, 'wpinv_sort_gateway_order' ); |
|
81 | + if (true === $sort) { |
|
82 | + uasort($gateway_list, 'wpinv_sort_gateway_order'); |
|
83 | 83 | |
84 | 84 | // Reorder our gateways so the default is first |
85 | 85 | $default_gateway_id = wpinv_get_default_gateway(); |
86 | 86 | |
87 | - if ( wpinv_is_gateway_active( $default_gateway_id ) ) { |
|
88 | - $default_gateway = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] ); |
|
89 | - unset( $gateway_list[ $default_gateway_id ] ); |
|
87 | + if (wpinv_is_gateway_active($default_gateway_id)) { |
|
88 | + $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]); |
|
89 | + unset($gateway_list[$default_gateway_id]); |
|
90 | 90 | |
91 | - $gateway_list = array_merge( $default_gateway, $gateway_list ); |
|
91 | + $gateway_list = array_merge($default_gateway, $gateway_list); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | - return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list ); |
|
95 | + return apply_filters('wpinv_enabled_payment_gateways', $gateway_list); |
|
96 | 96 | } |
97 | 97 | |
98 | -function wpinv_sort_gateway_order( $a, $b ) { |
|
98 | +function wpinv_sort_gateway_order($a, $b) { |
|
99 | 99 | return $a['ordering'] - $b['ordering']; |
100 | 100 | } |
101 | 101 | |
102 | -function wpinv_is_gateway_active( $gateway ) { |
|
102 | +function wpinv_is_gateway_active($gateway) { |
|
103 | 103 | $gateways = wpinv_get_enabled_payment_gateways(); |
104 | 104 | |
105 | - $ret = is_array($gateways) && $gateway ? array_key_exists( $gateway, $gateways ) : false; |
|
105 | + $ret = is_array($gateways) && $gateway ? array_key_exists($gateway, $gateways) : false; |
|
106 | 106 | |
107 | - return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways ); |
|
107 | + return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | function wpinv_get_default_gateway() { |
111 | - $default = wpinv_get_option( 'default_gateway', 'paypal' ); |
|
111 | + $default = wpinv_get_option('default_gateway', 'paypal'); |
|
112 | 112 | |
113 | - if ( !wpinv_is_gateway_active( $default ) ) { |
|
113 | + if (!wpinv_is_gateway_active($default)) { |
|
114 | 114 | $gateways = wpinv_get_enabled_payment_gateways(); |
115 | - $gateways = array_keys( $gateways ); |
|
116 | - $default = reset( $gateways ); |
|
115 | + $gateways = array_keys($gateways); |
|
116 | + $default = reset($gateways); |
|
117 | 117 | } |
118 | 118 | |
119 | - return apply_filters( 'wpinv_default_gateway', $default ); |
|
119 | + return apply_filters('wpinv_default_gateway', $default); |
|
120 | 120 | } |
121 | 121 | |
122 | -function wpinv_get_gateway_admin_label( $gateway ) { |
|
122 | +function wpinv_get_gateway_admin_label($gateway) { |
|
123 | 123 | $gateways = wpinv_get_payment_gateways(); |
124 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway; |
|
125 | - $payment = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false; |
|
124 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; |
|
125 | + $payment = isset($_GET['id']) ? absint($_GET['id']) : false; |
|
126 | 126 | |
127 | - if( $gateway == 'manual' && $payment ) { |
|
128 | - if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) { |
|
129 | - $label = __( 'Free Purchase', 'invoicing' ); |
|
127 | + if ($gateway == 'manual' && $payment) { |
|
128 | + if (!((float) wpinv_payment_total($payment) > 0)) { |
|
129 | + $label = __('Free Purchase', 'invoicing'); |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | - return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway ); |
|
133 | + return apply_filters('wpinv_gateway_admin_label', $label, $gateway); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_get_gateway_description( $gateway ) { |
|
136 | +function wpinv_get_gateway_description($gateway) { |
|
137 | 137 | global $wpinv_options; |
138 | 138 | |
139 | - $description = isset( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
139 | + $description = isset($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
140 | 140 | |
141 | - return apply_filters( 'wpinv_gateway_description', $description, $gateway ); |
|
141 | + return apply_filters('wpinv_gateway_description', $description, $gateway); |
|
142 | 142 | } |
143 | 143 | |
144 | -function wpinv_get_gateway_button_label( $gateway ) { |
|
145 | - return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' ); |
|
144 | +function wpinv_get_gateway_button_label($gateway) { |
|
145 | + return apply_filters('wpinv_gateway_' . $gateway . '_button_label', ''); |
|
146 | 146 | } |
147 | 147 | |
148 | -function wpinv_get_gateway_checkout_label( $gateway ) { |
|
148 | +function wpinv_get_gateway_checkout_label($gateway) { |
|
149 | 149 | $gateways = wpinv_get_payment_gateways(); |
150 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway; |
|
150 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway; |
|
151 | 151 | |
152 | - if( $gateway == 'manual' ) { |
|
153 | - $label = __( 'Manual Payment', 'invoicing' ); |
|
152 | + if ($gateway == 'manual') { |
|
153 | + $label = __('Manual Payment', 'invoicing'); |
|
154 | 154 | } |
155 | 155 | |
156 | - return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway ); |
|
156 | + return apply_filters('wpinv_gateway_checkout_label', $label, $gateway); |
|
157 | 157 | } |
158 | 158 | |
159 | -function wpinv_settings_sections_gateways( $settings ) { |
|
159 | +function wpinv_settings_sections_gateways($settings) { |
|
160 | 160 | $gateways = wpinv_get_payment_gateways(); |
161 | 161 | |
162 | 162 | if (!empty($gateways)) { |
163 | - foreach ($gateways as $key => $gateway) { |
|
163 | + foreach ($gateways as $key => $gateway) { |
|
164 | 164 | $settings[$key] = $gateway['admin_label']; |
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | 168 | return $settings; |
169 | 169 | } |
170 | -add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 ); |
|
170 | +add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1); |
|
171 | 171 | |
172 | -function wpinv_settings_gateways( $settings ) { |
|
172 | +function wpinv_settings_gateways($settings) { |
|
173 | 173 | $gateways = wpinv_get_payment_gateways(); |
174 | 174 | |
175 | 175 | if (!empty($gateways)) { |
176 | - foreach ($gateways as $key => $gateway) { |
|
176 | + foreach ($gateways as $key => $gateway) { |
|
177 | 177 | $setting = array(); |
178 | 178 | $setting[$key . '_header'] = array( |
179 | 179 | 'id' => 'gateway_header', |
180 | - 'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>', |
|
180 | + 'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>', |
|
181 | 181 | 'custom' => $key, |
182 | 182 | 'type' => 'gateway_header', |
183 | 183 | ); |
184 | 184 | $setting[$key . '_active'] = array( |
185 | 185 | 'id' => $key . '_active', |
186 | - 'name' => __( 'Active', 'invoicing' ), |
|
187 | - 'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ), |
|
186 | + 'name' => __('Active', 'invoicing'), |
|
187 | + 'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']), |
|
188 | 188 | 'type' => 'checkbox', |
189 | 189 | ); |
190 | 190 | |
191 | 191 | $setting[$key . '_title'] = array( |
192 | 192 | 'id' => $key . '_title', |
193 | - 'name' => __( 'Title', 'invoicing' ), |
|
194 | - 'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ), |
|
193 | + 'name' => __('Title', 'invoicing'), |
|
194 | + 'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'), |
|
195 | 195 | 'type' => 'text', |
196 | 196 | 'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '' |
197 | 197 | ); |
198 | 198 | |
199 | 199 | $setting[$key . '_desc'] = array( |
200 | 200 | 'id' => $key . '_desc', |
201 | - 'name' => __( 'Description', 'invoicing' ), |
|
202 | - 'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ), |
|
201 | + 'name' => __('Description', 'invoicing'), |
|
202 | + 'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'), |
|
203 | 203 | 'type' => 'text', |
204 | 204 | 'size' => 'large' |
205 | 205 | ); |
206 | 206 | |
207 | 207 | $setting[$key . '_ordering'] = array( |
208 | 208 | 'id' => $key . '_ordering', |
209 | - 'name' => __( 'Display Order', 'invoicing' ), |
|
209 | + 'name' => __('Display Order', 'invoicing'), |
|
210 | 210 | 'type' => 'number', |
211 | 211 | 'size' => 'small', |
212 | 212 | 'std' => isset($gateway['ordering']) ? $gateway['ordering'] : '10', |
@@ -215,8 +215,8 @@ discard block |
||
215 | 215 | 'step' => '1' |
216 | 216 | ); |
217 | 217 | |
218 | - $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key ); |
|
219 | - $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting ); |
|
218 | + $setting = apply_filters('wpinv_gateway_settings', $setting, $key); |
|
219 | + $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting); |
|
220 | 220 | |
221 | 221 | $settings[$key] = $setting; |
222 | 222 | } |
@@ -224,106 +224,106 @@ discard block |
||
224 | 224 | |
225 | 225 | return $settings; |
226 | 226 | } |
227 | -add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 ); |
|
227 | +add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1); |
|
228 | 228 | |
229 | -function wpinv_gateway_header_callback( $args ) { |
|
230 | - echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />'; |
|
229 | +function wpinv_gateway_header_callback($args) { |
|
230 | + echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />'; |
|
231 | 231 | } |
232 | 232 | |
233 | -function wpinv_get_gateway_supports( $gateway ) { |
|
233 | +function wpinv_get_gateway_supports($gateway) { |
|
234 | 234 | $gateways = wpinv_get_enabled_payment_gateways(); |
235 | - $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array(); |
|
236 | - return apply_filters( 'wpinv_gateway_supports', $supports, $gateway ); |
|
235 | + $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array(); |
|
236 | + return apply_filters('wpinv_gateway_supports', $supports, $gateway); |
|
237 | 237 | } |
238 | 238 | |
239 | -function wpinv_gateway_supports_buy_now( $gateway ) { |
|
240 | - $supports = wpinv_get_gateway_supports( $gateway ); |
|
241 | - $ret = in_array( 'buy_now', $supports ); |
|
242 | - return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway ); |
|
239 | +function wpinv_gateway_supports_buy_now($gateway) { |
|
240 | + $supports = wpinv_get_gateway_supports($gateway); |
|
241 | + $ret = in_array('buy_now', $supports); |
|
242 | + return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | function wpinv_shop_supports_buy_now() { |
246 | 246 | $gateways = wpinv_get_enabled_payment_gateways(); |
247 | 247 | $ret = false; |
248 | 248 | |
249 | - if ( !wpinv_use_taxes() && $gateways ) { |
|
250 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
251 | - if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) { |
|
249 | + if (!wpinv_use_taxes() && $gateways) { |
|
250 | + foreach ($gateways as $gateway_id => $gateway) { |
|
251 | + if (wpinv_gateway_supports_buy_now($gateway_id)) { |
|
252 | 252 | $ret = true; |
253 | 253 | break; |
254 | 254 | } |
255 | 255 | } |
256 | 256 | } |
257 | 257 | |
258 | - return apply_filters( 'wpinv_shop_supports_buy_now', $ret ); |
|
258 | + return apply_filters('wpinv_shop_supports_buy_now', $ret); |
|
259 | 259 | } |
260 | 260 | |
261 | -function wpinv_send_to_gateway( $gateway, $payment_data ) { |
|
262 | - $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' ); |
|
261 | +function wpinv_send_to_gateway($gateway, $payment_data) { |
|
262 | + $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway'); |
|
263 | 263 | |
264 | 264 | // $gateway must match the ID used when registering the gateway |
265 | - do_action( 'wpinv_gateway_' . $gateway, $payment_data ); |
|
265 | + do_action('wpinv_gateway_' . $gateway, $payment_data); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | function wpinv_show_gateways() { |
269 | 269 | $gateways = wpinv_get_enabled_payment_gateways(); |
270 | 270 | $show_gateways = false; |
271 | 271 | |
272 | - $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false; |
|
272 | + $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false; |
|
273 | 273 | |
274 | - if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) { |
|
274 | + if (count($gateways) > 1 && empty($chosen_gateway)) { |
|
275 | 275 | $show_gateways = true; |
276 | - if ( wpinv_get_cart_total() <= 0 ) { |
|
276 | + if (wpinv_get_cart_total() <= 0) { |
|
277 | 277 | $show_gateways = false; |
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | - if ( !$show_gateways && wpinv_cart_has_recurring_item() ) { |
|
281 | + if (!$show_gateways && wpinv_cart_has_recurring_item()) { |
|
282 | 282 | $show_gateways = true; |
283 | 283 | } |
284 | 284 | |
285 | - return apply_filters( 'wpinv_show_gateways', $show_gateways ); |
|
285 | + return apply_filters('wpinv_show_gateways', $show_gateways); |
|
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
|
289 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
288 | +function wpinv_get_chosen_gateway($invoice_id = 0) { |
|
289 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
290 | 290 | |
291 | 291 | $chosen = false; |
292 | - if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
292 | + if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) { |
|
293 | 293 | $chosen = $invoice->get_gateway(); |
294 | 294 | } |
295 | 295 | |
296 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
296 | + $chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen; |
|
297 | 297 | |
298 | - if ( false !== $chosen ) { |
|
299 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
298 | + if (false !== $chosen) { |
|
299 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen); |
|
300 | 300 | } |
301 | 301 | |
302 | - if ( ! empty ( $chosen ) ) { |
|
303 | - $enabled_gateway = urldecode( $chosen ); |
|
304 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
302 | + if (!empty ($chosen)) { |
|
303 | + $enabled_gateway = urldecode($chosen); |
|
304 | + } else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) { |
|
305 | 305 | $enabled_gateway = 'manual'; |
306 | 306 | } else { |
307 | 307 | $enabled_gateway = wpinv_get_default_gateway(); |
308 | 308 | } |
309 | 309 | |
310 | - if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
|
311 | - if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
|
310 | + if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) { |
|
311 | + if (wpinv_is_gateway_active(wpinv_get_default_gateway())) { |
|
312 | 312 | $enabled_gateway = wpinv_get_default_gateway(); |
313 | - }else{ |
|
313 | + } else { |
|
314 | 314 | $enabled_gateway = $gateways[0]; |
315 | 315 | } |
316 | 316 | |
317 | 317 | } |
318 | 318 | |
319 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
319 | + return apply_filters('wpinv_chosen_gateway', $enabled_gateway); |
|
320 | 320 | } |
321 | 321 | |
322 | -function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) { |
|
323 | - return wpinv_error_log( $message, $title ); |
|
322 | +function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) { |
|
323 | + return wpinv_error_log($message, $title); |
|
324 | 324 | } |
325 | 325 | |
326 | -function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
|
326 | +function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') { |
|
327 | 327 | $ret = 0; |
328 | 328 | $args = array( |
329 | 329 | 'meta_key' => '_wpinv_gateway', |
@@ -334,48 +334,48 @@ discard block |
||
334 | 334 | 'fields' => 'ids' |
335 | 335 | ); |
336 | 336 | |
337 | - $payments = new WP_Query( $args ); |
|
337 | + $payments = new WP_Query($args); |
|
338 | 338 | |
339 | - if( $payments ) |
|
339 | + if ($payments) |
|
340 | 340 | $ret = $payments->post_count; |
341 | 341 | return $ret; |
342 | 342 | } |
343 | 343 | |
344 | -function wpinv_settings_update_gateways( $input ) { |
|
344 | +function wpinv_settings_update_gateways($input) { |
|
345 | 345 | global $wpinv_options; |
346 | 346 | |
347 | - if ( !empty( $input['save_gateway'] ) ) { |
|
348 | - $gateways = wpinv_get_option( 'gateways', false ); |
|
347 | + if (!empty($input['save_gateway'])) { |
|
348 | + $gateways = wpinv_get_option('gateways', false); |
|
349 | 349 | $gateways = !empty($gateways) ? $gateways : array(); |
350 | 350 | $gateway = $input['save_gateway']; |
351 | 351 | |
352 | - if ( !empty( $input[$gateway . '_active'] ) ) { |
|
352 | + if (!empty($input[$gateway . '_active'])) { |
|
353 | 353 | $gateways[$gateway] = 1; |
354 | 354 | } else { |
355 | - if ( isset( $gateways[$gateway] ) ) { |
|
356 | - unset( $gateways[$gateway] ); |
|
355 | + if (isset($gateways[$gateway])) { |
|
356 | + unset($gateways[$gateway]); |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | |
360 | 360 | $input['gateways'] = $gateways; |
361 | 361 | } |
362 | 362 | |
363 | - if ( !empty( $input['default_gateway'] ) ) { |
|
363 | + if (!empty($input['default_gateway'])) { |
|
364 | 364 | $gateways = wpinv_get_payment_gateways(); |
365 | 365 | |
366 | - foreach ( $gateways as $key => $gateway ) { |
|
367 | - $active = 0; |
|
368 | - if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) { |
|
366 | + foreach ($gateways as $key => $gateway) { |
|
367 | + $active = 0; |
|
368 | + if (!empty($input['gateways']) && !empty($input['gateways'][$key])) { |
|
369 | 369 | $active = 1; |
370 | 370 | } |
371 | 371 | |
372 | 372 | $input[$key . '_active'] = $active; |
373 | 373 | |
374 | - if ( empty( $wpinv_options[$key . '_title'] ) ) { |
|
374 | + if (empty($wpinv_options[$key . '_title'])) { |
|
375 | 375 | $input[$key . '_title'] = $gateway['checkout_label']; |
376 | 376 | } |
377 | 377 | |
378 | - if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) { |
|
378 | + if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) { |
|
379 | 379 | $input[$key . '_ordering'] = $gateway['ordering']; |
380 | 380 | } |
381 | 381 | } |
@@ -383,27 +383,27 @@ discard block |
||
383 | 383 | |
384 | 384 | return $input; |
385 | 385 | } |
386 | -add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 ); |
|
386 | +add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1); |
|
387 | 387 | |
388 | 388 | // PayPal Standard settings |
389 | -function wpinv_gateway_settings_paypal( $setting ) { |
|
390 | - $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' ); |
|
391 | - $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
389 | +function wpinv_gateway_settings_paypal($setting) { |
|
390 | + $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing'); |
|
391 | + $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
392 | 392 | |
393 | 393 | $setting['paypal_sandbox'] = array( |
394 | 394 | 'type' => 'checkbox', |
395 | 395 | 'id' => 'paypal_sandbox', |
396 | - 'name' => __( 'PayPal Sandbox', 'invoicing' ), |
|
397 | - 'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ), |
|
396 | + 'name' => __('PayPal Sandbox', 'invoicing'), |
|
397 | + 'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'), |
|
398 | 398 | 'std' => 1 |
399 | 399 | ); |
400 | 400 | |
401 | 401 | $setting['paypal_email'] = array( |
402 | 402 | 'type' => 'text', |
403 | 403 | 'id' => 'paypal_email', |
404 | - 'name' => __( 'PayPal Email', 'invoicing' ), |
|
405 | - 'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ), |
|
406 | - 'std' => __( '[email protected]', 'invoicing' ), |
|
404 | + 'name' => __('PayPal Email', 'invoicing'), |
|
405 | + 'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'), |
|
406 | + 'std' => __('[email protected]', 'invoicing'), |
|
407 | 407 | ); |
408 | 408 | /* |
409 | 409 | $setting['paypal_ipn_url'] = array( |
@@ -417,139 +417,139 @@ discard block |
||
417 | 417 | |
418 | 418 | return $setting; |
419 | 419 | } |
420 | -add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 ); |
|
420 | +add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1); |
|
421 | 421 | |
422 | 422 | // Pre Bank Transfer settings |
423 | -function wpinv_gateway_settings_bank_transfer( $setting ) { |
|
424 | - $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ); |
|
423 | +function wpinv_gateway_settings_bank_transfer($setting) { |
|
424 | + $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'); |
|
425 | 425 | |
426 | 426 | $setting['bank_transfer_ac_name'] = array( |
427 | 427 | 'type' => 'text', |
428 | 428 | 'id' => 'bank_transfer_ac_name', |
429 | - 'name' => __( 'Account Name', 'invoicing' ), |
|
430 | - 'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ), |
|
431 | - 'std' => __( 'Mr. John Martin', 'invoicing' ), |
|
429 | + 'name' => __('Account Name', 'invoicing'), |
|
430 | + 'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'), |
|
431 | + 'std' => __('Mr. John Martin', 'invoicing'), |
|
432 | 432 | ); |
433 | 433 | |
434 | 434 | $setting['bank_transfer_ac_no'] = array( |
435 | 435 | 'type' => 'text', |
436 | 436 | 'id' => 'bank_transfer_ac_no', |
437 | - 'name' => __( 'Account Number', 'invoicing' ), |
|
438 | - 'desc' => __( 'Enter your bank account number.', 'invoicing' ), |
|
439 | - 'std' => __( 'TEST1234567890', 'invoicing' ), |
|
437 | + 'name' => __('Account Number', 'invoicing'), |
|
438 | + 'desc' => __('Enter your bank account number.', 'invoicing'), |
|
439 | + 'std' => __('TEST1234567890', 'invoicing'), |
|
440 | 440 | ); |
441 | 441 | |
442 | 442 | $setting['bank_transfer_bank_name'] = array( |
443 | 443 | 'type' => 'text', |
444 | 444 | 'id' => 'bank_transfer_bank_name', |
445 | - 'name' => __( 'Bank Name', 'invoicing' ), |
|
446 | - 'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ), |
|
447 | - 'std' => __( 'ICICI Bank', 'invoicing' ), |
|
445 | + 'name' => __('Bank Name', 'invoicing'), |
|
446 | + 'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'), |
|
447 | + 'std' => __('ICICI Bank', 'invoicing'), |
|
448 | 448 | ); |
449 | 449 | |
450 | 450 | $setting['bank_transfer_ifsc'] = array( |
451 | 451 | 'type' => 'text', |
452 | 452 | 'id' => 'bank_transfer_ifsc', |
453 | - 'name' => __( 'IFSC Code', 'invoicing' ), |
|
454 | - 'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ), |
|
455 | - 'std' => __( 'ICIC0001234', 'invoicing' ), |
|
453 | + 'name' => __('IFSC Code', 'invoicing'), |
|
454 | + 'desc' => __('Enter your bank IFSC code.', 'invoicing'), |
|
455 | + 'std' => __('ICIC0001234', 'invoicing'), |
|
456 | 456 | ); |
457 | 457 | |
458 | 458 | $setting['bank_transfer_iban'] = array( |
459 | 459 | 'type' => 'text', |
460 | 460 | 'id' => 'bank_transfer_iban', |
461 | - 'name' => __( 'IBAN', 'invoicing' ), |
|
462 | - 'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ), |
|
463 | - 'std' => __( 'GB29NWBK60161331926819', 'invoicing' ), |
|
461 | + 'name' => __('IBAN', 'invoicing'), |
|
462 | + 'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'), |
|
463 | + 'std' => __('GB29NWBK60161331926819', 'invoicing'), |
|
464 | 464 | ); |
465 | 465 | |
466 | 466 | $setting['bank_transfer_bic'] = array( |
467 | 467 | 'type' => 'text', |
468 | 468 | 'id' => 'bank_transfer_bic', |
469 | - 'name' => __( 'BIC/Swift Code', 'invoicing' ), |
|
470 | - 'std' => __( 'ICICGB2L129', 'invoicing' ), |
|
469 | + 'name' => __('BIC/Swift Code', 'invoicing'), |
|
470 | + 'std' => __('ICICGB2L129', 'invoicing'), |
|
471 | 471 | ); |
472 | 472 | |
473 | 473 | $setting['bank_transfer_sort_code'] = array( |
474 | 474 | 'type' => 'text', |
475 | 475 | 'id' => 'bank_transfer_sort_code', |
476 | - 'name' => __( 'Sort Code', 'invoicing' ), |
|
477 | - 'std' => __( '12-34-56', 'invoicing' ), |
|
476 | + 'name' => __('Sort Code', 'invoicing'), |
|
477 | + 'std' => __('12-34-56', 'invoicing'), |
|
478 | 478 | ); |
479 | 479 | |
480 | 480 | $setting['bank_transfer_info'] = array( |
481 | 481 | 'id' => 'bank_transfer_info', |
482 | - 'name' => __( 'Instructions', 'invoicing' ), |
|
483 | - 'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ), |
|
482 | + 'name' => __('Instructions', 'invoicing'), |
|
483 | + 'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'), |
|
484 | 484 | 'type' => 'textarea', |
485 | - 'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ), |
|
485 | + 'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'), |
|
486 | 486 | 'cols' => 37, |
487 | 487 | 'rows' => 5 |
488 | 488 | ); |
489 | 489 | |
490 | 490 | return $setting; |
491 | 491 | } |
492 | -add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 ); |
|
492 | +add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1); |
|
493 | 493 | |
494 | 494 | // Authorize.Net settings |
495 | -function wpinv_gateway_settings_authorizenet( $setting ) { |
|
496 | - $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' ); |
|
497 | - $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing' ); |
|
495 | +function wpinv_gateway_settings_authorizenet($setting) { |
|
496 | + $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing'); |
|
497 | + $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing'); |
|
498 | 498 | |
499 | 499 | $setting['authorizenet_sandbox'] = array( |
500 | 500 | 'type' => 'checkbox', |
501 | 501 | 'id' => 'authorizenet_sandbox', |
502 | - 'name' => __( 'Authorize.Net Test Mode', 'invoicing' ), |
|
503 | - 'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ), |
|
502 | + 'name' => __('Authorize.Net Test Mode', 'invoicing'), |
|
503 | + 'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'), |
|
504 | 504 | 'std' => 1 |
505 | 505 | ); |
506 | 506 | |
507 | 507 | $setting['authorizenet_login_id'] = array( |
508 | 508 | 'type' => 'text', |
509 | 509 | 'id' => 'authorizenet_login_id', |
510 | - 'name' => __( 'API Login ID', 'invoicing' ), |
|
511 | - 'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ), |
|
510 | + 'name' => __('API Login ID', 'invoicing'), |
|
511 | + 'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'), |
|
512 | 512 | 'std' => '2j4rBekUnD', |
513 | 513 | ); |
514 | 514 | |
515 | 515 | $setting['authorizenet_transaction_key'] = array( |
516 | 516 | 'type' => 'text', |
517 | 517 | 'id' => 'authorizenet_transaction_key', |
518 | - 'name' => __( 'Transaction Key', 'invoicing' ), |
|
519 | - 'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ), |
|
518 | + 'name' => __('Transaction Key', 'invoicing'), |
|
519 | + 'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'), |
|
520 | 520 | 'std' => '4vyBUOJgR74679xa', |
521 | 521 | ); |
522 | 522 | |
523 | 523 | $setting['authorizenet_md5_hash'] = array( |
524 | 524 | 'type' => 'text', |
525 | 525 | 'id' => 'authorizenet_md5_hash', |
526 | - 'name' => __( 'MD5-Hash', 'invoicing' ), |
|
527 | - 'desc' => __( 'The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ), |
|
526 | + 'name' => __('MD5-Hash', 'invoicing'), |
|
527 | + 'desc' => __('The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'), |
|
528 | 528 | 'std' => '', |
529 | 529 | ); |
530 | 530 | |
531 | 531 | $setting['authorizenet_transaction_type'] = array( |
532 | 532 | 'id' => 'authorizenet_transaction_type', |
533 | - 'name' => __( 'Transaction Type', 'invoicing' ), |
|
534 | - 'desc' => __( 'Choose transaction type.', 'invoicing' ), |
|
533 | + 'name' => __('Transaction Type', 'invoicing'), |
|
534 | + 'desc' => __('Choose transaction type.', 'invoicing'), |
|
535 | 535 | 'type' => 'select', |
536 | 536 | 'class' => 'wpi_select2', |
537 | 537 | 'options' => array( |
538 | - 'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ), |
|
539 | - 'authorize_only' => __( 'Authorize Only', 'invoicing' ), |
|
538 | + 'authorize_capture' => __('Authorize And Capture', 'invoicing'), |
|
539 | + 'authorize_only' => __('Authorize Only', 'invoicing'), |
|
540 | 540 | ), |
541 | 541 | 'std' => 'authorize_capture' |
542 | 542 | ); |
543 | 543 | |
544 | 544 | $setting['authorizenet_transaction_type_recurring'] = array( |
545 | 545 | 'id' => 'authorizenet_transaction_type_recurring', |
546 | - 'name' => __( 'Transaction Type for Recurring', 'invoicing' ), |
|
547 | - 'desc' => __( 'Choose transaction type for recurring payments.', 'invoicing' ), |
|
546 | + 'name' => __('Transaction Type for Recurring', 'invoicing'), |
|
547 | + 'desc' => __('Choose transaction type for recurring payments.', 'invoicing'), |
|
548 | 548 | 'type' => 'select', |
549 | 549 | 'class' => 'wpi_select2', |
550 | 550 | 'options' => array( |
551 | - 'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ), |
|
552 | - 'authorize_only' => __( 'Authorize Only', 'invoicing' ), |
|
551 | + 'authorize_capture' => __('Authorize And Capture', 'invoicing'), |
|
552 | + 'authorize_only' => __('Authorize Only', 'invoicing'), |
|
553 | 553 | ), |
554 | 554 | 'std' => 'authorize_only' |
555 | 555 | ); |
@@ -557,9 +557,9 @@ discard block |
||
557 | 557 | $setting['authorizenet_ipn_url'] = array( |
558 | 558 | 'type' => 'ipn_url', |
559 | 559 | 'id' => 'authorizenet_ipn_url', |
560 | - 'name' => __( 'Silent Post URL', 'invoicing' ), |
|
561 | - 'std' => wpinv_get_ipn_url( 'authorizenet' ), |
|
562 | - 'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ), |
|
560 | + 'name' => __('Silent Post URL', 'invoicing'), |
|
561 | + 'std' => wpinv_get_ipn_url('authorizenet'), |
|
562 | + 'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'), |
|
563 | 563 | 'size' => 'large', |
564 | 564 | 'custom' => 'authorizenet', |
565 | 565 | 'readonly' => true |
@@ -567,26 +567,26 @@ discard block |
||
567 | 567 | |
568 | 568 | return $setting; |
569 | 569 | } |
570 | -add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 ); |
|
570 | +add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1); |
|
571 | 571 | |
572 | 572 | // Worldpay settings |
573 | -function wpinv_gateway_settings_worldpay( $setting ) { |
|
574 | - $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing' ); |
|
575 | - $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing' ); |
|
573 | +function wpinv_gateway_settings_worldpay($setting) { |
|
574 | + $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __('( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing'); |
|
575 | + $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing'); |
|
576 | 576 | |
577 | 577 | $setting['worldpay_sandbox'] = array( |
578 | 578 | 'type' => 'checkbox', |
579 | 579 | 'id' => 'worldpay_sandbox', |
580 | - 'name' => __( 'Worldpay Test Mode', 'invoicing' ), |
|
581 | - 'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ), |
|
580 | + 'name' => __('Worldpay Test Mode', 'invoicing'), |
|
581 | + 'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'), |
|
582 | 582 | 'std' => 1 |
583 | 583 | ); |
584 | 584 | |
585 | 585 | $setting['worldpay_instId'] = array( |
586 | 586 | 'type' => 'text', |
587 | 587 | 'id' => 'worldpay_instId', |
588 | - 'name' => __( 'Installation Id', 'invoicing' ), |
|
589 | - 'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ), |
|
588 | + 'name' => __('Installation Id', 'invoicing'), |
|
589 | + 'desc' => __('Your installation id. Ex: 211616', 'invoicing'), |
|
590 | 590 | 'std' => '211616', |
591 | 591 | ); |
592 | 592 | /* |
@@ -602,9 +602,9 @@ discard block |
||
602 | 602 | $setting['worldpay_ipn_url'] = array( |
603 | 603 | 'type' => 'ipn_url', |
604 | 604 | 'id' => 'worldpay_ipn_url', |
605 | - 'name' => __( 'Worldpay Callback Url', 'invoicing' ), |
|
606 | - 'std' => wpinv_get_ipn_url( 'worldpay' ), |
|
607 | - 'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal"><wpdisplay item=MC_callback></font>' ), |
|
605 | + 'name' => __('Worldpay Callback Url', 'invoicing'), |
|
606 | + 'std' => wpinv_get_ipn_url('worldpay'), |
|
607 | + 'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal"><wpdisplay item=MC_callback></font>'), |
|
608 | 608 | 'size' => 'large', |
609 | 609 | 'custom' => 'worldpay', |
610 | 610 | 'readonly' => true |
@@ -612,99 +612,99 @@ discard block |
||
612 | 612 | |
613 | 613 | return $setting; |
614 | 614 | } |
615 | -add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 ); |
|
615 | +add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1); |
|
616 | 616 | |
617 | -function wpinv_ipn_url_callback( $args ) { |
|
618 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
617 | +function wpinv_ipn_url_callback($args) { |
|
618 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
619 | 619 | |
620 | 620 | $attrs = $args['readonly'] ? ' readonly' : ''; |
621 | 621 | |
622 | - $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">'; |
|
623 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
622 | + $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">'; |
|
623 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
624 | 624 | |
625 | 625 | echo $html; |
626 | 626 | } |
627 | 627 | |
628 | -function wpinv_is_test_mode( $gateway = '' ) { |
|
629 | - if ( empty( $gateway ) ) { |
|
628 | +function wpinv_is_test_mode($gateway = '') { |
|
629 | + if (empty($gateway)) { |
|
630 | 630 | return false; |
631 | 631 | } |
632 | 632 | |
633 | - $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false ); |
|
633 | + $is_test_mode = wpinv_get_option($gateway . '_sandbox', false); |
|
634 | 634 | |
635 | - return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway ); |
|
635 | + return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway); |
|
636 | 636 | } |
637 | 637 | |
638 | -function wpinv_get_ipn_url( $gateway = '', $args = array() ) { |
|
639 | - $data = array( 'wpi-listener' => 'IPN' ); |
|
638 | +function wpinv_get_ipn_url($gateway = '', $args = array()) { |
|
639 | + $data = array('wpi-listener' => 'IPN'); |
|
640 | 640 | |
641 | - if ( !empty( $gateway ) ) { |
|
642 | - $data['wpi-gateway'] = wpinv_sanitize_key( $gateway ); |
|
641 | + if (!empty($gateway)) { |
|
642 | + $data['wpi-gateway'] = wpinv_sanitize_key($gateway); |
|
643 | 643 | } |
644 | 644 | |
645 | - $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data; |
|
645 | + $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data; |
|
646 | 646 | |
647 | - $ipn_url = add_query_arg( $args, home_url( 'index.php' ) ); |
|
647 | + $ipn_url = add_query_arg($args, home_url('index.php')); |
|
648 | 648 | |
649 | - return apply_filters( 'wpinv_ipn_url', $ipn_url ); |
|
649 | + return apply_filters('wpinv_ipn_url', $ipn_url); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | function wpinv_listen_for_payment_ipn() { |
653 | 653 | // Regular PayPal IPN |
654 | - if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) { |
|
655 | - do_action( 'wpinv_verify_payment_ipn' ); |
|
654 | + if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') { |
|
655 | + do_action('wpinv_verify_payment_ipn'); |
|
656 | 656 | |
657 | - if ( !empty( $_GET['wpi-gateway'] ) ) { |
|
658 | - wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'WP Invoicing IPN', __FILE__, __LINE__ ); |
|
659 | - do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' ); |
|
657 | + if (!empty($_GET['wpi-gateway'])) { |
|
658 | + wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'WP Invoicing IPN', __FILE__, __LINE__); |
|
659 | + do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn'); |
|
660 | 660 | } |
661 | 661 | } |
662 | 662 | } |
663 | -add_action( 'init', 'wpinv_listen_for_payment_ipn' ); |
|
663 | +add_action('init', 'wpinv_listen_for_payment_ipn'); |
|
664 | 664 | |
665 | 665 | function wpinv_get_bank_instructions() { |
666 | - $bank_instructions = wpinv_get_option( 'bank_transfer_info' ); |
|
666 | + $bank_instructions = wpinv_get_option('bank_transfer_info'); |
|
667 | 667 | |
668 | - return apply_filters( 'wpinv_bank_instructions', $bank_instructions ); |
|
668 | + return apply_filters('wpinv_bank_instructions', $bank_instructions); |
|
669 | 669 | } |
670 | 670 | |
671 | -function wpinv_get_bank_info( $filtered = false ) { |
|
671 | +function wpinv_get_bank_info($filtered = false) { |
|
672 | 672 | $bank_fields = array( |
673 | - 'bank_transfer_ac_name' => __( 'Account Name', 'invoicing' ), |
|
674 | - 'bank_transfer_ac_no' => __( 'Account Number', 'invoicing' ), |
|
675 | - 'bank_transfer_bank_name' => __( 'Bank Name', 'invoicing' ), |
|
676 | - 'bank_transfer_ifsc' => __( 'IFSC code', 'invoicing' ), |
|
677 | - 'bank_transfer_iban' => __( 'IBAN', 'invoicing' ), |
|
678 | - 'bank_transfer_bic' => __( 'BIC/Swift code', 'invoicing' ), |
|
679 | - 'bank_transfer_sort_code' => __( 'Sort Code', 'invoicing' ) |
|
673 | + 'bank_transfer_ac_name' => __('Account Name', 'invoicing'), |
|
674 | + 'bank_transfer_ac_no' => __('Account Number', 'invoicing'), |
|
675 | + 'bank_transfer_bank_name' => __('Bank Name', 'invoicing'), |
|
676 | + 'bank_transfer_ifsc' => __('IFSC code', 'invoicing'), |
|
677 | + 'bank_transfer_iban' => __('IBAN', 'invoicing'), |
|
678 | + 'bank_transfer_bic' => __('BIC/Swift code', 'invoicing'), |
|
679 | + 'bank_transfer_sort_code' => __('Sort Code', 'invoicing') |
|
680 | 680 | ); |
681 | 681 | |
682 | 682 | $bank_info = array(); |
683 | - foreach ( $bank_fields as $field => $label ) { |
|
684 | - if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) { |
|
683 | + foreach ($bank_fields as $field => $label) { |
|
684 | + if ($filtered && !($value = wpinv_get_option($field))) { |
|
685 | 685 | continue; |
686 | 686 | } |
687 | 687 | |
688 | - $bank_info[$field] = array( 'label' => $label, 'value' => $value ); |
|
688 | + $bank_info[$field] = array('label' => $label, 'value' => $value); |
|
689 | 689 | } |
690 | 690 | |
691 | - return apply_filters( 'wpinv_bank_info', $bank_info, $filtered ); |
|
691 | + return apply_filters('wpinv_bank_info', $bank_info, $filtered); |
|
692 | 692 | } |
693 | 693 | |
694 | -function wpinv_get_post_data( $method = 'request' ) { |
|
694 | +function wpinv_get_post_data($method = 'request') { |
|
695 | 695 | $data = array(); |
696 | 696 | $request = $_REQUEST; |
697 | 697 | |
698 | - if ( $method == 'post' ) { |
|
699 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
698 | + if ($method == 'post') { |
|
699 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
700 | 700 | return $data; |
701 | 701 | } |
702 | 702 | |
703 | 703 | $request = $_POST; |
704 | 704 | } |
705 | 705 | |
706 | - if ( $method == 'get' ) { |
|
707 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) { |
|
706 | + if ($method == 'get') { |
|
707 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') { |
|
708 | 708 | return $data; |
709 | 709 | } |
710 | 710 | |
@@ -715,11 +715,11 @@ discard block |
||
715 | 715 | $post_data = ''; |
716 | 716 | |
717 | 717 | // Fallback just in case post_max_size is lower than needed |
718 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
719 | - $post_data = file_get_contents( 'php://input' ); |
|
718 | + if (ini_get('allow_url_fopen')) { |
|
719 | + $post_data = file_get_contents('php://input'); |
|
720 | 720 | } else { |
721 | 721 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
722 | - ini_set( 'post_max_size', '12M' ); |
|
722 | + ini_set('post_max_size', '12M'); |
|
723 | 723 | } |
724 | 724 | // Start the encoded data collection with notification command |
725 | 725 | $encoded_data = 'cmd=_notify-validate'; |
@@ -728,58 +728,58 @@ discard block |
||
728 | 728 | $arg_separator = wpinv_get_php_arg_separator_output(); |
729 | 729 | |
730 | 730 | // Verify there is a post_data |
731 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
731 | + if ($post_data || strlen($post_data) > 0) { |
|
732 | 732 | // Append the data |
733 | 733 | $encoded_data .= $arg_separator . $post_data; |
734 | 734 | } else { |
735 | 735 | // Check if POST is empty |
736 | - if ( empty( $request ) ) { |
|
736 | + if (empty($request)) { |
|
737 | 737 | // Nothing to do |
738 | 738 | return; |
739 | 739 | } else { |
740 | 740 | // Loop through each POST |
741 | - foreach ( $request as $key => $value ) { |
|
741 | + foreach ($request as $key => $value) { |
|
742 | 742 | // Encode the value and append the data |
743 | - $encoded_data .= $arg_separator . "$key=" . urlencode( $value ); |
|
743 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
744 | 744 | } |
745 | 745 | } |
746 | 746 | } |
747 | 747 | |
748 | 748 | // Convert collected post data to an array |
749 | - wp_parse_str( $encoded_data, $data ); |
|
749 | + wp_parse_str($encoded_data, $data); |
|
750 | 750 | |
751 | - foreach ( $data as $key => $value ) { |
|
752 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
753 | - $new_key = str_replace( '&', '&', $key ); |
|
754 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
751 | + foreach ($data as $key => $value) { |
|
752 | + if (false !== strpos($key, 'amp;')) { |
|
753 | + $new_key = str_replace('&', '&', $key); |
|
754 | + $new_key = str_replace('amp;', '&', $new_key); |
|
755 | 755 | |
756 | - unset( $data[ $key ] ); |
|
757 | - $data[ $new_key ] = sanitize_text_field( $value ); |
|
756 | + unset($data[$key]); |
|
757 | + $data[$new_key] = sanitize_text_field($value); |
|
758 | 758 | } |
759 | 759 | } |
760 | 760 | |
761 | 761 | return $data; |
762 | 762 | } |
763 | 763 | |
764 | -function wpinv_gateway_support_subscription( $gateway ) { |
|
764 | +function wpinv_gateway_support_subscription($gateway) { |
|
765 | 765 | $return = false; |
766 | 766 | |
767 | - if ( wpinv_is_gateway_active( $gateway ) ) { |
|
768 | - $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false ); |
|
767 | + if (wpinv_is_gateway_active($gateway)) { |
|
768 | + $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false); |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | return $return; |
772 | 772 | } |
773 | 773 | |
774 | -function wpinv_payment_gateways_on_cart( $gateways = array() ) { |
|
775 | - if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) { |
|
776 | - foreach ( $gateways as $gateway => $info ) { |
|
777 | - if ( !wpinv_gateway_support_subscription( $gateway ) ) { |
|
778 | - unset( $gateways[$gateway] ); |
|
774 | +function wpinv_payment_gateways_on_cart($gateways = array()) { |
|
775 | + if (!empty($gateways) && wpinv_cart_has_recurring_item()) { |
|
776 | + foreach ($gateways as $gateway => $info) { |
|
777 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
778 | + unset($gateways[$gateway]); |
|
779 | 779 | } |
780 | 780 | } |
781 | 781 | } |
782 | 782 | |
783 | 783 | return $gateways; |
784 | 784 | } |
785 | -add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 ); |
|
786 | 785 | \ No newline at end of file |
786 | +add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1); |
|
787 | 787 | \ No newline at end of file |
@@ -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 | |
@@ -21,166 +21,166 @@ discard block |
||
21 | 21 | public function init() { |
22 | 22 | global $wp_filesystem; |
23 | 23 | |
24 | - if ( empty( $wp_filesystem ) ) { |
|
25 | - require_once( ABSPATH . '/wp-admin/includes/file.php' ); |
|
24 | + if (empty($wp_filesystem)) { |
|
25 | + require_once(ABSPATH . '/wp-admin/includes/file.php'); |
|
26 | 26 | WP_Filesystem(); |
27 | 27 | global $wp_filesystem; |
28 | 28 | } |
29 | 29 | $this->wp_filesystem = $wp_filesystem; |
30 | 30 | |
31 | 31 | $this->export_dir = $this->export_location(); |
32 | - $this->export_url = $this->export_location( true ); |
|
32 | + $this->export_url = $this->export_location(true); |
|
33 | 33 | $this->export = 'invoicing'; |
34 | 34 | $this->filetype = 'csv'; |
35 | 35 | $this->per_page = 20; |
36 | 36 | |
37 | - do_action( 'wpinv_class_reports_init', $this ); |
|
37 | + do_action('wpinv_class_reports_init', $this); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | public function includes() { |
41 | - do_action( 'wpinv_class_reports_includes', $this ); |
|
41 | + do_action('wpinv_class_reports_includes', $this); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | public function actions() { |
45 | - if ( is_admin() ) { |
|
46 | - add_action( 'admin_menu', array( $this, 'add_submenu' ), 10 ); |
|
47 | - add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) ); |
|
48 | - add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) ); |
|
45 | + if (is_admin()) { |
|
46 | + add_action('admin_menu', array($this, 'add_submenu'), 10); |
|
47 | + add_action('wpinv_reports_tab_export', array($this, 'export')); |
|
48 | + add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export')); |
|
49 | 49 | |
50 | 50 | // Export Invoices. |
51 | - add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) ); |
|
52 | - add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) ); |
|
53 | - add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) ); |
|
54 | - add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) ); |
|
51 | + add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export')); |
|
52 | + add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns')); |
|
53 | + add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data')); |
|
54 | + add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status')); |
|
55 | 55 | } |
56 | - do_action( 'wpinv_class_reports_actions', $this ); |
|
56 | + do_action('wpinv_class_reports_actions', $this); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | public function add_submenu() { |
60 | 60 | global $wpi_reports_page; |
61 | - $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), wpinv_get_capability(), 'wpinv-reports', array( $this, 'reports_page' ) ); |
|
61 | + $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), wpinv_get_capability(), 'wpinv-reports', array($this, 'reports_page')); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | public function reports_page() { |
65 | - if ( !wp_script_is( 'postbox', 'enqueued' ) ) { |
|
66 | - wp_enqueue_script( 'postbox' ); |
|
65 | + if (!wp_script_is('postbox', 'enqueued')) { |
|
66 | + wp_enqueue_script('postbox'); |
|
67 | 67 | } |
68 | - if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) { |
|
69 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
68 | + if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) { |
|
69 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
70 | 70 | } |
71 | 71 | |
72 | - $current_page = admin_url( 'admin.php?page=wpinv-reports' ); |
|
73 | - $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'export'; |
|
72 | + $current_page = admin_url('admin.php?page=wpinv-reports'); |
|
73 | + $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'export'; |
|
74 | 74 | ?> |
75 | 75 | <div class="wrap wpi-reports-wrap"> |
76 | - <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1> |
|
76 | + <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1> |
|
77 | 77 | <h2 class="nav-tab-wrapper wp-clearfix"> |
78 | - <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a> |
|
79 | - <?php do_action( 'wpinv_reports_page_tabs' ); ;?> |
|
78 | + <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a> |
|
79 | + <?php do_action('wpinv_reports_page_tabs'); ;?> |
|
80 | 80 | </h2> |
81 | - <div class="wpi-reports-content wpi-reports-<?php echo esc_attr( $active_tab ); ?>"> |
|
81 | + <div class="wpi-reports-content wpi-reports-<?php echo esc_attr($active_tab); ?>"> |
|
82 | 82 | <?php |
83 | - do_action( 'wpinv_reports_page_top' ); |
|
84 | - do_action( 'wpinv_reports_tab_' . $active_tab ); |
|
85 | - do_action( 'wpinv_reports_page_bottom' ); |
|
83 | + do_action('wpinv_reports_page_top'); |
|
84 | + do_action('wpinv_reports_tab_' . $active_tab); |
|
85 | + do_action('wpinv_reports_page_bottom'); |
|
86 | 86 | ?> |
87 | 87 | </div> |
88 | 88 | <?php |
89 | 89 | } |
90 | 90 | |
91 | 91 | public function export() { |
92 | - $statuses = wpinv_get_invoice_statuses( true ); |
|
93 | - $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses ); |
|
92 | + $statuses = wpinv_get_invoice_statuses(true); |
|
93 | + $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses); |
|
94 | 94 | ?> |
95 | 95 | <div class="metabox-holder"> |
96 | 96 | <div id="post-body"> |
97 | 97 | <div id="post-body-content"> |
98 | - <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?> |
|
98 | + <?php do_action('wpinv_reports_tab_export_content_top'); ?> |
|
99 | 99 | |
100 | 100 | <div class="postbox wpi-export-invoices"> |
101 | - <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2> |
|
101 | + <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2> |
|
102 | 102 | <div class="inside"> |
103 | - <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p> |
|
103 | + <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p> |
|
104 | 104 | <form id="wpi-export-invoices" class="wpi-export-form" method="post"> |
105 | - <?php echo wpinv_html_date_field( array( |
|
105 | + <?php echo wpinv_html_date_field(array( |
|
106 | 106 | 'id' => 'wpi_export_from_date', |
107 | 107 | 'name' => 'from_date', |
108 | 108 | 'data' => array( |
109 | 109 | 'dateFormat' => 'yy-mm-dd' |
110 | 110 | ), |
111 | - 'placeholder' => __( 'From date', 'invoicing' ) ) |
|
111 | + 'placeholder' => __('From date', 'invoicing') ) |
|
112 | 112 | ); ?> |
113 | - <?php echo wpinv_html_date_field( array( |
|
113 | + <?php echo wpinv_html_date_field(array( |
|
114 | 114 | 'id' => 'wpi_export_to_date', |
115 | 115 | 'name' => 'to_date', |
116 | 116 | 'data' => array( |
117 | 117 | 'dateFormat' => 'yy-mm-dd' |
118 | 118 | ), |
119 | - 'placeholder' => __( 'To date', 'invoicing' ) ) |
|
119 | + 'placeholder' => __('To date', 'invoicing') ) |
|
120 | 120 | ); ?> |
121 | 121 | <span id="wpinv-status-wrap"> |
122 | - <?php echo wpinv_html_select( array( |
|
122 | + <?php echo wpinv_html_select(array( |
|
123 | 123 | 'options' => $statuses, |
124 | 124 | 'name' => 'status', |
125 | 125 | 'id' => 'wpi_export_status', |
126 | 126 | 'show_option_all' => false, |
127 | 127 | 'show_option_none' => false, |
128 | 128 | 'class' => 'wpi_select2', |
129 | - ) ); ?> |
|
130 | - <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?> |
|
129 | + )); ?> |
|
130 | + <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?> |
|
131 | 131 | </span> |
132 | 132 | <span id="wpinv-submit-wrap"> |
133 | 133 | <input type="hidden" value="invoices" name="export" /> |
134 | - <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" /> |
|
134 | + <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" /> |
|
135 | 135 | </span> |
136 | 136 | </form> |
137 | 137 | </div> |
138 | 138 | </div> |
139 | 139 | |
140 | - <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?> |
|
140 | + <?php do_action('wpinv_reports_tab_export_content_bottom'); ?> |
|
141 | 141 | </div> |
142 | 142 | </div> |
143 | 143 | </div> |
144 | 144 | <?php |
145 | 145 | } |
146 | 146 | |
147 | - public function export_location( $relative = false ) { |
|
147 | + public function export_location($relative = false) { |
|
148 | 148 | $upload_dir = wp_upload_dir(); |
149 | - $export_location = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache'; |
|
150 | - $export_location = apply_filters( 'wpinv_export_location', $export_location, $relative ); |
|
149 | + $export_location = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache'; |
|
150 | + $export_location = apply_filters('wpinv_export_location', $export_location, $relative); |
|
151 | 151 | |
152 | - return trailingslashit( $export_location ); |
|
152 | + return trailingslashit($export_location); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | public function check_export_location() { |
156 | 156 | try { |
157 | - if ( empty( $this->wp_filesystem ) ) { |
|
158 | - return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' ); |
|
157 | + if (empty($this->wp_filesystem)) { |
|
158 | + return __('Filesystem ERROR: Could not access filesystem.', 'invoicing'); |
|
159 | 159 | } |
160 | 160 | |
161 | - if ( is_wp_error( $this->wp_filesystem ) ) { |
|
162 | - return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' ); |
|
161 | + if (is_wp_error($this->wp_filesystem)) { |
|
162 | + return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing'); |
|
163 | 163 | } |
164 | 164 | |
165 | - $is_dir = $this->wp_filesystem->is_dir( $this->export_dir ); |
|
166 | - $is_writeable = $is_dir && is_writeable( $this->export_dir ); |
|
165 | + $is_dir = $this->wp_filesystem->is_dir($this->export_dir); |
|
166 | + $is_writeable = $is_dir && is_writeable($this->export_dir); |
|
167 | 167 | |
168 | - if ( $is_dir && $is_writeable ) { |
|
168 | + if ($is_dir && $is_writeable) { |
|
169 | 169 | return true; |
170 | - } else if ( $is_dir && !$is_writeable ) { |
|
171 | - if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) { |
|
172 | - return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir ); |
|
170 | + } else if ($is_dir && !$is_writeable) { |
|
171 | + if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) { |
|
172 | + return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | return true; |
176 | 176 | } else { |
177 | - if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) { |
|
178 | - return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir ); |
|
177 | + if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) { |
|
178 | + return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | return true; |
182 | 182 | } |
183 | - } catch ( Exception $e ) { |
|
183 | + } catch (Exception $e) { |
|
184 | 184 | return $e->getMessage(); |
185 | 185 | } |
186 | 186 | } |
@@ -188,127 +188,127 @@ discard block |
||
188 | 188 | public function ajax_export() { |
189 | 189 | $response = array(); |
190 | 190 | $response['success'] = false; |
191 | - $response['msg'] = __( 'Invalid export request found.', 'invoicing' ); |
|
191 | + $response['msg'] = __('Invalid export request found.', 'invoicing'); |
|
192 | 192 | |
193 | - if ( empty( $_POST['data'] ) || ! wpinv_current_user_can_manage_invoicing() ) { |
|
194 | - wp_send_json( $response ); |
|
193 | + if (empty($_POST['data']) || !wpinv_current_user_can_manage_invoicing()) { |
|
194 | + wp_send_json($response); |
|
195 | 195 | } |
196 | 196 | |
197 | - parse_str( $_POST['data'], $data ); |
|
197 | + parse_str($_POST['data'], $data); |
|
198 | 198 | |
199 | - $data['step'] = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1; |
|
199 | + $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1; |
|
200 | 200 | |
201 | - $_REQUEST = (array)$data; |
|
202 | - if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) { |
|
203 | - $response['msg'] = __( 'Security check failed.', 'invoicing' ); |
|
204 | - wp_send_json( $response ); |
|
201 | + $_REQUEST = (array) $data; |
|
202 | + if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) { |
|
203 | + $response['msg'] = __('Security check failed.', 'invoicing'); |
|
204 | + wp_send_json($response); |
|
205 | 205 | } |
206 | 206 | |
207 | - if ( ( $error = $this->check_export_location( true ) ) !== true ) { |
|
208 | - $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' ); |
|
209 | - wp_send_json( $response ); |
|
207 | + if (($error = $this->check_export_location(true)) !== true) { |
|
208 | + $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing'); |
|
209 | + wp_send_json($response); |
|
210 | 210 | } |
211 | 211 | |
212 | - $this->set_export_params( $_REQUEST ); |
|
212 | + $this->set_export_params($_REQUEST); |
|
213 | 213 | |
214 | 214 | $return = $this->process_export_step(); |
215 | 215 | $done = $this->get_export_status(); |
216 | 216 | |
217 | - if ( $return ) { |
|
217 | + if ($return) { |
|
218 | 218 | $this->step += 1; |
219 | 219 | |
220 | 220 | $response['success'] = true; |
221 | 221 | $response['msg'] = ''; |
222 | 222 | |
223 | - if ( $done >= 100 ) { |
|
223 | + if ($done >= 100) { |
|
224 | 224 | $this->step = 'done'; |
225 | - $new_filename = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype; |
|
225 | + $new_filename = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype; |
|
226 | 226 | $new_file = $this->export_dir . $new_filename; |
227 | 227 | |
228 | - if ( file_exists( $this->file ) ) { |
|
229 | - $this->wp_filesystem->move( $this->file, $new_file, true ); |
|
228 | + if (file_exists($this->file)) { |
|
229 | + $this->wp_filesystem->move($this->file, $new_file, true); |
|
230 | 230 | } |
231 | 231 | |
232 | - if ( file_exists( $new_file ) ) { |
|
233 | - $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) ); |
|
232 | + if (file_exists($new_file)) { |
|
233 | + $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2)); |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
237 | 237 | $response['data']['step'] = $this->step; |
238 | 238 | $response['data']['done'] = $done; |
239 | 239 | } else { |
240 | - $response['msg'] = __( 'No data found for export.', 'invoicing' ); |
|
240 | + $response['msg'] = __('No data found for export.', 'invoicing'); |
|
241 | 241 | } |
242 | 242 | |
243 | - wp_send_json( $response ); |
|
243 | + wp_send_json($response); |
|
244 | 244 | } |
245 | 245 | |
246 | - public function set_export_params( $request ) { |
|
246 | + public function set_export_params($request) { |
|
247 | 247 | $this->empty = false; |
248 | - $this->step = !empty( $request['step'] ) ? absint( $request['step'] ) : 1; |
|
249 | - $this->export = !empty( $request['export'] ) ? $request['export'] : $this->export; |
|
248 | + $this->step = !empty($request['step']) ? absint($request['step']) : 1; |
|
249 | + $this->export = !empty($request['export']) ? $request['export'] : $this->export; |
|
250 | 250 | $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype; |
251 | 251 | $this->file = $this->export_dir . $this->filename; |
252 | 252 | |
253 | - do_action( 'wpinv_export_set_params_' . $this->export, $request ); |
|
253 | + do_action('wpinv_export_set_params_' . $this->export, $request); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | public function get_columns() { |
257 | 257 | $columns = array(); |
258 | 258 | |
259 | - return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns ); |
|
259 | + return apply_filters('wpinv_export_get_columns_' . $this->export, $columns); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | protected function get_export_file() { |
263 | 263 | $file = ''; |
264 | 264 | |
265 | - if ( $this->wp_filesystem->exists( $this->file ) ) { |
|
266 | - $file = $this->wp_filesystem->get_contents( $this->file ); |
|
265 | + if ($this->wp_filesystem->exists($this->file)) { |
|
266 | + $file = $this->wp_filesystem->get_contents($this->file); |
|
267 | 267 | } else { |
268 | - $this->wp_filesystem->put_contents( $this->file, '' ); |
|
268 | + $this->wp_filesystem->put_contents($this->file, ''); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | return $file; |
272 | 272 | } |
273 | 273 | |
274 | - protected function attach_export_data( $data = '' ) { |
|
275 | - $filedata = $this->get_export_file(); |
|
276 | - $filedata .= $data; |
|
274 | + protected function attach_export_data($data = '') { |
|
275 | + $filedata = $this->get_export_file(); |
|
276 | + $filedata .= $data; |
|
277 | 277 | |
278 | - $this->wp_filesystem->put_contents( $this->file, $filedata ); |
|
278 | + $this->wp_filesystem->put_contents($this->file, $filedata); |
|
279 | 279 | |
280 | - $rows = file( $this->file, FILE_SKIP_EMPTY_LINES ); |
|
280 | + $rows = file($this->file, FILE_SKIP_EMPTY_LINES); |
|
281 | 281 | $columns = $this->get_columns(); |
282 | - $columns = empty( $columns ) ? 0 : 1; |
|
282 | + $columns = empty($columns) ? 0 : 1; |
|
283 | 283 | |
284 | - $this->empty = count( $rows ) == $columns ? true : false; |
|
284 | + $this->empty = count($rows) == $columns ? true : false; |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | public function print_columns() { |
288 | 288 | $column_data = ''; |
289 | 289 | $columns = $this->get_columns(); |
290 | 290 | $i = 1; |
291 | - foreach( $columns as $key => $column ) { |
|
292 | - $column_data .= '"' . addslashes( $column ) . '"'; |
|
293 | - $column_data .= $i == count( $columns ) ? '' : ','; |
|
291 | + foreach ($columns as $key => $column) { |
|
292 | + $column_data .= '"' . addslashes($column) . '"'; |
|
293 | + $column_data .= $i == count($columns) ? '' : ','; |
|
294 | 294 | $i++; |
295 | 295 | } |
296 | 296 | $column_data .= "\r\n"; |
297 | 297 | |
298 | - $this->attach_export_data( $column_data ); |
|
298 | + $this->attach_export_data($column_data); |
|
299 | 299 | |
300 | 300 | return $column_data; |
301 | 301 | } |
302 | 302 | |
303 | 303 | public function process_export_step() { |
304 | - if ( $this->step < 2 ) { |
|
305 | - /** @scrutinizer ignore-unhandled */ @unlink( $this->file ); |
|
304 | + if ($this->step < 2) { |
|
305 | + /** @scrutinizer ignore-unhandled */ @unlink($this->file); |
|
306 | 306 | $this->print_columns(); |
307 | 307 | } |
308 | 308 | |
309 | 309 | $return = $this->print_rows(); |
310 | 310 | |
311 | - if ( $return ) { |
|
311 | + if ($return) { |
|
312 | 312 | return true; |
313 | 313 | } else { |
314 | 314 | return false; |
@@ -317,14 +317,14 @@ discard block |
||
317 | 317 | |
318 | 318 | public function get_export_status() { |
319 | 319 | $status = 100; |
320 | - return apply_filters( 'wpinv_get_export_status_' . $this->export, $status ); |
|
320 | + return apply_filters('wpinv_get_export_status_' . $this->export, $status); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | public function get_export_data() { |
324 | 324 | $data = array(); |
325 | 325 | |
326 | - $data = apply_filters( 'wpinv_export_get_data', $data ); |
|
327 | - $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data ); |
|
326 | + $data = apply_filters('wpinv_export_get_data', $data); |
|
327 | + $data = apply_filters('wpinv_export_get_data_' . $this->export, $data); |
|
328 | 328 | |
329 | 329 | return $data; |
330 | 330 | } |
@@ -334,20 +334,20 @@ discard block |
||
334 | 334 | $data = $this->get_export_data(); |
335 | 335 | $columns = $this->get_columns(); |
336 | 336 | |
337 | - if ( $data ) { |
|
338 | - foreach ( $data as $row ) { |
|
337 | + if ($data) { |
|
338 | + foreach ($data as $row) { |
|
339 | 339 | $i = 1; |
340 | - foreach ( $row as $key => $column ) { |
|
341 | - if ( array_key_exists( $key, $columns ) ) { |
|
342 | - $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"'; |
|
343 | - $row_data .= $i == count( $columns ) ? '' : ','; |
|
340 | + foreach ($row as $key => $column) { |
|
341 | + if (array_key_exists($key, $columns)) { |
|
342 | + $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"'; |
|
343 | + $row_data .= $i == count($columns) ? '' : ','; |
|
344 | 344 | $i++; |
345 | 345 | } |
346 | 346 | } |
347 | 347 | $row_data .= "\r\n"; |
348 | 348 | } |
349 | 349 | |
350 | - $this->attach_export_data( $row_data ); |
|
350 | + $this->attach_export_data($row_data); |
|
351 | 351 | |
352 | 352 | return $row_data; |
353 | 353 | } |
@@ -356,48 +356,48 @@ discard block |
||
356 | 356 | } |
357 | 357 | |
358 | 358 | // Export Invoices. |
359 | - public function set_invoices_export( $request ) { |
|
360 | - $this->from_date = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : ''; |
|
361 | - $this->to_date = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : ''; |
|
362 | - $this->status = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publish'; |
|
359 | + public function set_invoices_export($request) { |
|
360 | + $this->from_date = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : ''; |
|
361 | + $this->to_date = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : ''; |
|
362 | + $this->status = isset($request['status']) ? sanitize_text_field($request['status']) : 'publish'; |
|
363 | 363 | } |
364 | 364 | |
365 | - public function get_invoices_columns( $columns = array() ) { |
|
365 | + public function get_invoices_columns($columns = array()) { |
|
366 | 366 | $columns = array( |
367 | - 'id' => __( 'ID', 'invoicing' ), |
|
368 | - 'number' => __( 'Number', 'invoicing' ), |
|
369 | - 'date' => __( 'Date', 'invoicing' ), |
|
370 | - 'due_date' => __( 'Due Date', 'invoicing' ), |
|
371 | - 'completed_date'=> __( 'Payment Done Date', 'invoicing' ), |
|
372 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
373 | - 'currency' => __( 'Currency', 'invoicing' ), |
|
374 | - 'items' => __( 'Items', 'invoicing' ), |
|
375 | - 'status_nicename' => __( 'Status Nicename', 'invoicing' ), |
|
376 | - 'status' => __( 'Status', 'invoicing' ), |
|
377 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
378 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
379 | - 'user_id' => __( 'User ID', 'invoicing' ), |
|
380 | - 'email' => __( 'Email', 'invoicing' ), |
|
381 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
382 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
383 | - 'address' => __( 'Address', 'invoicing' ), |
|
384 | - 'city' => __( 'City', 'invoicing' ), |
|
385 | - 'state' => __( 'State', 'invoicing' ), |
|
386 | - 'country' => __( 'Country', 'invoicing' ), |
|
387 | - 'zip' => __( 'Zipcode', 'invoicing' ), |
|
388 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
389 | - 'company' => __( 'Company', 'invoicing' ), |
|
390 | - 'vat_number' => __( 'Vat Number', 'invoicing' ), |
|
391 | - 'ip' => __( 'IP', 'invoicing' ), |
|
392 | - 'gateway' => __( 'Gateway', 'invoicing' ), |
|
393 | - 'gateway_nicename' => __( 'Gateway Nicename', 'invoicing' ), |
|
394 | - 'transaction_id'=> __( 'Transaction ID', 'invoicing' ), |
|
367 | + 'id' => __('ID', 'invoicing'), |
|
368 | + 'number' => __('Number', 'invoicing'), |
|
369 | + 'date' => __('Date', 'invoicing'), |
|
370 | + 'due_date' => __('Due Date', 'invoicing'), |
|
371 | + 'completed_date'=> __('Payment Done Date', 'invoicing'), |
|
372 | + 'amount' => __('Amount', 'invoicing'), |
|
373 | + 'currency' => __('Currency', 'invoicing'), |
|
374 | + 'items' => __('Items', 'invoicing'), |
|
375 | + 'status_nicename' => __('Status Nicename', 'invoicing'), |
|
376 | + 'status' => __('Status', 'invoicing'), |
|
377 | + 'tax' => __('Tax', 'invoicing'), |
|
378 | + 'discount' => __('Discount', 'invoicing'), |
|
379 | + 'user_id' => __('User ID', 'invoicing'), |
|
380 | + 'email' => __('Email', 'invoicing'), |
|
381 | + 'first_name' => __('First Name', 'invoicing'), |
|
382 | + 'last_name' => __('Last Name', 'invoicing'), |
|
383 | + 'address' => __('Address', 'invoicing'), |
|
384 | + 'city' => __('City', 'invoicing'), |
|
385 | + 'state' => __('State', 'invoicing'), |
|
386 | + 'country' => __('Country', 'invoicing'), |
|
387 | + 'zip' => __('Zipcode', 'invoicing'), |
|
388 | + 'phone' => __('Phone', 'invoicing'), |
|
389 | + 'company' => __('Company', 'invoicing'), |
|
390 | + 'vat_number' => __('Vat Number', 'invoicing'), |
|
391 | + 'ip' => __('IP', 'invoicing'), |
|
392 | + 'gateway' => __('Gateway', 'invoicing'), |
|
393 | + 'gateway_nicename' => __('Gateway Nicename', 'invoicing'), |
|
394 | + 'transaction_id'=> __('Transaction ID', 'invoicing'), |
|
395 | 395 | ); |
396 | 396 | |
397 | 397 | return $columns; |
398 | 398 | } |
399 | 399 | |
400 | - public function get_invoices_data( $response = array() ) { |
|
400 | + public function get_invoices_data($response = array()) { |
|
401 | 401 | $args = array( |
402 | 402 | 'limit' => $this->per_page, |
403 | 403 | 'page' => $this->step, |
@@ -405,42 +405,42 @@ discard block |
||
405 | 405 | 'orderby' => 'date', |
406 | 406 | ); |
407 | 407 | |
408 | - if ( $this->status != 'any' ) { |
|
408 | + if ($this->status != 'any') { |
|
409 | 409 | $args['status'] = $this->status; |
410 | 410 | } else { |
411 | - $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
411 | + $args['status'] = array_keys(wpinv_get_invoice_statuses(true)); |
|
412 | 412 | } |
413 | 413 | |
414 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
414 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
415 | 415 | $args['date_query'] = array( |
416 | 416 | array( |
417 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
418 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
417 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
418 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
419 | 419 | 'inclusive' => true |
420 | 420 | ) |
421 | 421 | ); |
422 | 422 | } |
423 | 423 | |
424 | - $invoices = wpinv_get_invoices( $args ); |
|
424 | + $invoices = wpinv_get_invoices($args); |
|
425 | 425 | |
426 | 426 | $data = array(); |
427 | 427 | |
428 | - if ( !empty( $invoices ) ) { |
|
429 | - foreach ( $invoices as $invoice ) { |
|
428 | + if (!empty($invoices)) { |
|
429 | + foreach ($invoices as $invoice) { |
|
430 | 430 | $items = $this->get_invoice_items($invoice); |
431 | 431 | $row = array( |
432 | 432 | 'id' => $invoice->ID, |
433 | 433 | 'number' => $invoice->get_number(), |
434 | - 'date' => $invoice->get_invoice_date( false ), |
|
435 | - 'due_date' => $invoice->get_due_date( false ), |
|
434 | + 'date' => $invoice->get_invoice_date(false), |
|
435 | + 'due_date' => $invoice->get_due_date(false), |
|
436 | 436 | 'completed_date'=> $invoice->get_completed_date(), |
437 | - 'amount' => wpinv_round_amount( $invoice->get_total() ), |
|
437 | + 'amount' => wpinv_round_amount($invoice->get_total()), |
|
438 | 438 | 'currency' => $invoice->get_currency(), |
439 | 439 | 'items' => $items, |
440 | - 'status_nicename' => $invoice->get_status( true ), |
|
440 | + 'status_nicename' => $invoice->get_status(true), |
|
441 | 441 | 'status' => $invoice->get_status(), |
442 | - 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '', |
|
443 | - 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '', |
|
442 | + 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '', |
|
443 | + 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '', |
|
444 | 444 | 'user_id' => $invoice->get_user_id(), |
445 | 445 | 'email' => $invoice->get_email(), |
446 | 446 | 'first_name' => $invoice->get_first_name(), |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | 'transaction_id'=> $invoice->gateway ? $invoice->get_transaction_id() : '', |
460 | 460 | ); |
461 | 461 | |
462 | - $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice ); |
|
462 | + $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | return $data; |
@@ -475,44 +475,44 @@ discard block |
||
475 | 475 | 'return' => 'ids', |
476 | 476 | ); |
477 | 477 | |
478 | - if ( $this->status != 'any' ) { |
|
478 | + if ($this->status != 'any') { |
|
479 | 479 | $args['status'] = $this->status; |
480 | 480 | } else { |
481 | - $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
481 | + $args['status'] = array_keys(wpinv_get_invoice_statuses(true)); |
|
482 | 482 | } |
483 | 483 | |
484 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
484 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
485 | 485 | $args['date_query'] = array( |
486 | 486 | array( |
487 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
488 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
487 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
488 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
489 | 489 | 'inclusive' => true |
490 | 490 | ) |
491 | 491 | ); |
492 | 492 | } |
493 | 493 | |
494 | - $invoices = wpinv_get_invoices( $args ); |
|
495 | - $total = !empty( $invoices ) ? count( $invoices ) : 0; |
|
494 | + $invoices = wpinv_get_invoices($args); |
|
495 | + $total = !empty($invoices) ? count($invoices) : 0; |
|
496 | 496 | $status = 100; |
497 | 497 | |
498 | - if ( $total > 0 ) { |
|
499 | - $status = ( ( $this->per_page * $this->step ) / $total ) * 100; |
|
498 | + if ($total > 0) { |
|
499 | + $status = (($this->per_page * $this->step) / $total) * 100; |
|
500 | 500 | } |
501 | 501 | |
502 | - if ( $status > 100 ) { |
|
502 | + if ($status > 100) { |
|
503 | 503 | $status = 100; |
504 | 504 | } |
505 | 505 | |
506 | 506 | return $status; |
507 | 507 | } |
508 | 508 | |
509 | - public function get_invoice_items($invoice){ |
|
510 | - if(!$invoice){ |
|
509 | + public function get_invoice_items($invoice) { |
|
510 | + if (!$invoice) { |
|
511 | 511 | return ''; |
512 | 512 | } |
513 | 513 | |
514 | 514 | $cart_details = $invoice->get_cart_details(); |
515 | - if(!empty($cart_details)){ |
|
515 | + if (!empty($cart_details)) { |
|
516 | 516 | $cart_details = maybe_serialize($cart_details); |
517 | 517 | } else { |
518 | 518 | $cart_details = ''; |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 1.0.13 |
9 | 9 | */ |
10 | 10 | |
11 | -if ( !defined( 'WPINC' ) ) { |
|
11 | +if (!defined('WPINC')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @param string $namespace Api Namespace |
43 | 43 | */ |
44 | - public function __construct( $namespace ) { |
|
44 | + public function __construct($namespace) { |
|
45 | 45 | |
46 | 46 | // Set api namespace... |
47 | 47 | $this->namespace = $namespace; |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | array( |
69 | 69 | array( |
70 | 70 | 'methods' => WP_REST_Server::READABLE, |
71 | - 'callback' => array( $this, 'get_discount_types' ), |
|
71 | + 'callback' => array($this, 'get_discount_types'), |
|
72 | 72 | ), |
73 | 73 | ) |
74 | 74 | ); |
@@ -84,13 +84,13 @@ discard block |
||
84 | 84 | * @param WP_REST_Request $request Full details about the request. |
85 | 85 | * @return true|WP_Error True if the request has read access, WP_Error object otherwise. |
86 | 86 | */ |
87 | - public function get_items_permissions_check( $request ) { |
|
87 | + public function get_items_permissions_check($request) { |
|
88 | 88 | |
89 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
89 | + if (wpinv_current_user_can_manage_invoicing()) { |
|
90 | 90 | return true; |
91 | 91 | } |
92 | 92 | |
93 | - return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to view invoice discounts.', 'invoicing' ), array( 'status' => rest_authorization_required_code() ) ); |
|
93 | + return new WP_Error('rest_forbidden_context', __('Sorry, you are not allowed to view invoice discounts.', 'invoicing'), array('status' => rest_authorization_required_code())); |
|
94 | 94 | |
95 | 95 | } |
96 | 96 | |
@@ -102,17 +102,17 @@ discard block |
||
102 | 102 | * @param WP_REST_Request $request Full details about the request. |
103 | 103 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
104 | 104 | */ |
105 | - public function get_items( $request ) { |
|
105 | + public function get_items($request) { |
|
106 | 106 | |
107 | 107 | // Retrieve the list of registered item query parameters. |
108 | 108 | $registered = $this->get_collection_params(); |
109 | 109 | |
110 | 110 | $args = array(); |
111 | 111 | |
112 | - foreach( array_keys( $registered ) as $key ) { |
|
112 | + foreach (array_keys($registered) as $key) { |
|
113 | 113 | |
114 | - if( isset( $request[ $key] ) ) { |
|
115 | - $args[ $key ] = $request[ $key]; |
|
114 | + if (isset($request[$key])) { |
|
115 | + $args[$key] = $request[$key]; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | } |
@@ -127,28 +127,28 @@ discard block |
||
127 | 127 | * @param array $args Key value array of query var to query value. |
128 | 128 | * @param WP_REST_Request $request The request used. |
129 | 129 | */ |
130 | - $args = apply_filters( "wpinv_rest_get_discounts_arguments", $args, $request, $this ); |
|
130 | + $args = apply_filters("wpinv_rest_get_discounts_arguments", $args, $request, $this); |
|
131 | 131 | |
132 | 132 | // Special args |
133 | - $args[ 'return' ] = 'objects'; |
|
134 | - $args[ 'paginate' ] = true; |
|
133 | + $args['return'] = 'objects'; |
|
134 | + $args['paginate'] = true; |
|
135 | 135 | |
136 | 136 | // Run the query. |
137 | - $query = wpinv_get_all_discounts( $args ); |
|
137 | + $query = wpinv_get_all_discounts($args); |
|
138 | 138 | |
139 | 139 | // Prepare the retrieved discounts |
140 | 140 | $discounts = array(); |
141 | - foreach( $query->discounts as $discount ) { |
|
141 | + foreach ($query->discounts as $discount) { |
|
142 | 142 | |
143 | - $data = $this->prepare_item_for_response( $discount, $request ); |
|
144 | - $discounts[] = $this->prepare_response_for_collection( $data ); |
|
143 | + $data = $this->prepare_item_for_response($discount, $request); |
|
144 | + $discounts[] = $this->prepare_response_for_collection($data); |
|
145 | 145 | |
146 | 146 | } |
147 | 147 | |
148 | 148 | // Prepare the response. |
149 | - $response = rest_ensure_response( $discounts ); |
|
150 | - $response->header( 'X-WP-Total', (int) $query->total ); |
|
151 | - $response->header( 'X-WP-TotalPages', (int) $query->max_num_pages ); |
|
149 | + $response = rest_ensure_response($discounts); |
|
150 | + $response->header('X-WP-Total', (int) $query->total); |
|
151 | + $response->header('X-WP-TotalPages', (int) $query->max_num_pages); |
|
152 | 152 | |
153 | 153 | /** |
154 | 154 | * Filters the responses for discount requests. |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | * @param WP_REST_Request $request The request used. |
162 | 162 | * @param array $args Array of args used to retrieve the discounts |
163 | 163 | */ |
164 | - $response = apply_filters( "wpinv_rest_discounts_response", $response, $request, $args ); |
|
164 | + $response = apply_filters("wpinv_rest_discounts_response", $response, $request, $args); |
|
165 | 165 | |
166 | - return rest_ensure_response( $response ); |
|
166 | + return rest_ensure_response($response); |
|
167 | 167 | |
168 | 168 | } |
169 | 169 | |
@@ -175,17 +175,17 @@ discard block |
||
175 | 175 | * @param int $discount_id Supplied ID. |
176 | 176 | * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise. |
177 | 177 | */ |
178 | - protected function get_post( $discount_id ) { |
|
178 | + protected function get_post($discount_id) { |
|
179 | 179 | |
180 | - $error = new WP_Error( 'rest_item_invalid_id', __( 'Invalid discount ID.', 'invoicing' ), array( 'status' => 404 ) ); |
|
180 | + $error = new WP_Error('rest_item_invalid_id', __('Invalid discount ID.', 'invoicing'), array('status' => 404)); |
|
181 | 181 | |
182 | 182 | // Ids start from 1 |
183 | - if ( (int) $discount_id <= 0 ) { |
|
183 | + if ((int) $discount_id <= 0) { |
|
184 | 184 | return $error; |
185 | 185 | } |
186 | 186 | |
187 | - $discount = wpinv_get_discount( (int) $discount_id ); |
|
188 | - if ( empty( $discount ) ) { |
|
187 | + $discount = wpinv_get_discount((int) $discount_id); |
|
188 | + if (empty($discount)) { |
|
189 | 189 | return $error; |
190 | 190 | } |
191 | 191 | |
@@ -201,20 +201,20 @@ discard block |
||
201 | 201 | * @param WP_REST_Request $request Full details about the request. |
202 | 202 | * @return bool|WP_Error True if the request has read access for the invoice item, WP_Error object otherwise. |
203 | 203 | */ |
204 | - public function get_item_permissions_check( $request ) { |
|
204 | + public function get_item_permissions_check($request) { |
|
205 | 205 | |
206 | 206 | // Retrieve the discount object. |
207 | - $discount = $this->get_post( $request['id'] ); |
|
207 | + $discount = $this->get_post($request['id']); |
|
208 | 208 | |
209 | 209 | // Ensure it is valid. |
210 | - if ( is_wp_error( $discount ) ) { |
|
210 | + if (is_wp_error($discount)) { |
|
211 | 211 | return $discount; |
212 | 212 | } |
213 | 213 | |
214 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
214 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
215 | 215 | return new WP_Error( |
216 | 216 | 'rest_cannot_view', |
217 | - __( 'Sorry, you are not allowed to view this discount.', 'invoicing' ), |
|
217 | + __('Sorry, you are not allowed to view this discount.', 'invoicing'), |
|
218 | 218 | array( |
219 | 219 | 'status' => rest_authorization_required_code(), |
220 | 220 | ) |
@@ -232,18 +232,18 @@ discard block |
||
232 | 232 | * @param WP_REST_Request $request Full details about the request. |
233 | 233 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
234 | 234 | */ |
235 | - public function get_item( $request ) { |
|
235 | + public function get_item($request) { |
|
236 | 236 | |
237 | 237 | // Fetch the discount. |
238 | - $discount = $this->get_post( $request['id'] ); |
|
238 | + $discount = $this->get_post($request['id']); |
|
239 | 239 | |
240 | 240 | // Abort early if it does not exist |
241 | - if ( is_wp_error( $discount ) ) { |
|
241 | + if (is_wp_error($discount)) { |
|
242 | 242 | return $discount; |
243 | 243 | } |
244 | 244 | |
245 | 245 | // Prepare the response |
246 | - $response = $this->prepare_item_for_response( $discount, $request ); |
|
246 | + $response = $this->prepare_item_for_response($discount, $request); |
|
247 | 247 | |
248 | 248 | /** |
249 | 249 | * Filters the responses for single discount requests. |
@@ -255,9 +255,9 @@ discard block |
||
255 | 255 | * @param WP_HTTP_Response $response Response. |
256 | 256 | * @param WP_REST_Request $request The request used. |
257 | 257 | */ |
258 | - $response = apply_filters( "wpinv_rest_get_discount_response", $response, $request ); |
|
258 | + $response = apply_filters("wpinv_rest_get_discount_response", $response, $request); |
|
259 | 259 | |
260 | - return rest_ensure_response( $response ); |
|
260 | + return rest_ensure_response($response); |
|
261 | 261 | |
262 | 262 | } |
263 | 263 | |
@@ -269,21 +269,21 @@ discard block |
||
269 | 269 | * @param WP_REST_Request $request Full details about the request. |
270 | 270 | * @return true|WP_Error True if the request has access to create items, WP_Error object otherwise. |
271 | 271 | */ |
272 | - public function create_item_permissions_check( $request ) { |
|
272 | + public function create_item_permissions_check($request) { |
|
273 | 273 | |
274 | - if ( ! empty( $request['id'] ) ) { |
|
275 | - return new WP_Error( 'rest_item_exists', __( 'Cannot create existing item.', 'invoicing' ), array( 'status' => 400 ) ); |
|
274 | + if (!empty($request['id'])) { |
|
275 | + return new WP_Error('rest_item_exists', __('Cannot create existing item.', 'invoicing'), array('status' => 400)); |
|
276 | 276 | } |
277 | 277 | |
278 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
278 | + if (wpinv_current_user_can_manage_invoicing()) { |
|
279 | 279 | return true; |
280 | 280 | } |
281 | 281 | |
282 | - $post_type = get_post_type_object( $this->post_type ); |
|
283 | - if ( ! current_user_can( $post_type->cap->create_posts ) ) { |
|
282 | + $post_type = get_post_type_object($this->post_type); |
|
283 | + if (!current_user_can($post_type->cap->create_posts)) { |
|
284 | 284 | return new WP_Error( |
285 | 285 | 'rest_cannot_create', |
286 | - __( 'Sorry, you are not allowed to create discounts as this user.', 'invoicing' ), |
|
286 | + __('Sorry, you are not allowed to create discounts as this user.', 'invoicing'), |
|
287 | 287 | array( |
288 | 288 | 'status' => rest_authorization_required_code(), |
289 | 289 | ) |
@@ -301,32 +301,32 @@ discard block |
||
301 | 301 | * @param WP_REST_Request $request Full details about the request. |
302 | 302 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
303 | 303 | */ |
304 | - public function create_item( $request ) { |
|
304 | + public function create_item($request) { |
|
305 | 305 | |
306 | - if ( ! empty( $request['id'] ) ) { |
|
307 | - return new WP_Error( 'rest_item_exists', __( 'Cannot create existing discount.', 'invoicing' ), array( 'status' => 400 ) ); |
|
306 | + if (!empty($request['id'])) { |
|
307 | + return new WP_Error('rest_item_exists', __('Cannot create existing discount.', 'invoicing'), array('status' => 400)); |
|
308 | 308 | } |
309 | 309 | |
310 | - $request->set_param( 'context', 'edit' ); |
|
310 | + $request->set_param('context', 'edit'); |
|
311 | 311 | |
312 | 312 | // Prepare the updated data. |
313 | - $discount_data = $this->prepare_item_for_database( $request ); |
|
313 | + $discount_data = $this->prepare_item_for_database($request); |
|
314 | 314 | |
315 | - if ( is_wp_error( $discount_data ) ) { |
|
315 | + if (is_wp_error($discount_data)) { |
|
316 | 316 | return $discount_data; |
317 | 317 | } |
318 | 318 | |
319 | 319 | $discount_data['post_type'] = $this->post_type; |
320 | 320 | |
321 | 321 | // Try creating the discount. |
322 | - $discount = wp_insert_post( $discount_data, true ); |
|
322 | + $discount = wp_insert_post($discount_data, true); |
|
323 | 323 | |
324 | - if ( is_wp_error( $discount ) ) { |
|
324 | + if (is_wp_error($discount)) { |
|
325 | 325 | return $discount; |
326 | 326 | } |
327 | 327 | |
328 | 328 | // Prepare the response |
329 | - $response = $this->prepare_item_for_response( $discount, $request ); |
|
329 | + $response = $this->prepare_item_for_response($discount, $request); |
|
330 | 330 | |
331 | 331 | /** |
332 | 332 | * Fires after a single discount is created or updated via the REST API. |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | * @param WP_REST_Request $request Request object. |
338 | 338 | * @param bool $creating True when creating a post, false when updating. |
339 | 339 | */ |
340 | - do_action( "wpinv_rest_insert_discount", $discount, $request, true ); |
|
340 | + do_action("wpinv_rest_insert_discount", $discount, $request, true); |
|
341 | 341 | |
342 | 342 | /** |
343 | 343 | * Filters the responses for creating single item requests. |
@@ -349,9 +349,9 @@ discard block |
||
349 | 349 | * @param array $response Invoice properties. |
350 | 350 | * @param WP_REST_Request $request The request used. |
351 | 351 | */ |
352 | - $response = apply_filters( "wpinv_rest_create_discount_response", $response, $request ); |
|
352 | + $response = apply_filters("wpinv_rest_create_discount_response", $response, $request); |
|
353 | 353 | |
354 | - return rest_ensure_response( $response ); |
|
354 | + return rest_ensure_response($response); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -362,21 +362,21 @@ discard block |
||
362 | 362 | * @param WP_REST_Request $request Full details about the request. |
363 | 363 | * @return true|WP_Error True if the request has access to update the item, WP_Error object otherwise. |
364 | 364 | */ |
365 | - public function update_item_permissions_check( $request ) { |
|
365 | + public function update_item_permissions_check($request) { |
|
366 | 366 | |
367 | 367 | // Retrieve the item. |
368 | - $item = $this->get_post( $request['id'] ); |
|
369 | - if ( is_wp_error( $item ) ) { |
|
368 | + $item = $this->get_post($request['id']); |
|
369 | + if (is_wp_error($item)) { |
|
370 | 370 | return $item; |
371 | 371 | } |
372 | 372 | |
373 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
373 | + if (wpinv_current_user_can_manage_invoicing()) { |
|
374 | 374 | return true; |
375 | 375 | } |
376 | 376 | |
377 | 377 | return new WP_Error( |
378 | 378 | 'rest_cannot_edit', |
379 | - __( 'Sorry, you are not allowed to update this discount.', 'invoicing' ), |
|
379 | + __('Sorry, you are not allowed to update this discount.', 'invoicing'), |
|
380 | 380 | array( |
381 | 381 | 'status' => rest_authorization_required_code(), |
382 | 382 | ) |
@@ -392,62 +392,62 @@ discard block |
||
392 | 392 | * @param WP_REST_Request $request Full details about the request. |
393 | 393 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
394 | 394 | */ |
395 | - public function update_item( $request ) { |
|
395 | + public function update_item($request) { |
|
396 | 396 | |
397 | 397 | // Ensure the item exists. |
398 | - $valid_check = $this->get_post( $request['id'] ); |
|
398 | + $valid_check = $this->get_post($request['id']); |
|
399 | 399 | |
400 | 400 | // Abort early if it does not exist |
401 | - if ( is_wp_error( $valid_check ) ) { |
|
401 | + if (is_wp_error($valid_check)) { |
|
402 | 402 | return $valid_check; |
403 | 403 | } |
404 | 404 | |
405 | - $request->set_param( 'context', 'edit' ); |
|
405 | + $request->set_param('context', 'edit'); |
|
406 | 406 | |
407 | 407 | // Prepare the updated data. |
408 | - $data_to_update = $this->prepare_item_for_database( $request ); |
|
408 | + $data_to_update = $this->prepare_item_for_database($request); |
|
409 | 409 | |
410 | - if ( is_wp_error( $data_to_update ) ) { |
|
410 | + if (is_wp_error($data_to_update)) { |
|
411 | 411 | return $data_to_update; |
412 | 412 | } |
413 | 413 | |
414 | - if( empty( $data_to_update['meta_input'] ) ) { |
|
415 | - unset( $data_to_update['meta_input'] ); |
|
414 | + if (empty($data_to_update['meta_input'])) { |
|
415 | + unset($data_to_update['meta_input']); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | // Abort if no item data is provided |
419 | - if( empty( $data_to_update ) ) { |
|
420 | - return new WP_Error( 'missing_data', __( 'An update request cannot be empty.', 'invoicing' ) ); |
|
419 | + if (empty($data_to_update)) { |
|
420 | + return new WP_Error('missing_data', __('An update request cannot be empty.', 'invoicing')); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | // post_status |
424 | - if( ! empty( $data_to_update['post_status'] ) ) { |
|
425 | - wpinv_update_discount_status( $request['id'], $data_to_update['post_status'] ); |
|
426 | - unset( $data_to_update['post_status'] ); |
|
424 | + if (!empty($data_to_update['post_status'])) { |
|
425 | + wpinv_update_discount_status($request['id'], $data_to_update['post_status']); |
|
426 | + unset($data_to_update['post_status']); |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | // Update the item |
430 | - if( ! empty( $data_to_update ) ) { |
|
430 | + if (!empty($data_to_update)) { |
|
431 | 431 | |
432 | 432 | // Include the item ID |
433 | 433 | $data_to_update['ID'] = $request['id']; |
434 | 434 | |
435 | - $updated = wp_update_post( $data_to_update, true ); |
|
435 | + $updated = wp_update_post($data_to_update, true); |
|
436 | 436 | |
437 | 437 | // Incase the update operation failed... |
438 | - if ( is_wp_error( $updated ) ) { |
|
438 | + if (is_wp_error($updated)) { |
|
439 | 439 | return $updated; |
440 | 440 | } |
441 | 441 | |
442 | 442 | } |
443 | 443 | |
444 | - $updated_discount = get_post( $request['id'] ); |
|
444 | + $updated_discount = get_post($request['id']); |
|
445 | 445 | |
446 | 446 | // Prepare the response |
447 | - $response = $this->prepare_item_for_response( $updated_discount, $request ); |
|
447 | + $response = $this->prepare_item_for_response($updated_discount, $request); |
|
448 | 448 | |
449 | 449 | /** This action is documented in includes/class-wpinv-rest-item-controller.php */ |
450 | - do_action( "wpinv_rest_insert_discount", $updated_discount, $request, false ); |
|
450 | + do_action("wpinv_rest_insert_discount", $updated_discount, $request, false); |
|
451 | 451 | |
452 | 452 | /** |
453 | 453 | * Filters the responses for updating single discount requests. |
@@ -459,9 +459,9 @@ discard block |
||
459 | 459 | * @param array $data_to_update Discount properties. |
460 | 460 | * @param WP_REST_Request $request The request used. |
461 | 461 | */ |
462 | - $response = apply_filters( "wpinv_rest_update_discount_response", $response, $data_to_update, $request ); |
|
462 | + $response = apply_filters("wpinv_rest_update_discount_response", $response, $data_to_update, $request); |
|
463 | 463 | |
464 | - return rest_ensure_response( $response ); |
|
464 | + return rest_ensure_response($response); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | /** |
@@ -472,19 +472,19 @@ discard block |
||
472 | 472 | * @param WP_REST_Request $request Full details about the request. |
473 | 473 | * @return true|WP_Error True if the request has access to delete the discount, WP_Error object otherwise. |
474 | 474 | */ |
475 | - public function delete_item_permissions_check( $request ) { |
|
475 | + public function delete_item_permissions_check($request) { |
|
476 | 476 | |
477 | 477 | // Retrieve the discount. |
478 | - $discount = $this->get_post( $request['id'] ); |
|
479 | - if ( is_wp_error( $discount ) ) { |
|
478 | + $discount = $this->get_post($request['id']); |
|
479 | + if (is_wp_error($discount)) { |
|
480 | 480 | return $discount; |
481 | 481 | } |
482 | 482 | |
483 | 483 | // Ensure the current user can delete the discount |
484 | - if (! wpinv_current_user_can_manage_invoicing() ) { |
|
484 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
485 | 485 | return new WP_Error( |
486 | 486 | 'rest_cannot_delete', |
487 | - __( 'Sorry, you are not allowed to delete this discount.', 'invoicing' ), |
|
487 | + __('Sorry, you are not allowed to delete this discount.', 'invoicing'), |
|
488 | 488 | array( |
489 | 489 | 'status' => rest_authorization_required_code(), |
490 | 490 | ) |
@@ -502,24 +502,24 @@ discard block |
||
502 | 502 | * @param WP_REST_Request $request Full details about the request. |
503 | 503 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
504 | 504 | */ |
505 | - public function delete_item( $request ) { |
|
505 | + public function delete_item($request) { |
|
506 | 506 | |
507 | 507 | // Retrieve the discount. |
508 | - $discount = $this->get_post( $request['id'] ); |
|
509 | - if ( is_wp_error( $discount ) ) { |
|
508 | + $discount = $this->get_post($request['id']); |
|
509 | + if (is_wp_error($discount)) { |
|
510 | 510 | return $discount; |
511 | 511 | } |
512 | 512 | |
513 | - $request->set_param( 'context', 'edit' ); |
|
513 | + $request->set_param('context', 'edit'); |
|
514 | 514 | |
515 | 515 | // Prepare the discount id |
516 | - $id = $discount->ID; |
|
516 | + $id = $discount->ID; |
|
517 | 517 | |
518 | 518 | // Prepare the response |
519 | - $response = $this->prepare_item_for_response( $discount, $request ); |
|
519 | + $response = $this->prepare_item_for_response($discount, $request); |
|
520 | 520 | |
521 | 521 | // Delete the discount... |
522 | - wpinv_remove_discount( $id ); |
|
522 | + wpinv_remove_discount($id); |
|
523 | 523 | |
524 | 524 | /** |
525 | 525 | * Fires immediately after a single discount is deleted via the REST API. |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | * @param WP_POST $discount The deleted discount. |
531 | 531 | * @param WP_REST_Request $request The request sent to the API. |
532 | 532 | */ |
533 | - do_action( "wpinv_rest_delete_discount", $discount, $request ); |
|
533 | + do_action("wpinv_rest_delete_discount", $discount, $request); |
|
534 | 534 | |
535 | 535 | return $response; |
536 | 536 | |
@@ -546,44 +546,44 @@ discard block |
||
546 | 546 | */ |
547 | 547 | public function get_collection_params() { |
548 | 548 | |
549 | - $query_params = array( |
|
549 | + $query_params = array( |
|
550 | 550 | |
551 | 551 | // Discount status. |
552 | 552 | 'status' => array( |
553 | 553 | 'default' => 'publish', |
554 | - 'description' => __( 'Limit result set to discounts assigned one or more statuses.', 'invoicing' ), |
|
554 | + 'description' => __('Limit result set to discounts assigned one or more statuses.', 'invoicing'), |
|
555 | 555 | 'type' => 'array', |
556 | - 'sanitize_callback' => array( $this, 'sanitize_post_statuses' ), |
|
556 | + 'sanitize_callback' => array($this, 'sanitize_post_statuses'), |
|
557 | 557 | ), |
558 | 558 | |
559 | 559 | // Discount types |
560 | 560 | 'type' => array( |
561 | - 'description' => __( 'Type of discounts to fetch.', 'invoicing' ), |
|
561 | + 'description' => __('Type of discounts to fetch.', 'invoicing'), |
|
562 | 562 | 'type' => 'array', |
563 | - 'default' => array_keys( wpinv_get_discount_types() ), |
|
563 | + 'default' => array_keys(wpinv_get_discount_types()), |
|
564 | 564 | 'items' => array( |
565 | - 'enum' => array_keys( wpinv_get_discount_types() ), |
|
565 | + 'enum' => array_keys(wpinv_get_discount_types()), |
|
566 | 566 | 'type' => 'string', |
567 | 567 | ), |
568 | 568 | ), |
569 | 569 | |
570 | 570 | // Number of results per page |
571 | 571 | 'limit' => array( |
572 | - 'description' => __( 'Number of discounts to fetch.', 'invoicing' ), |
|
572 | + 'description' => __('Number of discounts to fetch.', 'invoicing'), |
|
573 | 573 | 'type' => 'integer', |
574 | - 'default' => (int) get_option( 'posts_per_page' ), |
|
574 | + 'default' => (int) get_option('posts_per_page'), |
|
575 | 575 | ), |
576 | 576 | |
577 | 577 | // Pagination |
578 | 578 | 'page' => array( |
579 | - 'description' => __( 'Current page to fetch.', 'invoicing' ), |
|
579 | + 'description' => __('Current page to fetch.', 'invoicing'), |
|
580 | 580 | 'type' => 'integer', |
581 | 581 | 'default' => 1, |
582 | 582 | ), |
583 | 583 | |
584 | 584 | // Exclude certain items |
585 | 585 | 'exclude' => array( |
586 | - 'description' => __( 'Ensure result set excludes specific IDs.', 'invoicing' ), |
|
586 | + 'description' => __('Ensure result set excludes specific IDs.', 'invoicing'), |
|
587 | 587 | 'type' => 'array', |
588 | 588 | 'items' => array( |
589 | 589 | 'type' => 'integer', |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | |
594 | 594 | // Order discounts by |
595 | 595 | 'orderby' => array( |
596 | - 'description' => __( 'Sort discounts by object attribute.', 'invoicing' ), |
|
596 | + 'description' => __('Sort discounts by object attribute.', 'invoicing'), |
|
597 | 597 | 'type' => 'string', |
598 | 598 | 'default' => 'date', |
599 | 599 | 'enum' => array( |
@@ -609,15 +609,15 @@ discard block |
||
609 | 609 | |
610 | 610 | // How to order |
611 | 611 | 'order' => array( |
612 | - 'description' => __( 'Order sort attribute ascending or descending.', 'invoicing' ), |
|
612 | + 'description' => __('Order sort attribute ascending or descending.', 'invoicing'), |
|
613 | 613 | 'type' => 'string', |
614 | 614 | 'default' => 'DESC', |
615 | - 'enum' => array( 'ASC', 'DESC' ), |
|
615 | + 'enum' => array('ASC', 'DESC'), |
|
616 | 616 | ), |
617 | 617 | |
618 | 618 | // Search term |
619 | 619 | 'search' => array( |
620 | - 'description' => __( 'Return discounts that match the search term.', 'invoicing' ), |
|
620 | + 'description' => __('Return discounts that match the search term.', 'invoicing'), |
|
621 | 621 | 'type' => 'string', |
622 | 622 | ), |
623 | 623 | ); |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | * |
631 | 631 | * @param array $query_params JSON Schema-formatted collection parameters. |
632 | 632 | */ |
633 | - return apply_filters( "wpinv_rest_discounts_collection_params", $query_params ); |
|
633 | + return apply_filters("wpinv_rest_discounts_collection_params", $query_params); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | * @param object|string $post_type Post type name or object. |
642 | 642 | * @return bool Whether the post type is allowed in REST. |
643 | 643 | */ |
644 | - protected function check_is_post_type_allowed( $post_type ) { |
|
644 | + protected function check_is_post_type_allowed($post_type) { |
|
645 | 645 | return true; |
646 | 646 | } |
647 | 647 | |
@@ -653,93 +653,93 @@ discard block |
||
653 | 653 | * @param WP_REST_Request $request Request object. |
654 | 654 | * @return array|WP_Error Discount Properties or WP_Error. |
655 | 655 | */ |
656 | - protected function prepare_item_for_database( $request ) { |
|
657 | - $prepared_item = new stdClass(); |
|
656 | + protected function prepare_item_for_database($request) { |
|
657 | + $prepared_item = new stdClass(); |
|
658 | 658 | $prepared_item->meta_input = array(); |
659 | 659 | |
660 | 660 | // Post ID. |
661 | - if ( isset( $request['id'] ) ) { |
|
662 | - $existing_item = $this->get_post( $request['id'] ); |
|
663 | - if ( is_wp_error( $existing_item ) ) { |
|
661 | + if (isset($request['id'])) { |
|
662 | + $existing_item = $this->get_post($request['id']); |
|
663 | + if (is_wp_error($existing_item)) { |
|
664 | 664 | return $existing_item; |
665 | 665 | } |
666 | 666 | |
667 | - $prepared_item->ID = $existing_item->ID; |
|
667 | + $prepared_item->ID = $existing_item->ID; |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | $schema = $this->get_item_schema(); |
671 | 671 | |
672 | 672 | // item title. |
673 | - if ( ! empty( $schema['properties']['title'] ) && isset( $request['title'] ) ) { |
|
674 | - $prepared_item->post_title = sanitize_text_field( $request['title'] ); |
|
673 | + if (!empty($schema['properties']['title']) && isset($request['title'])) { |
|
674 | + $prepared_item->post_title = sanitize_text_field($request['title']); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | // item status. |
678 | - if ( ! empty( $schema['properties']['status'] ) && isset( $request['status'] ) && in_array( $request['status'], array_keys( get_post_stati( array( 'internal' => false ) ) ) ) ) { |
|
679 | - $prepared_item->post_status = sanitize_text_field( $request['status'] ); |
|
678 | + if (!empty($schema['properties']['status']) && isset($request['status']) && in_array($request['status'], array_keys(get_post_stati(array('internal' => false))))) { |
|
679 | + $prepared_item->post_status = sanitize_text_field($request['status']); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | // Code. |
683 | - if ( ! empty( $schema['properties']['code'] ) && isset( $request['code'] ) ) { |
|
684 | - $prepared_item->meta_input['_wpi_discount_code'] = trim( $request['code'] ); |
|
683 | + if (!empty($schema['properties']['code']) && isset($request['code'])) { |
|
684 | + $prepared_item->meta_input['_wpi_discount_code'] = trim($request['code']); |
|
685 | 685 | } |
686 | 686 | |
687 | 687 | // Type. |
688 | - if ( ! empty( $schema['properties']['type'] ) && isset( $request['type'] ) && in_array( $request['type'], array_keys( wpinv_get_discount_types() ) ) ) { |
|
689 | - $prepared_item->meta_input['_wpi_discount_type'] = trim( $request['type'] ); |
|
688 | + if (!empty($schema['properties']['type']) && isset($request['type']) && in_array($request['type'], array_keys(wpinv_get_discount_types()))) { |
|
689 | + $prepared_item->meta_input['_wpi_discount_type'] = trim($request['type']); |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | // Amount. |
693 | - if ( ! empty( $schema['properties']['amount'] ) && isset( $request['amount'] ) ) { |
|
694 | - $prepared_item->meta_input['_wpi_discount_amount'] = floatval( $request['amount'] ); |
|
693 | + if (!empty($schema['properties']['amount']) && isset($request['amount'])) { |
|
694 | + $prepared_item->meta_input['_wpi_discount_amount'] = floatval($request['amount']); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | // Items. |
698 | - if ( ! empty( $schema['properties']['items'] ) && isset( $request['items'] ) ) { |
|
699 | - $prepared_item->meta_input['_wpi_discount_items'] = wpinv_parse_list( $request['items'] ); |
|
698 | + if (!empty($schema['properties']['items']) && isset($request['items'])) { |
|
699 | + $prepared_item->meta_input['_wpi_discount_items'] = wpinv_parse_list($request['items']); |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | // Excluded Items. |
703 | - if ( ! empty( $schema['properties']['exclude_items'] ) && isset( $request['exclude_items'] ) ) { |
|
704 | - $prepared_item->meta_input['_wpi_discount_excluded_items'] = wpinv_parse_list( $request['exclude_items'] ); |
|
703 | + if (!empty($schema['properties']['exclude_items']) && isset($request['exclude_items'])) { |
|
704 | + $prepared_item->meta_input['_wpi_discount_excluded_items'] = wpinv_parse_list($request['exclude_items']); |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | // Start date. |
708 | - if ( ! empty( $schema['properties']['start_date'] ) && isset( $request['start_date'] ) ) { |
|
709 | - $prepared_item->meta_input['_wpi_discount_start'] = trim( $request['start_date'] ); |
|
708 | + if (!empty($schema['properties']['start_date']) && isset($request['start_date'])) { |
|
709 | + $prepared_item->meta_input['_wpi_discount_start'] = trim($request['start_date']); |
|
710 | 710 | } |
711 | 711 | |
712 | 712 | // End date. |
713 | - if ( ! empty( $schema['properties']['end_date'] ) && isset( $request['end_date'] ) ) { |
|
714 | - $prepared_item->meta_input['_wpi_discount_expiration'] = trim( $request['end_date'] ); |
|
713 | + if (!empty($schema['properties']['end_date']) && isset($request['end_date'])) { |
|
714 | + $prepared_item->meta_input['_wpi_discount_expiration'] = trim($request['end_date']); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | // Minimum amount. |
718 | - if ( ! empty( $schema['properties']['minimum_amount'] ) && isset( $request['minimum_amount'] ) ) { |
|
719 | - $prepared_item->meta_input['_wpi_discount_min_total'] = floatval( $request['minimum_amount'] ); |
|
718 | + if (!empty($schema['properties']['minimum_amount']) && isset($request['minimum_amount'])) { |
|
719 | + $prepared_item->meta_input['_wpi_discount_min_total'] = floatval($request['minimum_amount']); |
|
720 | 720 | } |
721 | 721 | |
722 | 722 | // Maximum amount. |
723 | - if ( ! empty( $schema['properties']['maximum_amount'] ) && isset( $request['maximum_amount'] ) ) { |
|
724 | - $prepared_item->meta_input['_wpi_discount_max_total'] = floatval( $request['maximum_amount'] ); |
|
723 | + if (!empty($schema['properties']['maximum_amount']) && isset($request['maximum_amount'])) { |
|
724 | + $prepared_item->meta_input['_wpi_discount_max_total'] = floatval($request['maximum_amount']); |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | // Recurring. |
728 | - if ( ! empty( $schema['properties']['recurring'] ) && isset( $request['recurring'] ) ) { |
|
729 | - $prepared_item->meta_input['_wpi_discount_is_recurring'] = empty( (int) $request['recurring'] ) ? 0 : 1; |
|
728 | + if (!empty($schema['properties']['recurring']) && isset($request['recurring'])) { |
|
729 | + $prepared_item->meta_input['_wpi_discount_is_recurring'] = empty((int) $request['recurring']) ? 0 : 1; |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | // Maximum uses. |
733 | - if ( ! empty( $schema['properties']['max_uses'] ) && isset( $request['max_uses'] ) ) { |
|
734 | - $prepared_item->meta_input['_wpi_discount_max_uses'] = intval( $request['max_uses'] ); |
|
733 | + if (!empty($schema['properties']['max_uses']) && isset($request['max_uses'])) { |
|
734 | + $prepared_item->meta_input['_wpi_discount_max_uses'] = intval($request['max_uses']); |
|
735 | 735 | } |
736 | 736 | |
737 | 737 | // Single use. |
738 | - if ( ! empty( $schema['properties']['single_use'] ) && isset( $request['single_use'] ) ) { |
|
739 | - $prepared_item->meta_input['_wpi_discount_is_single_use'] = empty( (int) $request['single_use'] ) ? 0 : 1; |
|
738 | + if (!empty($schema['properties']['single_use']) && isset($request['single_use'])) { |
|
739 | + $prepared_item->meta_input['_wpi_discount_is_single_use'] = empty((int) $request['single_use']) ? 0 : 1; |
|
740 | 740 | } |
741 | 741 | |
742 | - $discount_data = (array) wp_unslash( $prepared_item ); |
|
742 | + $discount_data = (array) wp_unslash($prepared_item); |
|
743 | 743 | |
744 | 744 | /** |
745 | 745 | * Filters an item before it is inserted via the REST API. |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | * @param array $discount_data An array of discount data |
750 | 750 | * @param WP_REST_Request $request Request object. |
751 | 751 | */ |
752 | - return apply_filters( "wpinv_rest_pre_insert_discount", $discount_data, $request ); |
|
752 | + return apply_filters("wpinv_rest_pre_insert_discount", $discount_data, $request); |
|
753 | 753 | |
754 | 754 | } |
755 | 755 | |
@@ -762,110 +762,110 @@ discard block |
||
762 | 762 | * @param WP_REST_Request $request Request object. |
763 | 763 | * @return WP_REST_Response Response object. |
764 | 764 | */ |
765 | - public function prepare_item_for_response( $discount, $request ) { |
|
765 | + public function prepare_item_for_response($discount, $request) { |
|
766 | 766 | |
767 | - $GLOBALS['post'] = get_post( $discount->ID ); |
|
767 | + $GLOBALS['post'] = get_post($discount->ID); |
|
768 | 768 | |
769 | - setup_postdata( $discount->ID ); |
|
769 | + setup_postdata($discount->ID); |
|
770 | 770 | |
771 | 771 | // Fetch the fields to include in this response. |
772 | - $fields = $this->get_fields_for_response( $request ); |
|
772 | + $fields = $this->get_fields_for_response($request); |
|
773 | 773 | |
774 | 774 | // Base fields for every discount. |
775 | 775 | $data = array(); |
776 | 776 | |
777 | 777 | // Set up ID. |
778 | - if ( rest_is_field_included( 'id', $fields ) ) { |
|
778 | + if (rest_is_field_included('id', $fields)) { |
|
779 | 779 | $data['id'] = $discount->ID; |
780 | 780 | } |
781 | 781 | |
782 | 782 | // Title. |
783 | - if ( rest_is_field_included( 'title', $fields ) ) { |
|
784 | - $data['title'] = get_the_title( $discount->ID ); |
|
783 | + if (rest_is_field_included('title', $fields)) { |
|
784 | + $data['title'] = get_the_title($discount->ID); |
|
785 | 785 | } |
786 | 786 | |
787 | 787 | // Code. |
788 | - if ( rest_is_field_included( 'code', $fields ) ) { |
|
789 | - $data['code'] = wpinv_get_discount_code( $discount->ID ); |
|
788 | + if (rest_is_field_included('code', $fields)) { |
|
789 | + $data['code'] = wpinv_get_discount_code($discount->ID); |
|
790 | 790 | } |
791 | 791 | |
792 | 792 | // Type. |
793 | - if ( rest_is_field_included( 'type', $fields ) ) { |
|
794 | - $data['type'] = wpinv_get_discount_type( $discount->ID ); |
|
793 | + if (rest_is_field_included('type', $fields)) { |
|
794 | + $data['type'] = wpinv_get_discount_type($discount->ID); |
|
795 | 795 | } |
796 | 796 | |
797 | 797 | // Amount. |
798 | - if ( rest_is_field_included( 'amount', $fields ) ) { |
|
799 | - $data['amount'] = wpinv_get_discount_amount( $discount->ID ); |
|
798 | + if (rest_is_field_included('amount', $fields)) { |
|
799 | + $data['amount'] = wpinv_get_discount_amount($discount->ID); |
|
800 | 800 | } |
801 | 801 | |
802 | 802 | // Status. |
803 | - if ( rest_is_field_included( 'status', $fields ) ) { |
|
804 | - $data['status'] = get_post_status( $discount->ID ); |
|
803 | + if (rest_is_field_included('status', $fields)) { |
|
804 | + $data['status'] = get_post_status($discount->ID); |
|
805 | 805 | } |
806 | 806 | |
807 | 807 | // Items. |
808 | - if ( rest_is_field_included( 'items', $fields ) ) { |
|
809 | - $data['items'] = wpinv_get_discount_item_reqs( $discount->ID ); |
|
808 | + if (rest_is_field_included('items', $fields)) { |
|
809 | + $data['items'] = wpinv_get_discount_item_reqs($discount->ID); |
|
810 | 810 | } |
811 | 811 | |
812 | 812 | // Excluded Items. |
813 | - if ( rest_is_field_included( 'exclude_items', $fields ) ) { |
|
814 | - $data['exclude_items'] = wpinv_get_discount_excluded_items( $discount->ID ); |
|
813 | + if (rest_is_field_included('exclude_items', $fields)) { |
|
814 | + $data['exclude_items'] = wpinv_get_discount_excluded_items($discount->ID); |
|
815 | 815 | } |
816 | 816 | |
817 | 817 | // Start date. |
818 | - if ( rest_is_field_included( 'start_date', $fields ) ) { |
|
819 | - $data['start_date'] = wpinv_get_discount_start_date( $discount->ID ); |
|
818 | + if (rest_is_field_included('start_date', $fields)) { |
|
819 | + $data['start_date'] = wpinv_get_discount_start_date($discount->ID); |
|
820 | 820 | } |
821 | 821 | |
822 | 822 | // End date. |
823 | - if ( rest_is_field_included( 'end_date', $fields ) ) { |
|
824 | - $data['end_date'] = wpinv_get_discount_expiration( $discount->ID ); |
|
823 | + if (rest_is_field_included('end_date', $fields)) { |
|
824 | + $data['end_date'] = wpinv_get_discount_expiration($discount->ID); |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | // Minimum amount. |
828 | - if ( rest_is_field_included( 'minimum_amount', $fields ) ) { |
|
829 | - $data['minimum_amount'] = wpinv_get_discount_min_total( $discount->ID ); |
|
828 | + if (rest_is_field_included('minimum_amount', $fields)) { |
|
829 | + $data['minimum_amount'] = wpinv_get_discount_min_total($discount->ID); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | // Maximum amount. |
833 | - if ( rest_is_field_included( 'maximum_amount', $fields ) ) { |
|
834 | - $data['maximum_amount'] = wpinv_get_discount_max_total( $discount->ID ); |
|
833 | + if (rest_is_field_included('maximum_amount', $fields)) { |
|
834 | + $data['maximum_amount'] = wpinv_get_discount_max_total($discount->ID); |
|
835 | 835 | } |
836 | 836 | |
837 | 837 | // Recurring. |
838 | - if ( rest_is_field_included( 'recurring', $fields ) ) { |
|
839 | - $data['recurring'] = wpinv_discount_is_recurring( $discount->ID ); |
|
838 | + if (rest_is_field_included('recurring', $fields)) { |
|
839 | + $data['recurring'] = wpinv_discount_is_recurring($discount->ID); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | // Maximum uses. |
843 | - if ( rest_is_field_included( 'max_uses', $fields ) ) { |
|
844 | - $data['max_uses'] = wpinv_get_discount_max_uses( $discount->ID ); |
|
843 | + if (rest_is_field_included('max_uses', $fields)) { |
|
844 | + $data['max_uses'] = wpinv_get_discount_max_uses($discount->ID); |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | // Single use. |
848 | - if ( rest_is_field_included( 'single_use', $fields ) ) { |
|
849 | - $data['single_use'] = wpinv_discount_is_single_use( $discount->ID ); |
|
848 | + if (rest_is_field_included('single_use', $fields)) { |
|
849 | + $data['single_use'] = wpinv_discount_is_single_use($discount->ID); |
|
850 | 850 | } |
851 | 851 | |
852 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
853 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
854 | - $data = $this->filter_response_by_context( $data, $context ); |
|
852 | + $context = !empty($request['context']) ? $request['context'] : 'view'; |
|
853 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
854 | + $data = $this->filter_response_by_context($data, $context); |
|
855 | 855 | |
856 | 856 | // Wrap the data in a response object. |
857 | - $response = rest_ensure_response( $data ); |
|
857 | + $response = rest_ensure_response($data); |
|
858 | 858 | |
859 | - $links = $this->prepare_links( $discount ); |
|
860 | - $response->add_links( $links ); |
|
859 | + $links = $this->prepare_links($discount); |
|
860 | + $response->add_links($links); |
|
861 | 861 | |
862 | - if ( ! empty( $links['self']['href'] ) ) { |
|
863 | - $actions = $this->get_available_actions( $discount, $request ); |
|
862 | + if (!empty($links['self']['href'])) { |
|
863 | + $actions = $this->get_available_actions($discount, $request); |
|
864 | 864 | |
865 | 865 | $self = $links['self']['href']; |
866 | 866 | |
867 | - foreach ( $actions as $rel ) { |
|
868 | - $response->add_link( $rel, $self ); |
|
867 | + foreach ($actions as $rel) { |
|
868 | + $response->add_link($rel, $self); |
|
869 | 869 | } |
870 | 870 | } |
871 | 871 | |
@@ -878,7 +878,7 @@ discard block |
||
878 | 878 | * @param WP_Post $discount The discount post object. |
879 | 879 | * @param WP_REST_Request $request Request object. |
880 | 880 | */ |
881 | - return apply_filters( "wpinv_rest_prepare_discount", $response, $discount, $request ); |
|
881 | + return apply_filters("wpinv_rest_prepare_discount", $response, $discount, $request); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | /** |
@@ -891,57 +891,57 @@ discard block |
||
891 | 891 | * @param WP_REST_Request $request Full details about the request. |
892 | 892 | * @return array Fields to be included in the response. |
893 | 893 | */ |
894 | - public function get_fields_for_response( $request ) { |
|
894 | + public function get_fields_for_response($request) { |
|
895 | 895 | $schema = $this->get_item_schema(); |
896 | - $properties = isset( $schema['properties'] ) ? $schema['properties'] : array(); |
|
896 | + $properties = isset($schema['properties']) ? $schema['properties'] : array(); |
|
897 | 897 | |
898 | 898 | $additional_fields = $this->get_additional_fields(); |
899 | - foreach ( $additional_fields as $field_name => $field_options ) { |
|
899 | + foreach ($additional_fields as $field_name => $field_options) { |
|
900 | 900 | // For back-compat, include any field with an empty schema |
901 | 901 | // because it won't be present in $this->get_item_schema(). |
902 | - if ( is_null( $field_options['schema'] ) ) { |
|
903 | - $properties[ $field_name ] = $field_options; |
|
902 | + if (is_null($field_options['schema'])) { |
|
903 | + $properties[$field_name] = $field_options; |
|
904 | 904 | } |
905 | 905 | } |
906 | 906 | |
907 | 907 | // Exclude fields that specify a different context than the request context. |
908 | 908 | $context = $request['context']; |
909 | - if ( $context ) { |
|
910 | - foreach ( $properties as $name => $options ) { |
|
911 | - if ( ! empty( $options['context'] ) && ! in_array( $context, $options['context'], true ) ) { |
|
912 | - unset( $properties[ $name ] ); |
|
909 | + if ($context) { |
|
910 | + foreach ($properties as $name => $options) { |
|
911 | + if (!empty($options['context']) && !in_array($context, $options['context'], true)) { |
|
912 | + unset($properties[$name]); |
|
913 | 913 | } |
914 | 914 | } |
915 | 915 | } |
916 | 916 | |
917 | - $fields = array_keys( $properties ); |
|
917 | + $fields = array_keys($properties); |
|
918 | 918 | |
919 | - if ( ! isset( $request['_fields'] ) ) { |
|
919 | + if (!isset($request['_fields'])) { |
|
920 | 920 | return $fields; |
921 | 921 | } |
922 | - $requested_fields = wpinv_parse_list( $request['_fields'] ); |
|
923 | - if ( 0 === count( $requested_fields ) ) { |
|
922 | + $requested_fields = wpinv_parse_list($request['_fields']); |
|
923 | + if (0 === count($requested_fields)) { |
|
924 | 924 | return $fields; |
925 | 925 | } |
926 | 926 | // Trim off outside whitespace from the comma delimited list. |
927 | - $requested_fields = array_map( 'trim', $requested_fields ); |
|
927 | + $requested_fields = array_map('trim', $requested_fields); |
|
928 | 928 | // Always persist 'id', because it can be needed for add_additional_fields_to_object(). |
929 | - if ( in_array( 'id', $fields, true ) ) { |
|
929 | + if (in_array('id', $fields, true)) { |
|
930 | 930 | $requested_fields[] = 'id'; |
931 | 931 | } |
932 | 932 | // Return the list of all requested fields which appear in the schema. |
933 | 933 | return array_reduce( |
934 | 934 | $requested_fields, |
935 | - function( $response_fields, $field ) use ( $fields ) { |
|
936 | - if ( in_array( $field, $fields, true ) ) { |
|
935 | + function($response_fields, $field) use ($fields) { |
|
936 | + if (in_array($field, $fields, true)) { |
|
937 | 937 | $response_fields[] = $field; |
938 | 938 | return $response_fields; |
939 | 939 | } |
940 | 940 | // Check for nested fields if $field is not a direct match. |
941 | - $nested_fields = explode( '.', $field ); |
|
941 | + $nested_fields = explode('.', $field); |
|
942 | 942 | // A nested field is included so long as its top-level property is |
943 | 943 | // present in the schema. |
944 | - if ( in_array( $nested_fields[0], $fields, true ) ) { |
|
944 | + if (in_array($nested_fields[0], $fields, true)) { |
|
945 | 945 | $response_fields[] = $field; |
946 | 946 | } |
947 | 947 | return $response_fields; |
@@ -960,8 +960,8 @@ discard block |
||
960 | 960 | public function get_item_schema() { |
961 | 961 | |
962 | 962 | // Maybe retrieve the schema from cache. |
963 | - if ( empty( $this->schema ) ) { |
|
964 | - return $this->add_additional_fields_schema( $this->schema ); |
|
963 | + if (empty($this->schema)) { |
|
964 | + return $this->add_additional_fields_schema($this->schema); |
|
965 | 965 | } |
966 | 966 | |
967 | 967 | $schema = array( |
@@ -973,99 +973,99 @@ discard block |
||
973 | 973 | 'properties' => array( |
974 | 974 | |
975 | 975 | 'id' => array( |
976 | - 'description' => __( 'Unique identifier for the discount.', 'invoicing' ), |
|
976 | + 'description' => __('Unique identifier for the discount.', 'invoicing'), |
|
977 | 977 | 'type' => 'integer', |
978 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
978 | + 'context' => array('view', 'edit', 'embed'), |
|
979 | 979 | 'readonly' => true, |
980 | 980 | ), |
981 | 981 | |
982 | 982 | 'title' => array( |
983 | - 'description' => __( 'The title for the discount.', 'invoicing' ), |
|
983 | + 'description' => __('The title for the discount.', 'invoicing'), |
|
984 | 984 | 'type' => 'string', |
985 | - 'context' => array( 'view', 'edit' ), |
|
985 | + 'context' => array('view', 'edit'), |
|
986 | 986 | ), |
987 | 987 | |
988 | 988 | 'code' => array( |
989 | - 'description' => __( 'The discount code.', 'invoicing' ), |
|
989 | + 'description' => __('The discount code.', 'invoicing'), |
|
990 | 990 | 'type' => 'string', |
991 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
991 | + 'context' => array('view', 'edit', 'embed'), |
|
992 | 992 | 'required' => true, |
993 | 993 | ), |
994 | 994 | |
995 | 995 | 'type' => array( |
996 | - 'description' => __( 'The type of discount.', 'invoicing' ), |
|
996 | + 'description' => __('The type of discount.', 'invoicing'), |
|
997 | 997 | 'type' => 'string', |
998 | - 'enum' => array_keys( wpinv_get_discount_types() ), |
|
999 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
998 | + 'enum' => array_keys(wpinv_get_discount_types()), |
|
999 | + 'context' => array('view', 'edit', 'embed'), |
|
1000 | 1000 | 'default' => 'percentage', |
1001 | 1001 | ), |
1002 | 1002 | |
1003 | 1003 | 'amount' => array( |
1004 | - 'description' => __( 'The discount value.', 'invoicing' ), |
|
1004 | + 'description' => __('The discount value.', 'invoicing'), |
|
1005 | 1005 | 'type' => 'number', |
1006 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1006 | + 'context' => array('view', 'edit', 'embed'), |
|
1007 | 1007 | 'required' => true, |
1008 | 1008 | ), |
1009 | 1009 | |
1010 | 1010 | 'status' => array( |
1011 | - 'description' => __( 'A named status for the discount.', 'invoicing' ), |
|
1011 | + 'description' => __('A named status for the discount.', 'invoicing'), |
|
1012 | 1012 | 'type' => 'string', |
1013 | - 'enum' => array_keys( get_post_stati( array( 'internal' => false ) ) ), |
|
1014 | - 'context' => array( 'view', 'edit' ), |
|
1013 | + 'enum' => array_keys(get_post_stati(array('internal' => false))), |
|
1014 | + 'context' => array('view', 'edit'), |
|
1015 | 1015 | ), |
1016 | 1016 | |
1017 | 1017 | 'items' => array( |
1018 | - 'description' => __( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount will be used on any item.', 'invoicing' ), |
|
1018 | + 'description' => __('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount will be used on any item.', 'invoicing'), |
|
1019 | 1019 | 'type' => 'array', |
1020 | - 'context' => array( 'view', 'edit' ), |
|
1020 | + 'context' => array('view', 'edit'), |
|
1021 | 1021 | ), |
1022 | 1022 | |
1023 | 1023 | 'exclude_items' => array( |
1024 | - 'description' => __( 'Items which are NOT allowed to use this discount.', 'invoicing' ), |
|
1024 | + 'description' => __('Items which are NOT allowed to use this discount.', 'invoicing'), |
|
1025 | 1025 | 'type' => 'array', |
1026 | - 'context' => array( 'view', 'edit' ), |
|
1026 | + 'context' => array('view', 'edit'), |
|
1027 | 1027 | ), |
1028 | 1028 | |
1029 | 1029 | 'start_date' => array( |
1030 | - 'description' => __( 'The start date for the discount in the format of yyyy-mm-dd hh:mm:ss . If provided, the discount can only be used after or on this date.', 'invoicing' ), |
|
1030 | + 'description' => __('The start date for the discount in the format of yyyy-mm-dd hh:mm:ss . If provided, the discount can only be used after or on this date.', 'invoicing'), |
|
1031 | 1031 | 'type' => 'string', |
1032 | - 'context' => array( 'view', 'edit' ), |
|
1032 | + 'context' => array('view', 'edit'), |
|
1033 | 1033 | ), |
1034 | 1034 | |
1035 | 1035 | 'end_date' => array( |
1036 | - 'description' => __( 'The expiration date for the discount.', 'invoicing' ), |
|
1036 | + 'description' => __('The expiration date for the discount.', 'invoicing'), |
|
1037 | 1037 | 'type' => 'string', |
1038 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1038 | + 'context' => array('view', 'edit', 'embed'), |
|
1039 | 1039 | ), |
1040 | 1040 | |
1041 | 1041 | 'minimum_amount' => array( |
1042 | - 'description' => __( 'Minimum amount needed to use this invoice.', 'invoicing' ), |
|
1042 | + 'description' => __('Minimum amount needed to use this invoice.', 'invoicing'), |
|
1043 | 1043 | 'type' => 'number', |
1044 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1044 | + 'context' => array('view', 'edit', 'embed'), |
|
1045 | 1045 | ), |
1046 | 1046 | |
1047 | 1047 | 'maximum_amount' => array( |
1048 | - 'description' => __( 'Maximum amount needed to use this invoice.', 'invoicing' ), |
|
1048 | + 'description' => __('Maximum amount needed to use this invoice.', 'invoicing'), |
|
1049 | 1049 | 'type' => 'number', |
1050 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1050 | + 'context' => array('view', 'edit', 'embed'), |
|
1051 | 1051 | ), |
1052 | 1052 | |
1053 | 1053 | 'recurring' => array( |
1054 | - 'description' => __( 'Whether the discount is applied to all recurring payments or only the first recurring payment.', 'invoicing' ), |
|
1054 | + 'description' => __('Whether the discount is applied to all recurring payments or only the first recurring payment.', 'invoicing'), |
|
1055 | 1055 | 'type' => 'integer', |
1056 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1056 | + 'context' => array('view', 'edit', 'embed'), |
|
1057 | 1057 | ), |
1058 | 1058 | |
1059 | 1059 | 'max_uses' => array( |
1060 | - 'description' => __( 'The maximum number of times this discount code can be used.', 'invoicing' ), |
|
1060 | + 'description' => __('The maximum number of times this discount code can be used.', 'invoicing'), |
|
1061 | 1061 | 'type' => 'number', |
1062 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1062 | + 'context' => array('view', 'edit', 'embed'), |
|
1063 | 1063 | ), |
1064 | 1064 | |
1065 | 1065 | 'single_use' => array( |
1066 | - 'description' => __( 'Whether or not this discount can only be used once per user.', 'invoicing' ), |
|
1066 | + 'description' => __('Whether or not this discount can only be used once per user.', 'invoicing'), |
|
1067 | 1067 | 'type' => 'integer', |
1068 | - 'context' => array( 'view', 'edit', 'embed' ), |
|
1068 | + 'context' => array('view', 'edit', 'embed'), |
|
1069 | 1069 | ) |
1070 | 1070 | |
1071 | 1071 | ), |
@@ -1083,12 +1083,12 @@ discard block |
||
1083 | 1083 | * |
1084 | 1084 | * @param array $schema The discount schema. |
1085 | 1085 | */ |
1086 | - $schema = apply_filters( "wpinv_rest_discount_schema", $schema ); |
|
1086 | + $schema = apply_filters("wpinv_rest_discount_schema", $schema); |
|
1087 | 1087 | |
1088 | 1088 | // Cache the discount schema. |
1089 | 1089 | $this->schema = $schema; |
1090 | 1090 | |
1091 | - return $this->add_additional_fields_schema( $this->schema ); |
|
1091 | + return $this->add_additional_fields_schema($this->schema); |
|
1092 | 1092 | } |
1093 | 1093 | |
1094 | 1094 | /** |
@@ -1100,20 +1100,20 @@ discard block |
||
1100 | 1100 | */ |
1101 | 1101 | protected function get_schema_links() { |
1102 | 1102 | |
1103 | - $href = rest_url( "{$this->namespace}/{$this->rest_base}/{id}" ); |
|
1103 | + $href = rest_url("{$this->namespace}/{$this->rest_base}/{id}"); |
|
1104 | 1104 | |
1105 | 1105 | $links = array(); |
1106 | 1106 | |
1107 | 1107 | $links[] = array( |
1108 | 1108 | 'rel' => 'https://api.w.org/action-publish', |
1109 | - 'title' => __( 'The current user can publish this discount.', 'invoicing' ), |
|
1109 | + 'title' => __('The current user can publish this discount.', 'invoicing'), |
|
1110 | 1110 | 'href' => $href, |
1111 | 1111 | 'targetSchema' => array( |
1112 | 1112 | 'type' => 'object', |
1113 | 1113 | 'properties' => array( |
1114 | 1114 | 'status' => array( |
1115 | 1115 | 'type' => 'string', |
1116 | - 'enum' => array( 'publish', 'future' ), |
|
1116 | + 'enum' => array('publish', 'future'), |
|
1117 | 1117 | ), |
1118 | 1118 | ), |
1119 | 1119 | ), |
@@ -1130,18 +1130,18 @@ discard block |
||
1130 | 1130 | * @param WP_Post $discount Post Object. |
1131 | 1131 | * @return array Links for the given discount. |
1132 | 1132 | */ |
1133 | - protected function prepare_links( $discount ) { |
|
1133 | + protected function prepare_links($discount) { |
|
1134 | 1134 | |
1135 | 1135 | // Prepare the base REST API endpoint for discounts. |
1136 | - $base = sprintf( '%s/%s', $this->namespace, $this->rest_base ); |
|
1136 | + $base = sprintf('%s/%s', $this->namespace, $this->rest_base); |
|
1137 | 1137 | |
1138 | 1138 | // Entity meta. |
1139 | 1139 | $links = array( |
1140 | 1140 | 'self' => array( |
1141 | - 'href' => rest_url( trailingslashit( $base ) . $discount->ID ), |
|
1141 | + 'href' => rest_url(trailingslashit($base) . $discount->ID), |
|
1142 | 1142 | ), |
1143 | 1143 | 'collection' => array( |
1144 | - 'href' => rest_url( $base ), |
|
1144 | + 'href' => rest_url($base), |
|
1145 | 1145 | ), |
1146 | 1146 | ); |
1147 | 1147 | |
@@ -1154,7 +1154,7 @@ discard block |
||
1154 | 1154 | * |
1155 | 1155 | * @param array $links Rest links. |
1156 | 1156 | */ |
1157 | - return apply_filters( "wpinv_rest_discount_links", $links ); |
|
1157 | + return apply_filters("wpinv_rest_discount_links", $links); |
|
1158 | 1158 | |
1159 | 1159 | } |
1160 | 1160 | |
@@ -1167,19 +1167,19 @@ discard block |
||
1167 | 1167 | * @param WP_REST_Request $request Request object. |
1168 | 1168 | * @return array List of link relations. |
1169 | 1169 | */ |
1170 | - protected function get_available_actions( $discount, $request ) { |
|
1170 | + protected function get_available_actions($discount, $request) { |
|
1171 | 1171 | |
1172 | - if ( 'edit' !== $request['context'] ) { |
|
1172 | + if ('edit' !== $request['context']) { |
|
1173 | 1173 | return array(); |
1174 | 1174 | } |
1175 | 1175 | |
1176 | 1176 | $rels = array(); |
1177 | 1177 | |
1178 | 1178 | // Retrieve the post type object. |
1179 | - $post_type = get_post_type_object( $discount->post_type ); |
|
1179 | + $post_type = get_post_type_object($discount->post_type); |
|
1180 | 1180 | |
1181 | 1181 | // Mark discount as published. |
1182 | - if ( current_user_can( $post_type->cap->publish_posts ) ) { |
|
1182 | + if (current_user_can($post_type->cap->publish_posts)) { |
|
1183 | 1183 | $rels[] = 'https://api.w.org/action-publish'; |
1184 | 1184 | } |
1185 | 1185 | |
@@ -1192,7 +1192,7 @@ discard block |
||
1192 | 1192 | * |
1193 | 1193 | * @param array $rels Available link relations. |
1194 | 1194 | */ |
1195 | - return apply_filters( "wpinv_rest_discount_link_relations", $rels ); |
|
1195 | + return apply_filters("wpinv_rest_discount_link_relations", $rels); |
|
1196 | 1196 | } |
1197 | 1197 | |
1198 | 1198 | /** |
@@ -1204,7 +1204,7 @@ discard block |
||
1204 | 1204 | * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. |
1205 | 1205 | */ |
1206 | 1206 | public function get_discount_types() { |
1207 | - return rest_ensure_response( wpinv_get_discount_types() ); |
|
1207 | + return rest_ensure_response(wpinv_get_discount_types()); |
|
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | } |
1211 | 1211 | \ No newline at end of file |