@@ -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 | - @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + @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 | - @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - @header( 'X-Robots-Tag: noindex' ); |
|
53 | + @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + @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() { |
@@ -76,39 +76,39 @@ discard block |
||
76 | 76 | 'remove_discount' => false, |
77 | 77 | ); |
78 | 78 | |
79 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
80 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
79 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
80 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
81 | 81 | |
82 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
83 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
82 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
83 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
84 | 84 | } |
85 | 85 | |
86 | - if ( $nopriv ) { |
|
87 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
86 | + if ($nopriv) { |
|
87 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
88 | 88 | |
89 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
89 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | 94 | public static function add_note() { |
95 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
95 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
96 | 96 | |
97 | - if ( !current_user_can( 'manage_options' ) ) { |
|
97 | + if (!current_user_can('manage_options')) { |
|
98 | 98 | die(-1); |
99 | 99 | } |
100 | 100 | |
101 | - $post_id = absint( $_POST['post_id'] ); |
|
102 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
103 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
101 | + $post_id = absint($_POST['post_id']); |
|
102 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
103 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
104 | 104 | |
105 | 105 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
106 | 106 | |
107 | - if ( $post_id > 0 ) { |
|
108 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
107 | + if ($post_id > 0) { |
|
108 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
109 | 109 | |
110 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
111 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
110 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
111 | + wpinv_get_invoice_note_line_item($note_id); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
@@ -116,16 +116,16 @@ discard block |
||
116 | 116 | } |
117 | 117 | |
118 | 118 | public static function delete_note() { |
119 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
119 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
120 | 120 | |
121 | - if ( !current_user_can( 'manage_options' ) ) { |
|
121 | + if (!current_user_can('manage_options')) { |
|
122 | 122 | die(-1); |
123 | 123 | } |
124 | 124 | |
125 | 125 | $note_id = (int)$_POST['note_id']; |
126 | 126 | |
127 | - if ( $note_id > 0 ) { |
|
128 | - wp_delete_comment( $note_id, true ); |
|
127 | + if ($note_id > 0) { |
|
128 | + wp_delete_comment($note_id, true); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | die(); |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | public static function checkout() { |
141 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
142 | - define( 'WPINV_CHECKOUT', true ); |
|
141 | + if (!defined('WPINV_CHECKOUT')) { |
|
142 | + define('WPINV_CHECKOUT', true); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | wpinv_process_checkout(); |
@@ -148,53 +148,53 @@ discard block |
||
148 | 148 | |
149 | 149 | public static function add_invoice_item() { |
150 | 150 | global $wpi_userID, $wpinv_ip_address_country; |
151 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
152 | - if ( !current_user_can( 'manage_options' ) ) { |
|
151 | + check_ajax_referer('invoice-item', '_nonce'); |
|
152 | + if (!current_user_can('manage_options')) { |
|
153 | 153 | die(-1); |
154 | 154 | } |
155 | 155 | |
156 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
157 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
156 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
157 | + $invoice_id = absint($_POST['invoice_id']); |
|
158 | 158 | |
159 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
159 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
160 | 160 | die(); |
161 | 161 | } |
162 | 162 | |
163 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
164 | - if ( empty( $invoice ) ) { |
|
163 | + $invoice = wpinv_get_invoice($invoice_id); |
|
164 | + if (empty($invoice)) { |
|
165 | 165 | die(); |
166 | 166 | } |
167 | 167 | |
168 | - if ( $invoice->is_paid() ) { |
|
168 | + if ($invoice->is_paid()) { |
|
169 | 169 | die(); // Don't allow modify items for paid invoice. |
170 | 170 | } |
171 | 171 | |
172 | - if ( !empty( $_POST['user_id'] ) ) { |
|
173 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
172 | + if (!empty($_POST['user_id'])) { |
|
173 | + $wpi_userID = absint($_POST['user_id']); |
|
174 | 174 | } |
175 | 175 | |
176 | - $item = new WPInv_Item( $item_id ); |
|
177 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
176 | + $item = new WPInv_Item($item_id); |
|
177 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
178 | 178 | die(); |
179 | 179 | } |
180 | 180 | |
181 | 181 | // Validate item before adding to invoice because recurring item must be paid individually. |
182 | - if ( !empty( $invoice->cart_details ) ) { |
|
182 | + if (!empty($invoice->cart_details)) { |
|
183 | 183 | $valid = true; |
184 | 184 | |
185 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
186 | - if ( $recurring_item != $item_id ) { |
|
185 | + if ($recurring_item = $invoice->get_recurring()) { |
|
186 | + if ($recurring_item != $item_id) { |
|
187 | 187 | $valid = false; |
188 | 188 | } |
189 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
189 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
190 | 190 | $valid = false; |
191 | 191 | } |
192 | 192 | |
193 | - if ( !$valid ) { |
|
193 | + if (!$valid) { |
|
194 | 194 | $response = array(); |
195 | 195 | $response['success'] = false; |
196 | - $response['msg'] = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ); |
|
197 | - wp_send_json( $response ); |
|
196 | + $response['msg'] = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'); |
|
197 | + wp_send_json($response); |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | |
203 | 203 | $data = array(); |
204 | 204 | $data['invoice_id'] = $invoice_id; |
205 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
205 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
206 | 206 | |
207 | - wpinv_set_checkout_session( $data ); |
|
207 | + wpinv_set_checkout_session($data); |
|
208 | 208 | |
209 | 209 | $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
210 | 210 | |
@@ -218,21 +218,21 @@ discard block |
||
218 | 218 | 'fees' => array() |
219 | 219 | ); |
220 | 220 | |
221 | - $invoice->add_item( $item_id, $args ); |
|
221 | + $invoice->add_item($item_id, $args); |
|
222 | 222 | $invoice->save(); |
223 | 223 | |
224 | - if ( empty( $_POST['country'] ) ) { |
|
224 | + if (empty($_POST['country'])) { |
|
225 | 225 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
226 | 226 | } |
227 | - if ( empty( $_POST['state'] ) ) { |
|
227 | + if (empty($_POST['state'])) { |
|
228 | 228 | $_POST['state'] = $invoice->state; |
229 | 229 | } |
230 | 230 | |
231 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
232 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
231 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
232 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
233 | 233 | |
234 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
235 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
234 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
235 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
236 | 236 | |
237 | 237 | $wpinv_ip_address_country = $invoice->country; |
238 | 238 | |
@@ -240,52 +240,52 @@ discard block |
||
240 | 240 | |
241 | 241 | $response = array(); |
242 | 242 | $response['success'] = true; |
243 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
243 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
244 | 244 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
245 | 245 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
246 | 246 | $response['data']['tax'] = $invoice->get_tax(); |
247 | 247 | $response['data']['taxf'] = $invoice->get_tax(true); |
248 | 248 | $response['data']['discount'] = $invoice->discount; |
249 | - $response['data']['discountf'] = wpinv_price( $invoice->discount, $invoice->get_currency() ); |
|
249 | + $response['data']['discountf'] = wpinv_price($invoice->discount, $invoice->get_currency()); |
|
250 | 250 | $response['data']['total'] = $invoice->get_total(); |
251 | 251 | $response['data']['totalf'] = $invoice->get_total(true); |
252 | 252 | |
253 | 253 | wpinv_set_checkout_session($checkout_session); |
254 | 254 | |
255 | - wp_send_json( $response ); |
|
255 | + wp_send_json($response); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | public static function remove_invoice_item() { |
259 | 259 | global $wpi_userID, $wpinv_ip_address_country; |
260 | 260 | |
261 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
262 | - if ( !current_user_can( 'manage_options' ) ) { |
|
261 | + check_ajax_referer('invoice-item', '_nonce'); |
|
262 | + if (!current_user_can('manage_options')) { |
|
263 | 263 | die(-1); |
264 | 264 | } |
265 | 265 | |
266 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
267 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
268 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
266 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
267 | + $invoice_id = absint($_POST['invoice_id']); |
|
268 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
269 | 269 | |
270 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
270 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
271 | 271 | die(); |
272 | 272 | } |
273 | 273 | |
274 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
275 | - if ( empty( $invoice ) ) { |
|
274 | + $invoice = wpinv_get_invoice($invoice_id); |
|
275 | + if (empty($invoice)) { |
|
276 | 276 | die(); |
277 | 277 | } |
278 | 278 | |
279 | - if ( $invoice->is_paid() ) { |
|
279 | + if ($invoice->is_paid()) { |
|
280 | 280 | die(); // Don't allow modify items for paid invoice. |
281 | 281 | } |
282 | 282 | |
283 | - if ( !empty( $_POST['user_id'] ) ) { |
|
284 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
283 | + if (!empty($_POST['user_id'])) { |
|
284 | + $wpi_userID = absint($_POST['user_id']); |
|
285 | 285 | } |
286 | 286 | |
287 | - $item = new WPInv_Item( $item_id ); |
|
288 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
287 | + $item = new WPInv_Item($item_id); |
|
288 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
289 | 289 | die(); |
290 | 290 | } |
291 | 291 | |
@@ -293,9 +293,9 @@ discard block |
||
293 | 293 | |
294 | 294 | $data = array(); |
295 | 295 | $data['invoice_id'] = $invoice_id; |
296 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
296 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
297 | 297 | |
298 | - wpinv_set_checkout_session( $data ); |
|
298 | + wpinv_set_checkout_session($data); |
|
299 | 299 | |
300 | 300 | $args = array( |
301 | 301 | 'id' => $item_id, |
@@ -303,21 +303,21 @@ discard block |
||
303 | 303 | 'cart_index' => $cart_index |
304 | 304 | ); |
305 | 305 | |
306 | - $invoice->remove_item( $item_id, $args ); |
|
306 | + $invoice->remove_item($item_id, $args); |
|
307 | 307 | $invoice->save(); |
308 | 308 | |
309 | - if ( empty( $_POST['country'] ) ) { |
|
309 | + if (empty($_POST['country'])) { |
|
310 | 310 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
311 | 311 | } |
312 | - if ( empty( $_POST['state'] ) ) { |
|
312 | + if (empty($_POST['state'])) { |
|
313 | 313 | $_POST['state'] = $invoice->state; |
314 | 314 | } |
315 | 315 | |
316 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
317 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
316 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
317 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
318 | 318 | |
319 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
320 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
319 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
320 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
321 | 321 | |
322 | 322 | $wpinv_ip_address_country = $invoice->country; |
323 | 323 | |
@@ -325,52 +325,52 @@ discard block |
||
325 | 325 | |
326 | 326 | $response = array(); |
327 | 327 | $response['success'] = true; |
328 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
328 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
329 | 329 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
330 | 330 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
331 | 331 | $response['data']['tax'] = $invoice->get_tax(); |
332 | 332 | $response['data']['taxf'] = $invoice->get_tax(true); |
333 | 333 | $response['data']['discount'] = $invoice->discount; |
334 | - $response['data']['discountf'] = wpinv_price( $invoice->discount, $invoice->get_currency() ); |
|
334 | + $response['data']['discountf'] = wpinv_price($invoice->discount, $invoice->get_currency()); |
|
335 | 335 | $response['data']['total'] = $invoice->get_total(); |
336 | 336 | $response['data']['totalf'] = $invoice->get_total(true); |
337 | 337 | |
338 | 338 | wpinv_set_checkout_session($checkout_session); |
339 | 339 | |
340 | - wp_send_json( $response ); |
|
340 | + wp_send_json($response); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | public static function create_invoice_item() { |
344 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
345 | - if ( !current_user_can( 'manage_options' ) ) { |
|
344 | + check_ajax_referer('invoice-item', '_nonce'); |
|
345 | + if (!current_user_can('manage_options')) { |
|
346 | 346 | die(-1); |
347 | 347 | } |
348 | 348 | |
349 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
349 | + $invoice_id = absint($_POST['invoice_id']); |
|
350 | 350 | |
351 | 351 | // Find the item |
352 | - if ( !is_numeric( $invoice_id ) ) { |
|
352 | + if (!is_numeric($invoice_id)) { |
|
353 | 353 | die(); |
354 | 354 | } |
355 | 355 | |
356 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
357 | - if ( empty( $invoice ) ) { |
|
356 | + $invoice = wpinv_get_invoice($invoice_id); |
|
357 | + if (empty($invoice)) { |
|
358 | 358 | die(); |
359 | 359 | } |
360 | 360 | |
361 | 361 | // Validate item before adding to invoice because recurring item must be paid individually. |
362 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
362 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
363 | 363 | $response = array(); |
364 | 364 | $response['success'] = false; |
365 | - $response['msg'] = __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ); |
|
366 | - wp_send_json( $response ); |
|
365 | + $response['msg'] = __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'); |
|
366 | + wp_send_json($response); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | $save_item = $_POST['_wpinv_quick']; |
370 | 370 | |
371 | 371 | $meta = array(); |
372 | 372 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
373 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
373 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
374 | 374 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
375 | 375 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
376 | 376 | |
@@ -380,9 +380,9 @@ discard block |
||
380 | 380 | $data['meta'] = $meta; |
381 | 381 | |
382 | 382 | $item = new WPInv_Item(); |
383 | - $item->create( $data ); |
|
383 | + $item->create($data); |
|
384 | 384 | |
385 | - if ( !empty( $item ) ) { |
|
385 | + if (!empty($item)) { |
|
386 | 386 | $_POST['item_id'] = $item->ID; |
387 | 387 | $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
388 | 388 | |
@@ -392,15 +392,15 @@ discard block |
||
392 | 392 | } |
393 | 393 | |
394 | 394 | public static function get_billing_details() { |
395 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
395 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
396 | 396 | |
397 | - if ( !current_user_can( 'manage_options' ) ) { |
|
397 | + if (!current_user_can('manage_options')) { |
|
398 | 398 | die(-1); |
399 | 399 | } |
400 | 400 | |
401 | 401 | $user_id = (int)$_POST['user_id']; |
402 | 402 | $billing_details = wpinv_get_user_address($user_id); |
403 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
403 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
404 | 404 | |
405 | 405 | if (isset($billing_details['user_id'])) { |
406 | 406 | unset($billing_details['user_id']); |
@@ -414,20 +414,20 @@ discard block |
||
414 | 414 | $response['success'] = true; |
415 | 415 | $response['data']['billing_details'] = $billing_details; |
416 | 416 | |
417 | - wp_send_json( $response ); |
|
417 | + wp_send_json($response); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | public static function admin_recalculate_totals() { |
421 | 421 | global $wpi_userID, $wpinv_ip_address_country; |
422 | 422 | |
423 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
424 | - if ( !current_user_can( 'manage_options' ) ) { |
|
423 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
424 | + if (!current_user_can('manage_options')) { |
|
425 | 425 | die(-1); |
426 | 426 | } |
427 | 427 | |
428 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
429 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
430 | - if ( empty( $invoice ) ) { |
|
428 | + $invoice_id = absint($_POST['invoice_id']); |
|
429 | + $invoice = wpinv_get_invoice($invoice_id); |
|
430 | + if (empty($invoice)) { |
|
431 | 431 | die(); |
432 | 432 | } |
433 | 433 | |
@@ -435,23 +435,23 @@ discard block |
||
435 | 435 | |
436 | 436 | $data = array(); |
437 | 437 | $data['invoice_id'] = $invoice_id; |
438 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
438 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
439 | 439 | |
440 | - wpinv_set_checkout_session( $data ); |
|
440 | + wpinv_set_checkout_session($data); |
|
441 | 441 | |
442 | - if ( !empty( $_POST['user_id'] ) ) { |
|
443 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
442 | + if (!empty($_POST['user_id'])) { |
|
443 | + $wpi_userID = absint($_POST['user_id']); |
|
444 | 444 | } |
445 | 445 | |
446 | - if ( empty( $_POST['country'] ) ) { |
|
446 | + if (empty($_POST['country'])) { |
|
447 | 447 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
448 | 448 | } |
449 | 449 | |
450 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
451 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
452 | - if ( isset( $_POST['state'] ) ) { |
|
453 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
454 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
450 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
451 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
452 | + if (isset($_POST['state'])) { |
|
453 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
454 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | $wpinv_ip_address_country = $invoice->country; |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | |
461 | 461 | $response = array(); |
462 | 462 | $response['success'] = true; |
463 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
463 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
464 | 464 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
465 | 465 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
466 | 466 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -472,25 +472,25 @@ discard block |
||
472 | 472 | |
473 | 473 | wpinv_set_checkout_session($checkout_session); |
474 | 474 | |
475 | - wp_send_json( $response ); |
|
475 | + wp_send_json($response); |
|
476 | 476 | } |
477 | 477 | |
478 | 478 | public static function admin_apply_discount() { |
479 | 479 | global $wpi_userID; |
480 | 480 | |
481 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
482 | - if ( !current_user_can( 'manage_options' ) ) { |
|
481 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
482 | + if (!current_user_can('manage_options')) { |
|
483 | 483 | die(-1); |
484 | 484 | } |
485 | 485 | |
486 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
487 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
488 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
486 | + $invoice_id = absint($_POST['invoice_id']); |
|
487 | + $discount_code = sanitize_text_field($_POST['code']); |
|
488 | + if (empty($invoice_id) || empty($discount_code)) { |
|
489 | 489 | die(); |
490 | 490 | } |
491 | 491 | |
492 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
493 | - if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) { |
|
492 | + $invoice = wpinv_get_invoice($invoice_id); |
|
493 | + if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) { |
|
494 | 494 | die(); |
495 | 495 | } |
496 | 496 | |
@@ -498,49 +498,49 @@ discard block |
||
498 | 498 | |
499 | 499 | $data = array(); |
500 | 500 | $data['invoice_id'] = $invoice_id; |
501 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
501 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
502 | 502 | |
503 | - wpinv_set_checkout_session( $data ); |
|
503 | + wpinv_set_checkout_session($data); |
|
504 | 504 | |
505 | 505 | $response = array(); |
506 | 506 | $response['success'] = false; |
507 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
507 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
508 | 508 | $response['data']['code'] = $discount_code; |
509 | 509 | |
510 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
511 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
510 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
511 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
512 | 512 | |
513 | 513 | $response['success'] = true; |
514 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
515 | - } else { |
|
514 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
515 | + } else { |
|
516 | 516 | $errors = wpinv_get_errors(); |
517 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
517 | + if (!empty($errors['wpinv-discount-error'])) { |
|
518 | 518 | $response['msg'] = $errors['wpinv-discount-error']; |
519 | 519 | } |
520 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
520 | + wpinv_unset_error('wpinv-discount-error'); |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | wpinv_set_checkout_session($checkout_session); |
524 | 524 | |
525 | - wp_send_json( $response ); |
|
525 | + wp_send_json($response); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | public static function admin_remove_discount() { |
529 | 529 | global $wpi_userID; |
530 | 530 | |
531 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
532 | - if ( !current_user_can( 'manage_options' ) ) { |
|
531 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
532 | + if (!current_user_can('manage_options')) { |
|
533 | 533 | die(-1); |
534 | 534 | } |
535 | 535 | |
536 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
537 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
538 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
536 | + $invoice_id = absint($_POST['invoice_id']); |
|
537 | + $discount_code = sanitize_text_field($_POST['code']); |
|
538 | + if (empty($invoice_id) || empty($discount_code)) { |
|
539 | 539 | die(); |
540 | 540 | } |
541 | 541 | |
542 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
543 | - if ( empty( $invoice ) || ( !empty( $invoice ) && $invoice->is_paid() ) ) { |
|
542 | + $invoice = wpinv_get_invoice($invoice_id); |
|
543 | + if (empty($invoice) || (!empty($invoice) && $invoice->is_paid())) { |
|
544 | 544 | die(); |
545 | 545 | } |
546 | 546 | |
@@ -548,38 +548,38 @@ discard block |
||
548 | 548 | |
549 | 549 | $data = array(); |
550 | 550 | $data['invoice_id'] = $invoice_id; |
551 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
551 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
552 | 552 | |
553 | - wpinv_set_checkout_session( $data ); |
|
553 | + wpinv_set_checkout_session($data); |
|
554 | 554 | |
555 | 555 | $response = array(); |
556 | 556 | $response['success'] = false; |
557 | 557 | $response['msg'] = NULL; |
558 | 558 | |
559 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
559 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
560 | 560 | $response['success'] = true; |
561 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
561 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
562 | 562 | |
563 | 563 | wpinv_set_checkout_session($checkout_session); |
564 | 564 | |
565 | - wp_send_json( $response ); |
|
565 | + wp_send_json($response); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | public static function check_email() { |
569 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
570 | - if ( !current_user_can( 'manage_options' ) ) { |
|
569 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
570 | + if (!current_user_can('manage_options')) { |
|
571 | 571 | die(-1); |
572 | 572 | } |
573 | 573 | |
574 | - $email = sanitize_text_field( $_POST['email'] ); |
|
574 | + $email = sanitize_text_field($_POST['email']); |
|
575 | 575 | |
576 | 576 | $response = array(); |
577 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
577 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
578 | 578 | $user_id = $user_data->ID; |
579 | 579 | $user_login = $user_data->user_login; |
580 | 580 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
581 | 581 | $billing_details = wpinv_get_user_address($user_id); |
582 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
582 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
583 | 583 | |
584 | 584 | if (isset($billing_details['user_id'])) { |
585 | 585 | unset($billing_details['user_id']); |
@@ -595,31 +595,31 @@ discard block |
||
595 | 595 | $response['data']['billing_details'] = $billing_details; |
596 | 596 | } |
597 | 597 | |
598 | - wp_send_json( $response ); |
|
598 | + wp_send_json($response); |
|
599 | 599 | } |
600 | 600 | |
601 | 601 | public static function run_tool() { |
602 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
603 | - if ( !current_user_can( 'manage_options' ) ) { |
|
602 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
603 | + if (!current_user_can('manage_options')) { |
|
604 | 604 | die(-1); |
605 | 605 | } |
606 | 606 | |
607 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
607 | + $tool = sanitize_text_field($_POST['tool']); |
|
608 | 608 | |
609 | - do_action( 'wpinv_run_tool' ); |
|
609 | + do_action('wpinv_run_tool'); |
|
610 | 610 | |
611 | - if ( !empty( $tool ) ) { |
|
612 | - do_action( 'wpinv_tool_' . $tool ); |
|
611 | + if (!empty($tool)) { |
|
612 | + do_action('wpinv_tool_' . $tool); |
|
613 | 613 | } |
614 | 614 | } |
615 | 615 | |
616 | 616 | public static function apply_discount() { |
617 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
617 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
618 | 618 | |
619 | 619 | $response = array(); |
620 | 620 | |
621 | - if ( isset( $_POST['code'] ) ) { |
|
622 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
621 | + if (isset($_POST['code'])) { |
|
622 | + $discount_code = sanitize_text_field($_POST['code']); |
|
623 | 623 | |
624 | 624 | $response['success'] = false; |
625 | 625 | $response['msg'] = ''; |
@@ -627,14 +627,14 @@ discard block |
||
627 | 627 | |
628 | 628 | $user = is_user_logged_in() ? get_current_user_id() : ''; |
629 | 629 | |
630 | - if ( wpinv_is_discount_valid( $discount_code, $user ) ) { |
|
631 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
632 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
633 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
634 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
635 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
630 | + if (wpinv_is_discount_valid($discount_code, $user)) { |
|
631 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
632 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
633 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
634 | + $total = wpinv_get_cart_total(null, $discounts); |
|
635 | + $cart_totals = wpinv_recalculate_tax(true); |
|
636 | 636 | |
637 | - if ( !empty( $cart_totals ) ) { |
|
637 | + if (!empty($cart_totals)) { |
|
638 | 638 | $response['success'] = true; |
639 | 639 | $response['data'] = $cart_totals; |
640 | 640 | $response['data']['code'] = $discount_code; |
@@ -643,29 +643,29 @@ discard block |
||
643 | 643 | } |
644 | 644 | } else { |
645 | 645 | $errors = wpinv_get_errors(); |
646 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
647 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
646 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
647 | + wpinv_unset_error('wpinv-discount-error'); |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | // Allow for custom discount code handling |
651 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
651 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
652 | 652 | } |
653 | 653 | |
654 | - wp_send_json( $response ); |
|
654 | + wp_send_json($response); |
|
655 | 655 | } |
656 | 656 | |
657 | 657 | public static function remove_discount() { |
658 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
658 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
659 | 659 | |
660 | 660 | $response = array(); |
661 | 661 | |
662 | - if ( isset( $_POST['code'] ) ) { |
|
663 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
664 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
665 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
666 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
662 | + if (isset($_POST['code'])) { |
|
663 | + $discount_code = sanitize_text_field($_POST['code']); |
|
664 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
665 | + $total = wpinv_get_cart_total(null, $discounts); |
|
666 | + $cart_totals = wpinv_recalculate_tax(true); |
|
667 | 667 | |
668 | - if ( !empty( $cart_totals ) ) { |
|
668 | + if (!empty($cart_totals)) { |
|
669 | 669 | $response['success'] = true; |
670 | 670 | $response['data'] = $cart_totals; |
671 | 671 | $response['data']['code'] = $discount_code; |
@@ -674,10 +674,10 @@ discard block |
||
674 | 674 | } |
675 | 675 | |
676 | 676 | // Allow for custom discount code handling |
677 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
677 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
678 | 678 | } |
679 | 679 | |
680 | - wp_send_json( $response ); |
|
680 | + wp_send_json($response); |
|
681 | 681 | } |
682 | 682 | } |
683 | 683 |
@@ -7,228 +7,228 @@ 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 | - 'ID' => __( 'ID', 'invoicing' ), |
|
18 | - 'details' => __( 'Details', 'invoicing' ), |
|
17 | + 'ID' => __('ID', 'invoicing'), |
|
18 | + 'details' => __('Details', 'invoicing'), |
|
19 | 19 | //'email' => __( 'Email', 'invoicing' ), |
20 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
21 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
22 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
23 | - 'status' => __( 'Status', 'invoicing' ), |
|
24 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
20 | + 'customer' => __('Customer', 'invoicing'), |
|
21 | + 'amount' => __('Amount', 'invoicing'), |
|
22 | + 'invoice_date' => __('Date', 'invoicing'), |
|
23 | + 'status' => __('Status', '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' ); |
|
38 | +add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions'); |
|
39 | 39 | |
40 | -function wpinv_sortable_columns( $columns ) { |
|
40 | +function wpinv_sortable_columns($columns) { |
|
41 | 41 | $columns = array( |
42 | - 'ID' => array( 'ID', true ), |
|
43 | - 'amount' => array( 'amount', false ), |
|
44 | - 'invoice_date' => array( 'date', false ), |
|
45 | - 'customer' => array( 'customer', false ), |
|
42 | + 'ID' => array('ID', true), |
|
43 | + 'amount' => array('amount', false), |
|
44 | + 'invoice_date' => array('date', false), |
|
45 | + 'customer' => array('customer', false), |
|
46 | 46 | ///'email' => array( 'email', false ), |
47 | - 'status' => array( 'status', false ), |
|
47 | + 'status' => array('status', false), |
|
48 | 48 | ); |
49 | 49 | |
50 | - return apply_filters( 'wpi_invoice_table_sortable_columns', $columns ); |
|
50 | + return apply_filters('wpi_invoice_table_sortable_columns', $columns); |
|
51 | 51 | } |
52 | -add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' ); |
|
52 | +add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns'); |
|
53 | 53 | |
54 | -add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
55 | -function wpinv_posts_custom_column( $column_name, $post_id = 0 ) { |
|
54 | +add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
55 | +function wpinv_posts_custom_column($column_name, $post_id = 0) { |
|
56 | 56 | global $post, $wpi_invoice; |
57 | 57 | |
58 | - if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) { |
|
59 | - $wpi_invoice = new WPInv_Invoice( $post->ID ); |
|
58 | + if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) { |
|
59 | + $wpi_invoice = new WPInv_Invoice($post->ID); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $value = NULL; |
63 | 63 | |
64 | - switch ( $column_name ) { |
|
64 | + switch ($column_name) { |
|
65 | 65 | case 'email' : |
66 | - $value = $wpi_invoice->get_email(); |
|
66 | + $value = $wpi_invoice->get_email(); |
|
67 | 67 | break; |
68 | 68 | case 'customer' : |
69 | 69 | $customer_name = $wpi_invoice->get_user_full_name(); |
70 | - $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' ); |
|
71 | - $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>'; |
|
72 | - if ( $email = $wpi_invoice->get_email() ) { |
|
70 | + $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing'); |
|
71 | + $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>'; |
|
72 | + if ($email = $wpi_invoice->get_email()) { |
|
73 | 73 | $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>'; |
74 | 74 | } |
75 | 75 | break; |
76 | 76 | case 'amount' : |
77 | - echo $wpi_invoice->get_total( true ); |
|
77 | + echo $wpi_invoice->get_total(true); |
|
78 | 78 | break; |
79 | 79 | case 'invoice_date' : |
80 | - $date_format = get_option( 'date_format' ); |
|
81 | - $time_format = get_option( 'time_format' ); |
|
82 | - $date_time_format = $date_format . ' '. $time_format; |
|
80 | + $date_format = get_option('date_format'); |
|
81 | + $time_format = get_option('time_format'); |
|
82 | + $date_time_format = $date_format . ' ' . $time_format; |
|
83 | 83 | |
84 | - $t_time = get_the_time( $date_time_format ); |
|
84 | + $t_time = get_the_time($date_time_format); |
|
85 | 85 | $m_time = $post->post_date; |
86 | - $h_time = mysql2date( $date_format, $m_time ); |
|
86 | + $h_time = mysql2date($date_format, $m_time); |
|
87 | 87 | |
88 | 88 | $value = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>'; |
89 | 89 | break; |
90 | 90 | case 'status' : |
91 | - $value = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' ); |
|
91 | + $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''); |
|
92 | 92 | break; |
93 | 93 | case 'details' : |
94 | - $edit_link = get_edit_post_link( $post->ID ); |
|
95 | - $value = '<a href="' . esc_url( $edit_link ) . '">' . __( 'View Invoice Details', 'invoicing' ) . '</a>'; |
|
94 | + $edit_link = get_edit_post_link($post->ID); |
|
95 | + $value = '<a href="' . esc_url($edit_link) . '">' . __('View Invoice Details', 'invoicing') . '</a>'; |
|
96 | 96 | break; |
97 | 97 | case 'wpi_actions' : |
98 | 98 | $value = ''; |
99 | - if ( !empty( $post->post_name ) ) { |
|
100 | - $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>'; |
|
99 | + if (!empty($post->post_name)) { |
|
100 | + $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>'; |
|
101 | 101 | } |
102 | 102 | |
103 | - if ( $email = $wpi_invoice->get_email() ) { |
|
104 | - $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>'; |
|
103 | + if ($email = $wpi_invoice->get_email()) { |
|
104 | + $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>'; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | break; |
108 | 108 | default: |
109 | - $value = isset( $post->$column_name ) ? $post->$column_name : ''; |
|
109 | + $value = isset($post->$column_name) ? $post->$column_name : ''; |
|
110 | 110 | break; |
111 | 111 | |
112 | 112 | } |
113 | - $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name ); |
|
113 | + $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name); |
|
114 | 114 | |
115 | - if ( $value !== NULL ) { |
|
115 | + if ($value !== NULL) { |
|
116 | 116 | echo $value; |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | -function wpinv_admin_post_id( $id = 0 ) { |
|
120 | +function wpinv_admin_post_id($id = 0) { |
|
121 | 121 | global $post; |
122 | 122 | |
123 | - if ( isset( $id ) && ! empty( $id ) ) { |
|
123 | + if (isset($id) && !empty($id)) { |
|
124 | 124 | return (int)$id; |
125 | - } else if ( get_the_ID() ) { |
|
126 | - return (int) get_the_ID(); |
|
127 | - } else if ( isset( $post->ID ) && !empty( $post->ID ) ) { |
|
128 | - return (int) $post->ID; |
|
129 | - } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) { |
|
130 | - return (int) $_GET['post']; |
|
131 | - } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) { |
|
132 | - return (int) $_GET['id']; |
|
133 | - } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) { |
|
134 | - return (int) $_POST['id']; |
|
125 | + } else if (get_the_ID()) { |
|
126 | + return (int)get_the_ID(); |
|
127 | + } else if (isset($post->ID) && !empty($post->ID)) { |
|
128 | + return (int)$post->ID; |
|
129 | + } else if (isset($_GET['post']) && !empty($_GET['post'])) { |
|
130 | + return (int)$_GET['post']; |
|
131 | + } else if (isset($_GET['id']) && !empty($_GET['id'])) { |
|
132 | + return (int)$_GET['id']; |
|
133 | + } else if (isset($_POST['id']) && !empty($_POST['id'])) { |
|
134 | + return (int)$_POST['id']; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | return null; |
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_admin_post_type( $id = 0 ) { |
|
141 | - if ( !$id ) { |
|
140 | +function wpinv_admin_post_type($id = 0) { |
|
141 | + if (!$id) { |
|
142 | 142 | $id = wpinv_admin_post_id(); |
143 | 143 | } |
144 | 144 | |
145 | - $type = get_post_type( $id ); |
|
145 | + $type = get_post_type($id); |
|
146 | 146 | |
147 | - if ( !$type ) { |
|
148 | - $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null; |
|
147 | + if (!$type) { |
|
148 | + $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null; |
|
149 | 149 | } |
150 | 150 | |
151 | - return apply_filters( 'wpinv_admin_post_type', $type, $id ); |
|
151 | + return apply_filters('wpinv_admin_post_type', $type, $id); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | function wpinv_admin_messages() { |
155 | 155 | global $wpinv_options; |
156 | 156 | |
157 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
158 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
157 | + if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
158 | + add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated'); |
|
159 | 159 | } |
160 | 160 | |
161 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
162 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
161 | + if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
162 | + add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error'); |
|
163 | 163 | } |
164 | 164 | |
165 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
166 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
165 | + if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
166 | + add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error'); |
|
167 | 167 | } |
168 | 168 | |
169 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
170 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
169 | + if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
170 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated'); |
|
171 | 171 | } |
172 | 172 | |
173 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
174 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
173 | + if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
174 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error'); |
|
175 | 175 | } |
176 | 176 | |
177 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
178 | - add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
177 | + if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
178 | + add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated'); |
|
179 | 179 | } |
180 | 180 | |
181 | - if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
182 | - add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
181 | + if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
182 | + add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated'); |
|
183 | 183 | } |
184 | 184 | |
185 | - if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
186 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
185 | + if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
186 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error'); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
190 | - add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
|
189 | + if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
190 | + add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated'); |
|
191 | 191 | } |
192 | 192 | |
193 | - if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
194 | - add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
193 | + if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
194 | + add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated'); |
|
195 | 195 | } |
196 | 196 | |
197 | - if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
198 | - add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
197 | + if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
198 | + add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated'); |
|
199 | 199 | } |
200 | 200 | |
201 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
202 | - add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
201 | + if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
202 | + add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated'); |
|
203 | 203 | } |
204 | 204 | |
205 | - settings_errors( 'wpinv-notices' ); |
|
205 | + settings_errors('wpinv-notices'); |
|
206 | 206 | } |
207 | -add_action( 'admin_notices', 'wpinv_admin_messages' ); |
|
207 | +add_action('admin_notices', 'wpinv_admin_messages'); |
|
208 | 208 | |
209 | -function wpinv_items_columns( $existing_columns ) { |
|
209 | +function wpinv_items_columns($existing_columns) { |
|
210 | 210 | global $wpinv_euvat; |
211 | 211 | |
212 | 212 | $columns = array(); |
213 | 213 | $columns['cb'] = $existing_columns['cb']; |
214 | - $columns['title'] = __( 'Title', 'invoicing' ); |
|
215 | - $columns['price'] = __( 'Price', 'invoicing' ); |
|
216 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
217 | - $columns['vat_rule'] = __( 'VAT rule type', 'invoicing' ); |
|
214 | + $columns['title'] = __('Title', 'invoicing'); |
|
215 | + $columns['price'] = __('Price', 'invoicing'); |
|
216 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
217 | + $columns['vat_rule'] = __('VAT rule type', 'invoicing'); |
|
218 | 218 | } |
219 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
220 | - $columns['vat_class'] = __( 'VAT class', 'invoicing' ); |
|
219 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
220 | + $columns['vat_class'] = __('VAT class', 'invoicing'); |
|
221 | 221 | } |
222 | - $columns['type'] = __( 'Type', 'invoicing' ); |
|
223 | - $columns['recurring'] = __( 'Recurring', 'invoicing' ); |
|
224 | - $columns['date'] = __( 'Date', 'invoicing' ); |
|
225 | - $columns['id'] = __( 'ID', 'invoicing' ); |
|
222 | + $columns['type'] = __('Type', 'invoicing'); |
|
223 | + $columns['recurring'] = __('Recurring', 'invoicing'); |
|
224 | + $columns['date'] = __('Date', 'invoicing'); |
|
225 | + $columns['id'] = __('ID', 'invoicing'); |
|
226 | 226 | |
227 | - return apply_filters( 'wpinv_items_columns', $columns ); |
|
227 | + return apply_filters('wpinv_items_columns', $columns); |
|
228 | 228 | } |
229 | -add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' ); |
|
229 | +add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns'); |
|
230 | 230 | |
231 | -function wpinv_items_sortable_columns( $columns ) { |
|
231 | +function wpinv_items_sortable_columns($columns) { |
|
232 | 232 | $columns['price'] = 'price'; |
233 | 233 | $columns['vat_rule'] = 'vat_rule'; |
234 | 234 | $columns['vat_class'] = 'vat_class'; |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | |
239 | 239 | return $columns; |
240 | 240 | } |
241 | -add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' ); |
|
241 | +add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns'); |
|
242 | 242 | |
243 | -function wpinv_item_quick_edit( $column_name, $post_type ) { |
|
244 | - if ( !( $post_type == 'wpi_item' && $column_name == 'price' ) ) { |
|
243 | +function wpinv_item_quick_edit($column_name, $post_type) { |
|
244 | + if (!($post_type == 'wpi_item' && $column_name == 'price')) { |
|
245 | 245 | return; |
246 | 246 | } |
247 | 247 | global $wpinv_euvat, $post; |
@@ -249,23 +249,23 @@ discard block |
||
249 | 249 | $symbol = wpinv_currency_symbol(); |
250 | 250 | $position = wpinv_currency_position(); |
251 | 251 | |
252 | - $price = wpinv_get_item_price( $post->ID ); |
|
253 | - $item_type = wpinv_get_item_type( $post->ID ); |
|
252 | + $price = wpinv_get_item_price($post->ID); |
|
253 | + $item_type = wpinv_get_item_type($post->ID); |
|
254 | 254 | ?> |
255 | 255 | <fieldset class="inline-edit-col-right wpi-inline-item-col"> |
256 | 256 | <div class="inline-edit-col"> |
257 | 257 | <div class="inline-edit-group wp-clearfix"> |
258 | 258 | <label class="inline-edit-wpinv-price"> |
259 | - <span class="title"><?php _e( 'Item price', 'invoicing' );?></span> |
|
260 | - <span class="input-text-wrap"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID;?>"><?php echo ( $position == 'right' ? $symbol . ' ' : '' );?></span> |
|
259 | + <span class="title"><?php _e('Item price', 'invoicing'); ?></span> |
|
260 | + <span class="input-text-wrap"><?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID; ?>"><?php echo ($position == 'right' ? $symbol . ' ' : ''); ?></span> |
|
261 | 261 | </label> |
262 | 262 | </div> |
263 | - <?php if ( $wpinv_euvat->allow_vat_rules() ) { $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); ?> |
|
263 | + <?php if ($wpinv_euvat->allow_vat_rules()) { $rule_type = $wpinv_euvat->get_item_rule($post->ID); ?> |
|
264 | 264 | <div class="inline-edit-group wp-clearfix"> |
265 | 265 | <label class="inline-edit-wpinv-vat-rate"> |
266 | - <span class="title"><?php _e( 'VAT rule type to use', 'invoicing' );?></span> |
|
266 | + <span class="title"><?php _e('VAT rule type to use', 'invoicing'); ?></span> |
|
267 | 267 | <span class="input-text-wrap"> |
268 | - <?php echo wpinv_html_select( array( |
|
268 | + <?php echo wpinv_html_select(array( |
|
269 | 269 | 'options' => $wpinv_euvat->get_rules(), |
270 | 270 | 'name' => '_wpinv_vat_rules', |
271 | 271 | 'id' => 'wpinv_vat_rules-' . $post->ID, |
@@ -273,16 +273,16 @@ discard block |
||
273 | 273 | 'show_option_all' => false, |
274 | 274 | 'show_option_none' => false, |
275 | 275 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules', |
276 | - ) ); ?> |
|
276 | + )); ?> |
|
277 | 277 | </span> |
278 | 278 | </label> |
279 | 279 | </div> |
280 | - <?php } if ( $wpinv_euvat->allow_vat_classes() ) { $vat_class = $wpinv_euvat->get_item_class( $post->ID ); ?> |
|
280 | + <?php } if ($wpinv_euvat->allow_vat_classes()) { $vat_class = $wpinv_euvat->get_item_class($post->ID); ?> |
|
281 | 281 | <div class="inline-edit-group wp-clearfix"> |
282 | 282 | <label class="inline-edit-wpinv-vat-class"> |
283 | - <span class="title"><?php _e( 'VAT class to use', 'invoicing' );?></span> |
|
283 | + <span class="title"><?php _e('VAT class to use', 'invoicing'); ?></span> |
|
284 | 284 | <span class="input-text-wrap"> |
285 | - <?php echo wpinv_html_select( array( |
|
285 | + <?php echo wpinv_html_select(array( |
|
286 | 286 | 'options' => $wpinv_euvat->get_all_classes(), |
287 | 287 | 'name' => '_wpinv_vat_class', |
288 | 288 | 'id' => 'wpinv_vat_class-' . $post->ID, |
@@ -290,16 +290,16 @@ discard block |
||
290 | 290 | 'show_option_all' => false, |
291 | 291 | 'show_option_none' => false, |
292 | 292 | 'class' => 'gdmbx2-text-medium wpinv-vat-class', |
293 | - ) ); ?> |
|
293 | + )); ?> |
|
294 | 294 | </span> |
295 | 295 | </label> |
296 | 296 | </div> |
297 | 297 | <?php } ?> |
298 | 298 | <div class="inline-edit-group wp-clearfix"> |
299 | 299 | <label class="inline-edit-wpinv-type"> |
300 | - <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
|
300 | + <span class="title"><?php _e('Item type', 'invoicing'); ?></span> |
|
301 | 301 | <span class="input-text-wrap"> |
302 | - <?php echo wpinv_html_select( array( |
|
302 | + <?php echo wpinv_html_select(array( |
|
303 | 303 | 'options' => wpinv_get_item_types(), |
304 | 304 | 'name' => '_wpinv_item_type', |
305 | 305 | 'id' => 'wpinv_item_type-' . $post->ID, |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | 'show_option_all' => false, |
308 | 308 | 'show_option_none' => false, |
309 | 309 | 'class' => 'gdmbx2-text-medium wpinv-item-type', |
310 | - ) ); ?> |
|
310 | + )); ?> |
|
311 | 311 | </span> |
312 | 312 | </label> |
313 | 313 | </div> |
@@ -315,150 +315,150 @@ discard block |
||
315 | 315 | </fieldset> |
316 | 316 | <?php |
317 | 317 | } |
318 | -add_action( 'quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 ); |
|
319 | -add_action( 'bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 ); |
|
318 | +add_action('quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2); |
|
319 | +add_action('bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2); |
|
320 | 320 | |
321 | -function wpinv_items_table_custom_column( $column ) { |
|
321 | +function wpinv_items_table_custom_column($column) { |
|
322 | 322 | global $wpinv_euvat, $post, $wpi_item; |
323 | 323 | |
324 | - if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) { |
|
325 | - $wpi_item = new WPInv_Item( $post->ID ); |
|
324 | + if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) { |
|
325 | + $wpi_item = new WPInv_Item($post->ID); |
|
326 | 326 | } |
327 | 327 | |
328 | - switch ( $column ) { |
|
328 | + switch ($column) { |
|
329 | 329 | case 'price' : |
330 | - echo wpinv_item_price( $post->ID ); |
|
330 | + echo wpinv_item_price($post->ID); |
|
331 | 331 | break; |
332 | 332 | case 'vat_rule' : |
333 | - echo $wpinv_euvat->item_rule_label( $post->ID ); |
|
333 | + echo $wpinv_euvat->item_rule_label($post->ID); |
|
334 | 334 | break; |
335 | 335 | case 'vat_class' : |
336 | - echo $wpinv_euvat->item_class_label( $post->ID ); |
|
336 | + echo $wpinv_euvat->item_class_label($post->ID); |
|
337 | 337 | break; |
338 | 338 | case 'type' : |
339 | - echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_cpt_singular_name() . '</span>'; |
|
339 | + echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_cpt_singular_name() . '</span>'; |
|
340 | 340 | break; |
341 | 341 | case 'recurring' : |
342 | - 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>' ); |
|
342 | + 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>'); |
|
343 | 343 | break; |
344 | 344 | case 'id' : |
345 | 345 | echo $post->ID; |
346 | 346 | echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
347 | - <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>'; |
|
348 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
349 | - echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>'; |
|
347 | + <div class="price">' . wpinv_get_item_price($post->ID) . '</div>'; |
|
348 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
349 | + echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>'; |
|
350 | 350 | } |
351 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
352 | - echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>'; |
|
351 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
352 | + echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>'; |
|
353 | 353 | } |
354 | - echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div> |
|
354 | + echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div> |
|
355 | 355 | </div>'; |
356 | 356 | break; |
357 | 357 | } |
358 | 358 | |
359 | - do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post ); |
|
359 | + do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post); |
|
360 | 360 | } |
361 | -add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' ); |
|
361 | +add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column'); |
|
362 | 362 | |
363 | 363 | function wpinv_add_items_filters() { |
364 | 364 | global $wpinv_euvat, $typenow; |
365 | 365 | |
366 | 366 | // Checks if the current post type is 'item' |
367 | - if ( $typenow == 'wpi_item') { |
|
368 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
369 | - echo wpinv_html_select( array( |
|
370 | - 'options' => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ), |
|
367 | + if ($typenow == 'wpi_item') { |
|
368 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
369 | + echo wpinv_html_select(array( |
|
370 | + 'options' => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()), |
|
371 | 371 | 'name' => 'vat_rule', |
372 | 372 | 'id' => 'vat_rule', |
373 | - 'selected' => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ), |
|
373 | + 'selected' => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''), |
|
374 | 374 | 'show_option_all' => false, |
375 | 375 | 'show_option_none' => false, |
376 | 376 | 'class' => 'gdmbx2-text-medium', |
377 | - ) ); |
|
377 | + )); |
|
378 | 378 | } |
379 | 379 | |
380 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
381 | - echo wpinv_html_select( array( |
|
382 | - 'options' => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ), |
|
380 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
381 | + echo wpinv_html_select(array( |
|
382 | + 'options' => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()), |
|
383 | 383 | 'name' => 'vat_class', |
384 | 384 | 'id' => 'vat_class', |
385 | - 'selected' => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ), |
|
385 | + 'selected' => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''), |
|
386 | 386 | 'show_option_all' => false, |
387 | 387 | 'show_option_none' => false, |
388 | 388 | 'class' => 'gdmbx2-text-medium', |
389 | - ) ); |
|
389 | + )); |
|
390 | 390 | } |
391 | 391 | |
392 | - echo wpinv_html_select( array( |
|
393 | - 'options' => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ), |
|
392 | + echo wpinv_html_select(array( |
|
393 | + 'options' => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()), |
|
394 | 394 | 'name' => 'type', |
395 | 395 | 'id' => 'type', |
396 | - 'selected' => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ), |
|
396 | + 'selected' => (isset($_GET['type']) ? $_GET['type'] : ''), |
|
397 | 397 | 'show_option_all' => false, |
398 | 398 | 'show_option_none' => false, |
399 | 399 | 'class' => 'gdmbx2-text-medium', |
400 | - ) ); |
|
400 | + )); |
|
401 | 401 | |
402 | - if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) { |
|
402 | + if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) { |
|
403 | 403 | echo '<input type="hidden" name="all_posts" value="1" />'; |
404 | 404 | } |
405 | 405 | } |
406 | 406 | } |
407 | -add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 ); |
|
407 | +add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100); |
|
408 | 408 | |
409 | -function wpinv_send_invoice_after_save( $post_id ) { |
|
409 | +function wpinv_send_invoice_after_save($post_id) { |
|
410 | 410 | // If this is just a revision, don't send the email. |
411 | - if ( wp_is_post_revision( $post_id ) ) { |
|
411 | + if (wp_is_post_revision($post_id)) { |
|
412 | 412 | return; |
413 | 413 | } |
414 | 414 | |
415 | - if ( !current_user_can( 'manage_options' ) || !(get_post_type( $post_id ) == 'wpi_invoice' || get_post_type( $post_id ) == 'wpi_quote') ) { |
|
415 | + if (!current_user_can('manage_options') || !(get_post_type($post_id) == 'wpi_invoice' || get_post_type($post_id) == 'wpi_quote')) { |
|
416 | 416 | return; |
417 | 417 | } |
418 | 418 | |
419 | - if ( !empty( $_POST['wpi_save_send'] ) ) { |
|
420 | - wpinv_user_invoice_notification( $post_id ); |
|
419 | + if (!empty($_POST['wpi_save_send'])) { |
|
420 | + wpinv_user_invoice_notification($post_id); |
|
421 | 421 | } |
422 | 422 | } |
423 | -add_action( 'save_post_wpi_invoice', 'wpinv_send_invoice_after_save', 100, 1 ); |
|
423 | +add_action('save_post_wpi_invoice', 'wpinv_send_invoice_after_save', 100, 1); |
|
424 | 424 | |
425 | -function wpinv_send_register_new_user( $data, $postarr ) { |
|
426 | - if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && $data['post_type'] == 'wpi_invoice' ) { |
|
427 | - $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false; |
|
428 | - $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL; |
|
425 | +function wpinv_send_register_new_user($data, $postarr) { |
|
426 | + if (current_user_can('manage_options') && !empty($data['post_type']) && $data['post_type'] == 'wpi_invoice') { |
|
427 | + $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false; |
|
428 | + $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL; |
|
429 | 429 | |
430 | - if ( $is_new_user && $email && !email_exists( $email ) ) { |
|
431 | - $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : ''; |
|
432 | - $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : ''; |
|
433 | - $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : ''; |
|
434 | - $user_nicename = $display_name ? trim( $display_name ) : $email; |
|
435 | - $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : ''; |
|
430 | + if ($is_new_user && $email && !email_exists($email)) { |
|
431 | + $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : ''; |
|
432 | + $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : ''; |
|
433 | + $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : ''; |
|
434 | + $user_nicename = $display_name ? trim($display_name) : $email; |
|
435 | + $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : ''; |
|
436 | 436 | |
437 | - $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true ); |
|
438 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
439 | - $user_login = sanitize_user( str_replace( ' ', '', $user_company ), true ); |
|
437 | + $user_login = sanitize_user(str_replace(' ', '', $display_name), true); |
|
438 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
439 | + $user_login = sanitize_user(str_replace(' ', '', $user_company), true); |
|
440 | 440 | |
441 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
441 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
442 | 442 | $user_login = $email; |
443 | 443 | } |
444 | 444 | } |
445 | 445 | |
446 | 446 | $userdata = array( |
447 | 447 | 'user_login' => $user_login, |
448 | - 'user_pass' => wp_generate_password( 12, false ), |
|
449 | - 'user_email' => sanitize_text_field( $email ), |
|
448 | + 'user_pass' => wp_generate_password(12, false), |
|
449 | + 'user_email' => sanitize_text_field($email), |
|
450 | 450 | 'first_name' => $first_name, |
451 | 451 | 'last_name' => $last_name, |
452 | - 'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ), |
|
452 | + 'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50), |
|
453 | 453 | 'nickname' => $display_name, |
454 | 454 | 'display_name' => $display_name, |
455 | 455 | ); |
456 | 456 | |
457 | - $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata ); |
|
457 | + $userdata = apply_filters('wpinv_register_new_user_data', $userdata); |
|
458 | 458 | |
459 | - $new_user_id = wp_insert_user( $userdata ); |
|
459 | + $new_user_id = wp_insert_user($userdata); |
|
460 | 460 | |
461 | - if ( !is_wp_error( $new_user_id ) ) { |
|
461 | + if (!is_wp_error($new_user_id)) { |
|
462 | 462 | $data['post_author'] = $new_user_id; |
463 | 463 | $_POST['post_author'] = $new_user_id; |
464 | 464 | $_POST['post_author_override'] = $new_user_id; |
@@ -479,27 +479,27 @@ discard block |
||
479 | 479 | |
480 | 480 | $meta = array(); |
481 | 481 | ///$meta['_wpinv_user_id'] = $new_user_id; |
482 | - foreach ( $meta_fields as $field ) { |
|
483 | - $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : ''; |
|
482 | + foreach ($meta_fields as $field) { |
|
483 | + $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : ''; |
|
484 | 484 | } |
485 | 485 | |
486 | - $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id ); |
|
486 | + $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id); |
|
487 | 487 | |
488 | 488 | // Update user meta. |
489 | - foreach ( $meta as $key => $value ) { |
|
490 | - update_user_meta( $new_user_id, $key, $value ); |
|
489 | + foreach ($meta as $key => $value) { |
|
490 | + update_user_meta($new_user_id, $key, $value); |
|
491 | 491 | } |
492 | 492 | |
493 | - if ( function_exists( 'wp_send_new_user_notifications' ) ) { |
|
493 | + if (function_exists('wp_send_new_user_notifications')) { |
|
494 | 494 | // Send email notifications related to the creation of new user. |
495 | - wp_send_new_user_notifications( $new_user_id, 'user' ); |
|
495 | + wp_send_new_user_notifications($new_user_id, 'user'); |
|
496 | 496 | } |
497 | 497 | } else { |
498 | - wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ ); |
|
498 | + wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__); |
|
499 | 499 | } |
500 | 500 | } |
501 | 501 | } |
502 | 502 | |
503 | 503 | return $data; |
504 | 504 | } |
505 | -add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 ); |
|
506 | 505 | \ No newline at end of file |
506 | +add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2); |
|
507 | 507 | \ No newline at end of file |
@@ -1,22 +1,22 @@ 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 | class WPInv_Meta_Box_Items { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | global $wpinv_euvat, $ajax_cart_details; |
10 | 10 | |
11 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
12 | - $invoice = new WPInv_Invoice( $post_id ); |
|
11 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
12 | + $invoice = new WPInv_Invoice($post_id); |
|
13 | 13 | $ajax_cart_details = $invoice->get_cart_details(); |
14 | - $subtotal = $invoice->get_subtotal( true ); |
|
14 | + $subtotal = $invoice->get_subtotal(true); |
|
15 | 15 | $discount_raw = $invoice->get_discount(); |
16 | - $discount = wpinv_price( $discount_raw, $invoice->get_currency() ); |
|
16 | + $discount = wpinv_price($discount_raw, $invoice->get_currency()); |
|
17 | 17 | $discounts = $discount_raw > 0 ? $invoice->get_discounts() : ''; |
18 | - $tax = $invoice->get_tax( true ); |
|
19 | - $total = $invoice->get_total( true ); |
|
18 | + $tax = $invoice->get_tax(true); |
|
19 | + $total = $invoice->get_total(true); |
|
20 | 20 | $item_quantities = wpinv_item_quantities_enabled(); |
21 | 21 | $use_taxes = wpinv_use_taxes(); |
22 | 22 | $item_types = wpinv_get_item_types(); |
@@ -29,17 +29,17 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | $cols = 5; |
32 | - if ( $item_quantities ) { |
|
32 | + if ($item_quantities) { |
|
33 | 33 | $cols++; |
34 | 34 | } |
35 | - if ( $use_taxes ) { |
|
35 | + if ($use_taxes) { |
|
36 | 36 | $cols++; |
37 | 37 | } |
38 | 38 | $class = ''; |
39 | - if ( $invoice->is_paid() ) { |
|
39 | + if ($invoice->is_paid()) { |
|
40 | 40 | $class .= ' wpinv-paid'; |
41 | 41 | } |
42 | - if ( $is_recurring ) { |
|
42 | + if ($is_recurring) { |
|
43 | 43 | $class .= ' wpi-recurring'; |
44 | 44 | } |
45 | 45 | ?> |
@@ -47,21 +47,21 @@ discard block |
||
47 | 47 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
48 | 48 | <thead> |
49 | 49 | <tr> |
50 | - <th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
|
51 | - <th class="title"><?php _e( 'Item', 'invoicing' );?></th> |
|
52 | - <th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
|
53 | - <?php if ( $item_quantities ) { ?> |
|
54 | - <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th> |
|
50 | + <th class="id"><?php _e('ID', 'invoicing'); ?></th> |
|
51 | + <th class="title"><?php _e('Item', 'invoicing'); ?></th> |
|
52 | + <th class="price"><?php _e('Price', 'invoicing'); ?></th> |
|
53 | + <?php if ($item_quantities) { ?> |
|
54 | + <th class="qty"><?php _e('Qty', 'invoicing'); ?></th> |
|
55 | 55 | <?php } ?> |
56 | - <th class="total"><?php _e( 'Total', 'invoicing' );?></th> |
|
57 | - <?php if ( $use_taxes ) { ?> |
|
58 | - <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th> |
|
56 | + <th class="total"><?php _e('Total', 'invoicing'); ?></th> |
|
57 | + <?php if ($use_taxes) { ?> |
|
58 | + <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th> |
|
59 | 59 | <?php } ?> |
60 | 60 | <th class="action"></th> |
61 | 61 | </tr> |
62 | 62 | </thead> |
63 | 63 | <tbody class="wpinv-line-items"> |
64 | - <?php echo wpinv_admin_get_line_items( $invoice ); ?> |
|
64 | + <?php echo wpinv_admin_get_line_items($invoice); ?> |
|
65 | 65 | </tbody> |
66 | 66 | <tfoot class="wpinv-totals"> |
67 | 67 | <tr> |
@@ -73,44 +73,44 @@ discard block |
||
73 | 73 | </td> |
74 | 74 | <td class="title"> |
75 | 75 | <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]"> |
76 | - <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> |
|
76 | + <?php if ($wpinv_euvat->allow_vat_rules()) { ?> |
|
77 | 77 | <div class="wp-clearfix"> |
78 | 78 | <label class="wpi-vat-rule"> |
79 | - <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span> |
|
79 | + <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span> |
|
80 | 80 | <span class="input-text-wrap"> |
81 | - <?php echo wpinv_html_select( array( |
|
81 | + <?php echo wpinv_html_select(array( |
|
82 | 82 | 'options' => $wpinv_euvat->get_rules(), |
83 | 83 | 'name' => '_wpinv_quick[vat_rule]', |
84 | 84 | 'id' => '_wpinv_quick_vat_rule', |
85 | 85 | 'show_option_all' => false, |
86 | 86 | 'show_option_none' => false, |
87 | 87 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
88 | - ) ); ?> |
|
88 | + )); ?> |
|
89 | 89 | </span> |
90 | 90 | </label> |
91 | 91 | </div> |
92 | - <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?> |
|
92 | + <?php } if ($wpinv_euvat->allow_vat_classes()) { ?> |
|
93 | 93 | <div class="wp-clearfix"> |
94 | 94 | <label class="wpi-vat-class"> |
95 | - <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span> |
|
95 | + <span class="title"><?php _e('VAT class', 'invoicing'); ?></span> |
|
96 | 96 | <span class="input-text-wrap"> |
97 | - <?php echo wpinv_html_select( array( |
|
97 | + <?php echo wpinv_html_select(array( |
|
98 | 98 | 'options' => $wpinv_euvat->get_all_classes(), |
99 | 99 | 'name' => '_wpinv_quick[vat_class]', |
100 | 100 | 'id' => '_wpinv_quick_vat_class', |
101 | 101 | 'show_option_all' => false, |
102 | 102 | 'show_option_none' => false, |
103 | 103 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
104 | - ) ); ?> |
|
104 | + )); ?> |
|
105 | 105 | </span> |
106 | 106 | </label> |
107 | 107 | </div> |
108 | 108 | <?php } ?> |
109 | 109 | <div class="wp-clearfix"> |
110 | 110 | <label class="wpi-item-type"> |
111 | - <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
|
111 | + <span class="title"><?php _e('Item type', 'invoicing'); ?></span> |
|
112 | 112 | <span class="input-text-wrap"> |
113 | - <?php echo wpinv_html_select( array( |
|
113 | + <?php echo wpinv_html_select(array( |
|
114 | 114 | 'options' => $item_types, |
115 | 115 | 'name' => '_wpinv_quick[type]', |
116 | 116 | 'id' => '_wpinv_quick_type', |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | 'show_option_all' => false, |
119 | 119 | 'show_option_none' => false, |
120 | 120 | 'class' => 'gdmbx2-text-medium wpinv-quick-type', |
121 | - ) ); ?> |
|
121 | + )); ?> |
|
122 | 122 | </span> |
123 | 123 | </label> |
124 | 124 | </div> |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | </div> |
132 | 132 | </td> |
133 | 133 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td> |
134 | - <?php if ( $item_quantities ) { ?> |
|
134 | + <?php if ($item_quantities) { ?> |
|
135 | 135 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td> |
136 | 136 | <?php } ?> |
137 | 137 | <td class="total"></td> |
138 | - <?php if ( $use_taxes ) { ?> |
|
138 | + <?php if ($use_taxes) { ?> |
|
139 | 139 | <td class="tax"></td> |
140 | 140 | <?php } ?> |
141 | 141 | <td class="action"></td> |
@@ -148,29 +148,29 @@ discard block |
||
148 | 148 | <td colspan="<?php echo $cols; ?>"></td> |
149 | 149 | </tr> |
150 | 150 | <tr class="totals"> |
151 | - <td colspan="<?php echo ( $cols - 4 ); ?>"></td> |
|
151 | + <td colspan="<?php echo ($cols - 4); ?>"></td> |
|
152 | 152 | <td colspan="4"> |
153 | 153 | <table cellspacing="0" cellpadding="0"> |
154 | 154 | <tr class="subtotal"> |
155 | - <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td> |
|
156 | - <td class="total"><?php echo $subtotal;?></td> |
|
155 | + <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td> |
|
156 | + <td class="total"><?php echo $subtotal; ?></td> |
|
157 | 157 | <td class="action"></td> |
158 | 158 | </tr> |
159 | 159 | <tr class="discount"> |
160 | - <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td> |
|
161 | - <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td> |
|
160 | + <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td> |
|
161 | + <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td> |
|
162 | 162 | <td class="action"></td> |
163 | 163 | </tr> |
164 | - <?php if ( $use_taxes ) { ?> |
|
164 | + <?php if ($use_taxes) { ?> |
|
165 | 165 | <tr class="tax"> |
166 | - <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td> |
|
167 | - <td class="total"><?php echo $tax;?></td> |
|
166 | + <td class="name"><?php _e('Tax:', 'invoicing'); ?></td> |
|
167 | + <td class="total"><?php echo $tax; ?></td> |
|
168 | 168 | <td class="action"></td> |
169 | 169 | </tr> |
170 | 170 | <?php } ?> |
171 | 171 | <tr class="total"> |
172 | - <td class="name"><?php _e( 'Invoice Total:', 'invoicing' );?></td> |
|
173 | - <td class="total"><?php echo $total;?></td> |
|
172 | + <td class="name"><?php _e('Invoice Total:', 'invoicing'); ?></td> |
|
173 | + <td class="total"><?php echo $total; ?></td> |
|
174 | 174 | <td class="action"></td> |
175 | 175 | </tr> |
176 | 176 | </table> |
@@ -180,89 +180,89 @@ discard block |
||
180 | 180 | </table> |
181 | 181 | <div class="wpinv-actions"> |
182 | 182 | <?php |
183 | - if ( !$invoice->is_paid() ) { |
|
184 | - if ( !$invoice->is_recurring() ) { |
|
185 | - echo wpinv_item_dropdown( array( |
|
183 | + if (!$invoice->is_paid()) { |
|
184 | + if (!$invoice->is_recurring()) { |
|
185 | + echo wpinv_item_dropdown(array( |
|
186 | 186 | 'name' => 'wpinv_invoice_item', |
187 | 187 | 'id' => 'wpinv_invoice_item', |
188 | 188 | 'with_packages' => false, |
189 | 189 | 'show_recurring' => true, |
190 | - ) ); |
|
190 | + )); |
|
191 | 191 | ?> |
192 | - <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
192 | + <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
193 | 193 | <?php } ?> |
194 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
|
194 | + <?php do_action('wpinv_invoice_items_actions', $invoice); ?> |
|
195 | 195 | </div> |
196 | 196 | </div> |
197 | 197 | <?php |
198 | 198 | } |
199 | 199 | |
200 | - public static function prices( $post ) { |
|
200 | + public static function prices($post) { |
|
201 | 201 | $symbol = wpinv_currency_symbol(); |
202 | 202 | $position = wpinv_currency_position(); |
203 | - $item = new WPInv_Item( $post->ID ); |
|
203 | + $item = new WPInv_Item($post->ID); |
|
204 | 204 | |
205 | 205 | $price = $item->get_price(); |
206 | 206 | $is_recurring = $item->is_recurring(); |
207 | 207 | $period = $item->get_recurring_period(); |
208 | - $interval = absint( $item->get_recurring_interval() ); |
|
209 | - $times = absint( $item->get_recurring_limit() ); |
|
208 | + $interval = absint($item->get_recurring_interval()); |
|
209 | + $times = absint($item->get_recurring_limit()); |
|
210 | 210 | $free_trial = $item->has_free_trial(); |
211 | 211 | $trial_interval = $item->get_trial_interval(); |
212 | 212 | $trial_period = $item->get_trial_period(); |
213 | 213 | |
214 | 214 | $intervals = array(); |
215 | - for ( $i = 1; $i <= 90; $i++ ) { |
|
215 | + for ($i = 1; $i <= 90; $i++) { |
|
216 | 216 | $intervals[$i] = $i; |
217 | 217 | } |
218 | 218 | |
219 | - $interval = $interval > 0 ? $interval : 1; |
|
219 | + $interval = $interval > 0 ? $interval : 1; |
|
220 | 220 | |
221 | 221 | $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n'; |
222 | 222 | ?> |
223 | - <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_package(), true ); ?> /><?php echo ( $position == 'right' ? ' ' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" /> |
|
224 | - <?php if ( $item->is_package() ) { ?> |
|
225 | - <span class="description"><?php _e( 'GD package item price can be edited only from GD payment manager.', 'invoicing' ); ?></span> |
|
223 | + <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_package(), true); ?> /><?php echo ($position == 'right' ? ' ' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" /> |
|
224 | + <?php if ($item->is_package()) { ?> |
|
225 | + <span class="description"><?php _e('GD package item price can be edited only from GD payment manager.', 'invoicing'); ?></span> |
|
226 | 226 | <?php } ?> |
227 | 227 | </p> |
228 | 228 | <p class="wpinv-row-is-recurring"> |
229 | 229 | <label for="wpinv_is_recurring"> |
230 | - <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> /> |
|
231 | - <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?> |
|
230 | + <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> /> |
|
231 | + <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?> |
|
232 | 232 | </label> |
233 | 233 | </p> |
234 | - <p class="wpinv-row-recurring-fields <?php echo $class;?>"> |
|
235 | - <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label> |
|
236 | - <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array( |
|
234 | + <p class="wpinv-row-recurring-fields <?php echo $class; ?>"> |
|
235 | + <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label> |
|
236 | + <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array( |
|
237 | 237 | 'options' => $intervals, |
238 | 238 | 'name' => 'wpinv_recurring_interval', |
239 | 239 | 'id' => 'wpinv_recurring_interval', |
240 | 240 | 'selected' => $interval, |
241 | 241 | 'show_option_all' => false, |
242 | 242 | 'show_option_none' => false |
243 | - ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label> |
|
244 | - <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label> |
|
243 | + )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label> |
|
244 | + <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label> |
|
245 | 245 | <span class="clear wpi-trial-clr"></span> |
246 | 246 | <label class="wpinv-free-trial" for="wpinv_free_trial"> |
247 | - <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> |
|
248 | - <?php echo __( 'Offer free trial for', 'invoicing' ); ?> |
|
247 | + <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> |
|
248 | + <?php echo __('Offer free trial for', 'invoicing'); ?> |
|
249 | 249 | </label> |
250 | 250 | <label class="wpinv-trial-interval" for="wpinv_trial_interval"> |
251 | - <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select> |
|
251 | + <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select> |
|
252 | 252 | </label> |
253 | 253 | </p> |
254 | - <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" /> |
|
255 | - <?php do_action( 'wpinv_item_price_field', $post->ID ); ?> |
|
254 | + <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" /> |
|
255 | + <?php do_action('wpinv_item_price_field', $post->ID); ?> |
|
256 | 256 | <?php |
257 | 257 | } |
258 | 258 | |
259 | - public static function vat_rules( $post ) { |
|
259 | + public static function vat_rules($post) { |
|
260 | 260 | global $wpinv_euvat; |
261 | 261 | |
262 | - $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); |
|
262 | + $rule_type = $wpinv_euvat->get_item_rule($post->ID); |
|
263 | 263 | ?> |
264 | - <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label> |
|
265 | - <?php echo wpinv_html_select( array( |
|
264 | + <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label> |
|
265 | + <?php echo wpinv_html_select(array( |
|
266 | 266 | 'options' => $wpinv_euvat->get_rules(), |
267 | 267 | 'name' => 'wpinv_vat_rules', |
268 | 268 | 'id' => 'wpinv_vat_rules', |
@@ -270,19 +270,19 @@ discard block |
||
270 | 270 | 'show_option_all' => false, |
271 | 271 | 'show_option_none' => false, |
272 | 272 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules', |
273 | - ) ); ?> |
|
273 | + )); ?> |
|
274 | 274 | </p> |
275 | - <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p> |
|
276 | - <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p> |
|
275 | + <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing'); ?></p> |
|
276 | + <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing'); ?></p> |
|
277 | 277 | <?php |
278 | 278 | } |
279 | 279 | |
280 | - public static function vat_classes( $post ) { |
|
280 | + public static function vat_classes($post) { |
|
281 | 281 | global $wpinv_euvat; |
282 | 282 | |
283 | - $vat_class = $wpinv_euvat->get_item_class( $post->ID ); |
|
283 | + $vat_class = $wpinv_euvat->get_item_class($post->ID); |
|
284 | 284 | ?> |
285 | - <p><?php echo wpinv_html_select( array( |
|
285 | + <p><?php echo wpinv_html_select(array( |
|
286 | 286 | 'options' => $wpinv_euvat->get_all_classes(), |
287 | 287 | 'name' => 'wpinv_vat_class', |
288 | 288 | 'id' => 'wpinv_vat_class', |
@@ -290,18 +290,18 @@ discard block |
||
290 | 290 | 'show_option_all' => false, |
291 | 291 | 'show_option_none' => false, |
292 | 292 | 'class' => 'gdmbx2-text-medium wpinv-vat-class', |
293 | - ) ); ?> |
|
293 | + )); ?> |
|
294 | 294 | </p> |
295 | - <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p> |
|
295 | + <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p> |
|
296 | 296 | <?php |
297 | 297 | } |
298 | 298 | |
299 | - public static function item_info( $post ) { |
|
300 | - $item_type = wpinv_get_item_type( $post->ID ); |
|
301 | - do_action( 'wpinv_item_info_metabox_before', $post ); |
|
299 | + public static function item_info($post) { |
|
300 | + $item_type = wpinv_get_item_type($post->ID); |
|
301 | + do_action('wpinv_item_info_metabox_before', $post); |
|
302 | 302 | ?> |
303 | - <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label> |
|
304 | - <?php echo wpinv_html_select( array( |
|
303 | + <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label> |
|
304 | + <?php echo wpinv_html_select(array( |
|
305 | 305 | 'options' => wpinv_get_item_types(), |
306 | 306 | 'name' => 'wpinv_item_type', |
307 | 307 | 'id' => 'wpinv_item_type', |
@@ -310,93 +310,93 @@ discard block |
||
310 | 310 | 'show_option_none' => false, |
311 | 311 | 'class' => 'gdmbx2-text-medium wpinv-item-type', |
312 | 312 | //'disabled' => $item_type == 'package' ? true : false, |
313 | - ) ); ?> |
|
313 | + )); ?> |
|
314 | 314 | </p> |
315 | - <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( 'Standard: standard item type', 'invoicing' );?><br><?php _e( 'Fee: like Registration Fee, Signup Fee etc.', 'invoicing' );?></p> |
|
315 | + <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('Standard: standard item type', 'invoicing'); ?><br><?php _e('Fee: like Registration Fee, Signup Fee etc.', 'invoicing'); ?></p> |
|
316 | 316 | <?php |
317 | - do_action( 'wpinv_item_info_metabox_after', $post ); |
|
317 | + do_action('wpinv_item_info_metabox_after', $post); |
|
318 | 318 | } |
319 | 319 | |
320 | - public static function save( $post_id, $data, $post ) { |
|
321 | - $invoice = new WPInv_Invoice( $post_id ); |
|
320 | + public static function save($post_id, $data, $post) { |
|
321 | + $invoice = new WPInv_Invoice($post_id); |
|
322 | 322 | |
323 | 323 | // Billing |
324 | - $first_name = sanitize_text_field( $data['wpinv_first_name'] ); |
|
325 | - $last_name = sanitize_text_field( $data['wpinv_last_name'] ); |
|
326 | - $company = sanitize_text_field( $data['wpinv_company'] ); |
|
327 | - $vat_number = sanitize_text_field( $data['wpinv_vat_number'] ); |
|
328 | - $phone = sanitize_text_field( $data['wpinv_phone'] ); |
|
329 | - $address = sanitize_text_field( $data['wpinv_address'] ); |
|
330 | - $city = sanitize_text_field( $data['wpinv_city'] ); |
|
331 | - $zip = sanitize_text_field( $data['wpinv_zip'] ); |
|
332 | - $country = sanitize_text_field( $data['wpinv_country'] ); |
|
333 | - $state = sanitize_text_field( $data['wpinv_state'] ); |
|
324 | + $first_name = sanitize_text_field($data['wpinv_first_name']); |
|
325 | + $last_name = sanitize_text_field($data['wpinv_last_name']); |
|
326 | + $company = sanitize_text_field($data['wpinv_company']); |
|
327 | + $vat_number = sanitize_text_field($data['wpinv_vat_number']); |
|
328 | + $phone = sanitize_text_field($data['wpinv_phone']); |
|
329 | + $address = sanitize_text_field($data['wpinv_address']); |
|
330 | + $city = sanitize_text_field($data['wpinv_city']); |
|
331 | + $zip = sanitize_text_field($data['wpinv_zip']); |
|
332 | + $country = sanitize_text_field($data['wpinv_country']); |
|
333 | + $state = sanitize_text_field($data['wpinv_state']); |
|
334 | 334 | |
335 | 335 | // Details |
336 | - $status = sanitize_text_field( $data['wpinv_status'] ); |
|
337 | - $old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status; |
|
338 | - $number = sanitize_text_field( $data['wpinv_number'] ); |
|
339 | - $due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : ''; |
|
336 | + $status = sanitize_text_field($data['wpinv_status']); |
|
337 | + $old_status = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status; |
|
338 | + $number = sanitize_text_field($data['wpinv_number']); |
|
339 | + $due_date = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : ''; |
|
340 | 340 | //$discounts = sanitize_text_field( $data['wpinv_discounts'] ); |
341 | 341 | //$discount = sanitize_text_field( $data['wpinv_discount'] ); |
342 | 342 | |
343 | - $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
343 | + $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
344 | 344 | |
345 | - $invoice->set( 'due_date', $due_date ); |
|
346 | - $invoice->set( 'first_name', $first_name ); |
|
347 | - $invoice->set( 'last_name', $last_name ); |
|
348 | - $invoice->set( 'company', $company ); |
|
349 | - $invoice->set( 'vat_number', $vat_number ); |
|
350 | - $invoice->set( 'phone', $phone ); |
|
351 | - $invoice->set( 'address', $address ); |
|
352 | - $invoice->set( 'city', $city ); |
|
353 | - $invoice->set( 'zip', $zip ); |
|
354 | - $invoice->set( 'country', $country ); |
|
355 | - $invoice->set( 'state', $state ); |
|
356 | - $invoice->set( 'status', $status ); |
|
357 | - $invoice->set( 'number', $number ); |
|
345 | + $invoice->set('due_date', $due_date); |
|
346 | + $invoice->set('first_name', $first_name); |
|
347 | + $invoice->set('last_name', $last_name); |
|
348 | + $invoice->set('company', $company); |
|
349 | + $invoice->set('vat_number', $vat_number); |
|
350 | + $invoice->set('phone', $phone); |
|
351 | + $invoice->set('address', $address); |
|
352 | + $invoice->set('city', $city); |
|
353 | + $invoice->set('zip', $zip); |
|
354 | + $invoice->set('country', $country); |
|
355 | + $invoice->set('state', $state); |
|
356 | + $invoice->set('status', $status); |
|
357 | + $invoice->set('number', $number); |
|
358 | 358 | //$invoice->set( 'discounts', $discounts ); |
359 | 359 | //$invoice->set( 'discount', $discount ); |
360 | - $invoice->set( 'ip', $ip ); |
|
360 | + $invoice->set('ip', $ip); |
|
361 | 361 | $invoice->old_status = $_POST['original_post_status']; |
362 | 362 | $invoice->currency = wpinv_get_currency(); |
363 | - if ( !empty( $data['wpinv_gateway'] ) ) { |
|
364 | - $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) ); |
|
363 | + if (!empty($data['wpinv_gateway'])) { |
|
364 | + $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway'])); |
|
365 | 365 | } |
366 | 366 | $saved = $invoice->save(); |
367 | 367 | |
368 | 368 | // Check for payment notes |
369 | - if ( !empty( $data['invoice_note'] ) ) { |
|
370 | - $note = wp_kses( $data['invoice_note'], array() ); |
|
371 | - $note_type = sanitize_text_field( $data['invoice_note_type'] ); |
|
369 | + if (!empty($data['invoice_note'])) { |
|
370 | + $note = wp_kses($data['invoice_note'], array()); |
|
371 | + $note_type = sanitize_text_field($data['invoice_note_type']); |
|
372 | 372 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
373 | 373 | |
374 | - wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note ); |
|
374 | + wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | // Update user address if empty. |
378 | - if ( $saved && !empty( $invoice ) ) { |
|
379 | - if ( $user_id = $invoice->get_user_id() ) { |
|
380 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
378 | + if ($saved && !empty($invoice)) { |
|
379 | + if ($user_id = $invoice->get_user_id()) { |
|
380 | + $user_address = wpinv_get_user_address($user_id, false); |
|
381 | 381 | |
382 | 382 | if (empty($user_address['first_name'])) { |
383 | - update_user_meta( $user_id, '_wpinv_first_name', $first_name ); |
|
384 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
383 | + update_user_meta($user_id, '_wpinv_first_name', $first_name); |
|
384 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
385 | 385 | } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { |
386 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
386 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { |
390 | - update_user_meta( $user_id, '_wpinv_address', $address ); |
|
391 | - update_user_meta( $user_id, '_wpinv_city', $city ); |
|
392 | - update_user_meta( $user_id, '_wpinv_state', $state ); |
|
393 | - update_user_meta( $user_id, '_wpinv_country', $country ); |
|
394 | - update_user_meta( $user_id, '_wpinv_zip', $zip ); |
|
395 | - update_user_meta( $user_id, '_wpinv_phone', $phone ); |
|
390 | + update_user_meta($user_id, '_wpinv_address', $address); |
|
391 | + update_user_meta($user_id, '_wpinv_city', $city); |
|
392 | + update_user_meta($user_id, '_wpinv_state', $state); |
|
393 | + update_user_meta($user_id, '_wpinv_country', $country); |
|
394 | + update_user_meta($user_id, '_wpinv_zip', $zip); |
|
395 | + update_user_meta($user_id, '_wpinv_phone', $phone); |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | |
399 | - do_action( 'wpinv_invoice_metabox_saveed', $invoice ); |
|
399 | + do_action('wpinv_invoice_metabox_saveed', $invoice); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | return $saved; |
@@ -1,66 +1,66 @@ 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 | -function wpinv_get_option( $key = '', $default = false ) { |
|
7 | +function wpinv_get_option($key = '', $default = false) { |
|
8 | 8 | global $wpinv_options; |
9 | 9 | |
10 | - $value = isset( $wpinv_options[ $key ] ) ? $wpinv_options[ $key ] : $default; |
|
11 | - $value = apply_filters( 'wpinv_get_option', $value, $key, $default ); |
|
10 | + $value = isset($wpinv_options[$key]) ? $wpinv_options[$key] : $default; |
|
11 | + $value = apply_filters('wpinv_get_option', $value, $key, $default); |
|
12 | 12 | |
13 | - return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default ); |
|
13 | + return apply_filters('wpinv_get_option_' . $key, $value, $key, $default); |
|
14 | 14 | } |
15 | 15 | |
16 | -function wpinv_update_option( $key = '', $value = false ) { |
|
16 | +function wpinv_update_option($key = '', $value = false) { |
|
17 | 17 | // If no key, exit |
18 | - if ( empty( $key ) ) { |
|
18 | + if (empty($key)) { |
|
19 | 19 | return false; |
20 | 20 | } |
21 | 21 | |
22 | - if ( empty( $value ) ) { |
|
23 | - $remove_option = wpinv_delete_option( $key ); |
|
22 | + if (empty($value)) { |
|
23 | + $remove_option = wpinv_delete_option($key); |
|
24 | 24 | return $remove_option; |
25 | 25 | } |
26 | 26 | |
27 | 27 | // First let's grab the current settings |
28 | - $options = get_option( 'wpinv_settings' ); |
|
28 | + $options = get_option('wpinv_settings'); |
|
29 | 29 | |
30 | 30 | // Let's let devs alter that value coming in |
31 | - $value = apply_filters( 'wpinv_update_option', $value, $key ); |
|
31 | + $value = apply_filters('wpinv_update_option', $value, $key); |
|
32 | 32 | |
33 | 33 | // Next let's try to update the value |
34 | - $options[ $key ] = $value; |
|
35 | - $did_update = update_option( 'wpinv_settings', $options ); |
|
34 | + $options[$key] = $value; |
|
35 | + $did_update = update_option('wpinv_settings', $options); |
|
36 | 36 | |
37 | 37 | // If it updated, let's update the global variable |
38 | - if ( $did_update ) { |
|
38 | + if ($did_update) { |
|
39 | 39 | global $wpinv_options; |
40 | - $wpinv_options[ $key ] = $value; |
|
40 | + $wpinv_options[$key] = $value; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | return $did_update; |
44 | 44 | } |
45 | 45 | |
46 | -function wpinv_delete_option( $key = '' ) { |
|
46 | +function wpinv_delete_option($key = '') { |
|
47 | 47 | // If no key, exit |
48 | - if ( empty( $key ) ) { |
|
48 | + if (empty($key)) { |
|
49 | 49 | return false; |
50 | 50 | } |
51 | 51 | |
52 | 52 | // First let's grab the current settings |
53 | - $options = get_option( 'wpinv_settings' ); |
|
53 | + $options = get_option('wpinv_settings'); |
|
54 | 54 | |
55 | 55 | // Next let's try to update the value |
56 | - if( isset( $options[ $key ] ) ) { |
|
57 | - unset( $options[ $key ] ); |
|
56 | + if (isset($options[$key])) { |
|
57 | + unset($options[$key]); |
|
58 | 58 | } |
59 | 59 | |
60 | - $did_update = update_option( 'wpinv_settings', $options ); |
|
60 | + $did_update = update_option('wpinv_settings', $options); |
|
61 | 61 | |
62 | 62 | // If it updated, let's update the global variable |
63 | - if ( $did_update ){ |
|
63 | + if ($did_update) { |
|
64 | 64 | global $wpinv_options; |
65 | 65 | $wpinv_options = $options; |
66 | 66 | } |
@@ -69,37 +69,37 @@ discard block |
||
69 | 69 | } |
70 | 70 | |
71 | 71 | function wpinv_get_settings() { |
72 | - $settings = get_option( 'wpinv_settings' ); |
|
72 | + $settings = get_option('wpinv_settings'); |
|
73 | 73 | |
74 | - if ( empty( $settings ) ) { |
|
74 | + if (empty($settings)) { |
|
75 | 75 | // Update old settings with new single option |
76 | - $general_settings = is_array( get_option( 'wpinv_settings_general' ) ) ? get_option( 'wpinv_settings_general' ) : array(); |
|
77 | - $gateways_settings = is_array( get_option( 'wpinv_settings_gateways' ) ) ? get_option( 'wpinv_settings_gateways' ) : array(); |
|
78 | - $email_settings = is_array( get_option( 'wpinv_settings_emails' ) ) ? get_option( 'wpinv_settings_emails' ) : array(); |
|
79 | - $tax_settings = is_array( get_option( 'wpinv_settings_taxes' ) ) ? get_option( 'wpinv_settings_taxes' ) : array(); |
|
80 | - $misc_settings = is_array( get_option( 'wpinv_settings_misc' ) ) ? get_option( 'wpinv_settings_misc' ) : array(); |
|
81 | - $tool_settings = is_array( get_option( 'wpinv_settings_tools' ) ) ? get_option( 'wpinv_settings_tools' ) : array(); |
|
76 | + $general_settings = is_array(get_option('wpinv_settings_general')) ? get_option('wpinv_settings_general') : array(); |
|
77 | + $gateways_settings = is_array(get_option('wpinv_settings_gateways')) ? get_option('wpinv_settings_gateways') : array(); |
|
78 | + $email_settings = is_array(get_option('wpinv_settings_emails')) ? get_option('wpinv_settings_emails') : array(); |
|
79 | + $tax_settings = is_array(get_option('wpinv_settings_taxes')) ? get_option('wpinv_settings_taxes') : array(); |
|
80 | + $misc_settings = is_array(get_option('wpinv_settings_misc')) ? get_option('wpinv_settings_misc') : array(); |
|
81 | + $tool_settings = is_array(get_option('wpinv_settings_tools')) ? get_option('wpinv_settings_tools') : array(); |
|
82 | 82 | |
83 | - $settings = array_merge( $general_settings, $gateways_settings, $tax_settings, $tool_settings ); |
|
83 | + $settings = array_merge($general_settings, $gateways_settings, $tax_settings, $tool_settings); |
|
84 | 84 | |
85 | - update_option( 'wpinv_settings', $settings ); |
|
85 | + update_option('wpinv_settings', $settings); |
|
86 | 86 | |
87 | 87 | } |
88 | - return apply_filters( 'wpinv_get_settings', $settings ); |
|
88 | + return apply_filters('wpinv_get_settings', $settings); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | function wpinv_register_settings() { |
92 | - if ( false == get_option( 'wpinv_settings' ) ) { |
|
93 | - add_option( 'wpinv_settings' ); |
|
92 | + if (false == get_option('wpinv_settings')) { |
|
93 | + add_option('wpinv_settings'); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | $register_settings = wpinv_get_registered_settings(); |
97 | 97 | |
98 | - foreach ( $register_settings as $tab => $sections ) { |
|
99 | - foreach ( $sections as $section => $settings) { |
|
98 | + foreach ($register_settings as $tab => $sections) { |
|
99 | + foreach ($sections as $section => $settings) { |
|
100 | 100 | // Check for backwards compatibility |
101 | - $section_tabs = wpinv_get_settings_tab_sections( $tab ); |
|
102 | - if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) { |
|
101 | + $section_tabs = wpinv_get_settings_tab_sections($tab); |
|
102 | + if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) { |
|
103 | 103 | $section = 'main'; |
104 | 104 | $settings = $sections; |
105 | 105 | } |
@@ -111,42 +111,42 @@ discard block |
||
111 | 111 | 'wpinv_settings_' . $tab . '_' . $section |
112 | 112 | ); |
113 | 113 | |
114 | - foreach ( $settings as $option ) { |
|
114 | + foreach ($settings as $option) { |
|
115 | 115 | // For backwards compatibility |
116 | - if ( empty( $option['id'] ) ) { |
|
116 | + if (empty($option['id'])) { |
|
117 | 117 | continue; |
118 | 118 | } |
119 | 119 | |
120 | - $name = isset( $option['name'] ) ? $option['name'] : ''; |
|
120 | + $name = isset($option['name']) ? $option['name'] : ''; |
|
121 | 121 | |
122 | 122 | add_settings_field( |
123 | 123 | 'wpinv_settings[' . $option['id'] . ']', |
124 | 124 | $name, |
125 | - function_exists( 'wpinv_' . $option['type'] . '_callback' ) ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback', |
|
125 | + function_exists('wpinv_' . $option['type'] . '_callback') ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback', |
|
126 | 126 | 'wpinv_settings_' . $tab . '_' . $section, |
127 | 127 | 'wpinv_settings_' . $tab . '_' . $section, |
128 | 128 | array( |
129 | 129 | 'section' => $section, |
130 | - 'id' => isset( $option['id'] ) ? $option['id'] : null, |
|
131 | - 'desc' => ! empty( $option['desc'] ) ? $option['desc'] : '', |
|
132 | - 'name' => isset( $option['name'] ) ? $option['name'] : null, |
|
133 | - 'size' => isset( $option['size'] ) ? $option['size'] : null, |
|
134 | - 'options' => isset( $option['options'] ) ? $option['options'] : '', |
|
135 | - 'selected' => isset( $option['selected'] ) ? $option['selected'] : null, |
|
136 | - 'std' => isset( $option['std'] ) ? $option['std'] : '', |
|
137 | - 'min' => isset( $option['min'] ) ? $option['min'] : null, |
|
138 | - 'max' => isset( $option['max'] ) ? $option['max'] : null, |
|
139 | - 'step' => isset( $option['step'] ) ? $option['step'] : null, |
|
140 | - 'chosen' => isset( $option['chosen'] ) ? $option['chosen'] : null, |
|
141 | - 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null, |
|
142 | - 'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true, |
|
143 | - 'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false, |
|
144 | - 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
|
145 | - 'onchange' => !empty( $option['onchange'] ) ? $option['onchange'] : '', |
|
146 | - 'custom' => !empty( $option['custom'] ) ? $option['custom'] : '', |
|
147 | - 'class' => !empty( $option['class'] ) ? $option['class'] : '', |
|
148 | - 'cols' => !empty( $option['cols'] ) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50, |
|
149 | - 'rows' => !empty( $option['rows'] ) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5, |
|
130 | + 'id' => isset($option['id']) ? $option['id'] : null, |
|
131 | + 'desc' => !empty($option['desc']) ? $option['desc'] : '', |
|
132 | + 'name' => isset($option['name']) ? $option['name'] : null, |
|
133 | + 'size' => isset($option['size']) ? $option['size'] : null, |
|
134 | + 'options' => isset($option['options']) ? $option['options'] : '', |
|
135 | + 'selected' => isset($option['selected']) ? $option['selected'] : null, |
|
136 | + 'std' => isset($option['std']) ? $option['std'] : '', |
|
137 | + 'min' => isset($option['min']) ? $option['min'] : null, |
|
138 | + 'max' => isset($option['max']) ? $option['max'] : null, |
|
139 | + 'step' => isset($option['step']) ? $option['step'] : null, |
|
140 | + 'chosen' => isset($option['chosen']) ? $option['chosen'] : null, |
|
141 | + 'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null, |
|
142 | + 'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true, |
|
143 | + 'readonly' => isset($option['readonly']) ? $option['readonly'] : false, |
|
144 | + 'faux' => isset($option['faux']) ? $option['faux'] : false, |
|
145 | + 'onchange' => !empty($option['onchange']) ? $option['onchange'] : '', |
|
146 | + 'custom' => !empty($option['custom']) ? $option['custom'] : '', |
|
147 | + 'class' => !empty($option['class']) ? $option['class'] : '', |
|
148 | + 'cols' => !empty($option['cols']) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50, |
|
149 | + 'rows' => !empty($option['rows']) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5, |
|
150 | 150 | ) |
151 | 151 | ); |
152 | 152 | } |
@@ -154,21 +154,21 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | // Creates our settings in the options table |
157 | - register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' ); |
|
157 | + register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize'); |
|
158 | 158 | } |
159 | -add_action( 'admin_init', 'wpinv_register_settings' ); |
|
159 | +add_action('admin_init', 'wpinv_register_settings'); |
|
160 | 160 | |
161 | 161 | function wpinv_get_registered_settings() { |
162 | - $pages = wpinv_get_pages( true ); |
|
162 | + $pages = wpinv_get_pages(true); |
|
163 | 163 | |
164 | 164 | $due_payment_options = array(); |
165 | - $due_payment_options[0] = __( 'Now', 'invoicing' ); |
|
166 | - for ( $i = 1; $i <= 30; $i++ ) { |
|
165 | + $due_payment_options[0] = __('Now', 'invoicing'); |
|
166 | + for ($i = 1; $i <= 30; $i++) { |
|
167 | 167 | $due_payment_options[$i] = $i; |
168 | 168 | } |
169 | 169 | |
170 | 170 | $invoice_number_padd_options = array(); |
171 | - for ( $i = 0; $i <= 20; $i++ ) { |
|
171 | + for ($i = 0; $i <= 20; $i++) { |
|
172 | 172 | $invoice_number_padd_options[$i] = $i; |
173 | 173 | } |
174 | 174 | |
@@ -177,141 +177,141 @@ discard block |
||
177 | 177 | $alert_wrapper_start = '<p style="color: #F00">'; |
178 | 178 | $alert_wrapper_close = '</p>'; |
179 | 179 | $wpinv_settings = array( |
180 | - 'general' => apply_filters( 'wpinv_settings_general', |
|
180 | + 'general' => apply_filters('wpinv_settings_general', |
|
181 | 181 | array( |
182 | 182 | 'main' => array( |
183 | 183 | 'location_settings' => array( |
184 | 184 | 'id' => 'location_settings', |
185 | - 'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>', |
|
185 | + 'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>', |
|
186 | 186 | 'desc' => '', |
187 | 187 | 'type' => 'header', |
188 | 188 | ), |
189 | 189 | 'default_country' => array( |
190 | 190 | 'id' => 'default_country', |
191 | - 'name' => __( 'Default Country', 'invoicing' ), |
|
192 | - 'desc' => __( 'Where does your store operate from?', 'invoicing' ), |
|
191 | + 'name' => __('Default Country', 'invoicing'), |
|
192 | + 'desc' => __('Where does your store operate from?', 'invoicing'), |
|
193 | 193 | 'type' => 'select', |
194 | 194 | 'options' => wpinv_get_country_list(), |
195 | 195 | 'std' => 'GB', |
196 | 196 | 'chosen' => true, |
197 | - 'placeholder' => __( 'Select a country', 'invoicing' ), |
|
197 | + 'placeholder' => __('Select a country', 'invoicing'), |
|
198 | 198 | ), |
199 | 199 | 'default_state' => array( |
200 | 200 | 'id' => 'default_state', |
201 | - 'name' => __( 'Default State / Province', 'invoicing' ), |
|
202 | - 'desc' => __( 'What state / province does your store operate from?', 'invoicing' ), |
|
201 | + 'name' => __('Default State / Province', 'invoicing'), |
|
202 | + 'desc' => __('What state / province does your store operate from?', 'invoicing'), |
|
203 | 203 | 'type' => 'country_states', |
204 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
204 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
205 | 205 | ), |
206 | 206 | 'store_name' => array( |
207 | 207 | 'id' => 'store_name', |
208 | - 'name' => __( 'Store Name', 'invoicing' ), |
|
209 | - 'desc' => __( 'Store name to print on invoices.', 'invoicing' ), |
|
208 | + 'name' => __('Store Name', 'invoicing'), |
|
209 | + 'desc' => __('Store name to print on invoices.', 'invoicing'), |
|
210 | 210 | 'std' => get_option('blogname'), |
211 | 211 | 'type' => 'text', |
212 | 212 | ), |
213 | 213 | 'logo' => array( |
214 | 214 | 'id' => 'logo', |
215 | - 'name' => __( 'Logo URL', 'invoicing' ), |
|
216 | - 'desc' => __( 'Store logo to print on invoices.', 'invoicing' ), |
|
215 | + 'name' => __('Logo URL', 'invoicing'), |
|
216 | + 'desc' => __('Store logo to print on invoices.', 'invoicing'), |
|
217 | 217 | 'type' => 'text', |
218 | 218 | ), |
219 | 219 | 'store_address' => array( |
220 | 220 | 'id' => 'store_address', |
221 | - 'name' => __( 'Store Address', 'invoicing' ), |
|
222 | - 'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ), |
|
221 | + 'name' => __('Store Address', 'invoicing'), |
|
222 | + 'desc' => __('Enter the store address to display on invoice', 'invoicing'), |
|
223 | 223 | 'type' => 'textarea', |
224 | 224 | ), |
225 | 225 | 'page_settings' => array( |
226 | 226 | 'id' => 'page_settings', |
227 | - 'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>', |
|
227 | + 'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>', |
|
228 | 228 | 'desc' => '', |
229 | 229 | 'type' => 'header', |
230 | 230 | ), |
231 | 231 | 'checkout_page' => array( |
232 | 232 | 'id' => 'checkout_page', |
233 | - 'name' => __( 'Checkout Page', 'invoicing' ), |
|
234 | - 'desc' => __( 'This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing' ), |
|
233 | + 'name' => __('Checkout Page', 'invoicing'), |
|
234 | + 'desc' => __('This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing'), |
|
235 | 235 | 'type' => 'select', |
236 | 236 | 'options' => $pages, |
237 | 237 | 'chosen' => true, |
238 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
238 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
239 | 239 | ), |
240 | 240 | 'success_page' => array( |
241 | 241 | 'id' => 'success_page', |
242 | - 'name' => __( 'Success Page', 'invoicing' ), |
|
243 | - 'desc' => __( 'This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing' ), |
|
242 | + 'name' => __('Success Page', 'invoicing'), |
|
243 | + 'desc' => __('This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing'), |
|
244 | 244 | 'type' => 'select', |
245 | 245 | 'options' => $pages, |
246 | 246 | 'chosen' => true, |
247 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
247 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
248 | 248 | ), |
249 | 249 | 'failure_page' => array( |
250 | 250 | 'id' => 'failure_page', |
251 | - 'name' => __( 'Failed Transaction Page', 'invoicing' ), |
|
252 | - 'desc' => __( 'This is the page buyers are sent to if their transaction is cancelled or fails', 'invoicing' ), |
|
251 | + 'name' => __('Failed Transaction Page', 'invoicing'), |
|
252 | + 'desc' => __('This is the page buyers are sent to if their transaction is cancelled or fails', 'invoicing'), |
|
253 | 253 | 'type' => 'select', |
254 | 254 | 'options' => $pages, |
255 | 255 | 'chosen' => true, |
256 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
256 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
257 | 257 | ), |
258 | 258 | 'invoice_history_page' => array( |
259 | 259 | 'id' => 'invoice_history_page', |
260 | - 'name' => __( 'Invoice History Page', 'invoicing' ), |
|
261 | - 'desc' => __( 'This page shows a invoice history for the current user', 'invoicing' ), |
|
260 | + 'name' => __('Invoice History Page', 'invoicing'), |
|
261 | + 'desc' => __('This page shows a invoice history for the current user', 'invoicing'), |
|
262 | 262 | 'type' => 'select', |
263 | 263 | 'options' => $pages, |
264 | 264 | 'chosen' => true, |
265 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
265 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
266 | 266 | ) |
267 | 267 | ), |
268 | 268 | 'currency_section' => array( |
269 | 269 | 'currency_settings' => array( |
270 | 270 | 'id' => 'currency_settings', |
271 | - 'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>', |
|
271 | + 'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>', |
|
272 | 272 | 'desc' => '', |
273 | 273 | 'type' => 'header', |
274 | 274 | ), |
275 | 275 | 'currency' => array( |
276 | 276 | 'id' => 'currency', |
277 | - 'name' => __( 'Currency', 'invoicing' ), |
|
278 | - 'desc' => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ), |
|
277 | + 'name' => __('Currency', 'invoicing'), |
|
278 | + 'desc' => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'), |
|
279 | 279 | 'type' => 'select', |
280 | 280 | 'options' => wpinv_get_currencies(), |
281 | 281 | 'chosen' => true, |
282 | 282 | ), |
283 | 283 | 'currency_position' => array( |
284 | 284 | 'id' => 'currency_position', |
285 | - 'name' => __( 'Currency Position', 'invoicing' ), |
|
286 | - 'desc' => __( 'Choose the location of the currency sign.', 'invoicing' ), |
|
285 | + 'name' => __('Currency Position', 'invoicing'), |
|
286 | + 'desc' => __('Choose the location of the currency sign.', 'invoicing'), |
|
287 | 287 | 'type' => 'select', |
288 | 288 | 'options' => array( |
289 | - 'left' => __( 'Left', 'invoicing' ) . ' (' . $currency_symbol . wpinv_format_amount( '99.99' ) . ')', |
|
290 | - 'right' => __( 'Right', 'invoicing' ) . ' ('. wpinv_format_amount( '99.99' ) . $currency_symbol . ')', |
|
291 | - 'left_space' => __( 'Left with space', 'invoicing' ) . ' (' . $currency_symbol . ' ' . wpinv_format_amount( '99.99' ) . ')', |
|
292 | - 'right_space' => __( 'Right with space', 'invoicing' ) . ' (' . wpinv_format_amount( '99.99' ) . ' ' . $currency_symbol . ')' |
|
289 | + 'left' => __('Left', 'invoicing') . ' (' . $currency_symbol . wpinv_format_amount('99.99') . ')', |
|
290 | + 'right' => __('Right', 'invoicing') . ' (' . wpinv_format_amount('99.99') . $currency_symbol . ')', |
|
291 | + 'left_space' => __('Left with space', 'invoicing') . ' (' . $currency_symbol . ' ' . wpinv_format_amount('99.99') . ')', |
|
292 | + 'right_space' => __('Right with space', 'invoicing') . ' (' . wpinv_format_amount('99.99') . ' ' . $currency_symbol . ')' |
|
293 | 293 | ) |
294 | 294 | ), |
295 | 295 | 'thousands_separator' => array( |
296 | 296 | 'id' => 'thousands_separator', |
297 | - 'name' => __( 'Thousands Separator', 'invoicing' ), |
|
298 | - 'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ), |
|
297 | + 'name' => __('Thousands Separator', 'invoicing'), |
|
298 | + 'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'), |
|
299 | 299 | 'type' => 'text', |
300 | 300 | 'size' => 'small', |
301 | 301 | 'std' => ',', |
302 | 302 | ), |
303 | 303 | 'decimal_separator' => array( |
304 | 304 | 'id' => 'decimal_separator', |
305 | - 'name' => __( 'Decimal Separator', 'invoicing' ), |
|
306 | - 'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ), |
|
305 | + 'name' => __('Decimal Separator', 'invoicing'), |
|
306 | + 'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'), |
|
307 | 307 | 'type' => 'text', |
308 | 308 | 'size' => 'small', |
309 | 309 | 'std' => '.', |
310 | 310 | ), |
311 | 311 | 'decimals' => array( |
312 | 312 | 'id' => 'decimals', |
313 | - 'name' => __( 'Number of Decimals', 'invoicing' ), |
|
314 | - 'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ), |
|
313 | + 'name' => __('Number of Decimals', 'invoicing'), |
|
314 | + 'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'), |
|
315 | 315 | 'type' => 'number', |
316 | 316 | 'size' => 'small', |
317 | 317 | 'std' => '2', |
@@ -323,29 +323,29 @@ discard block |
||
323 | 323 | 'labels' => array( |
324 | 324 | 'labels' => array( |
325 | 325 | 'id' => 'labels_settings', |
326 | - 'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>', |
|
326 | + 'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>', |
|
327 | 327 | 'desc' => '', |
328 | 328 | 'type' => 'header', |
329 | 329 | ), |
330 | 330 | 'vat_name' => array( |
331 | 331 | 'id' => 'vat_name', |
332 | - 'name' => __( 'VAT Name', 'invoicing' ), |
|
333 | - 'desc' => __( 'Enter the VAT name', 'invoicing' ), |
|
332 | + 'name' => __('VAT Name', 'invoicing'), |
|
333 | + 'desc' => __('Enter the VAT name', 'invoicing'), |
|
334 | 334 | 'type' => 'text', |
335 | 335 | 'size' => 'regular', |
336 | 336 | 'std' => 'VAT' |
337 | 337 | ), |
338 | 338 | 'vat_invoice_notice_label' => array( |
339 | 339 | 'id' => 'vat_invoice_notice_label', |
340 | - 'name' => __( 'Invoice notice label', 'invoicing' ), |
|
341 | - 'desc' => __( 'Use this to add a invoice notice section (label) to your invoices', 'invoicing' ), |
|
340 | + 'name' => __('Invoice notice label', 'invoicing'), |
|
341 | + 'desc' => __('Use this to add a invoice notice section (label) to your invoices', 'invoicing'), |
|
342 | 342 | 'type' => 'text', |
343 | 343 | 'size' => 'regular', |
344 | 344 | ), |
345 | 345 | 'vat_invoice_notice' => array( |
346 | 346 | 'id' => 'vat_invoice_notice', |
347 | - 'name' => __( 'Invoice notice', 'invoicing' ), |
|
348 | - 'desc' => __( 'Use this to add a invoice notice section (description) to your invoices', 'invoicing' ), |
|
347 | + 'name' => __('Invoice notice', 'invoicing'), |
|
348 | + 'desc' => __('Use this to add a invoice notice section (description) to your invoices', 'invoicing'), |
|
349 | 349 | 'type' => 'text', |
350 | 350 | 'size' => 'regular', |
351 | 351 | ) |
@@ -357,22 +357,22 @@ discard block |
||
357 | 357 | 'main' => array( |
358 | 358 | 'gateway_settings' => array( |
359 | 359 | 'id' => 'api_header', |
360 | - 'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>', |
|
360 | + 'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>', |
|
361 | 361 | 'desc' => '', |
362 | 362 | 'type' => 'header', |
363 | 363 | ), |
364 | 364 | 'gateways' => array( |
365 | 365 | 'id' => 'gateways', |
366 | - 'name' => __( 'Payment Gateways', 'invoicing' ), |
|
367 | - 'desc' => __( 'Choose the payment gateways you want to enable.', 'invoicing' ), |
|
366 | + 'name' => __('Payment Gateways', 'invoicing'), |
|
367 | + 'desc' => __('Choose the payment gateways you want to enable.', 'invoicing'), |
|
368 | 368 | 'type' => 'gateways', |
369 | 369 | 'std' => array('manual'=>1), |
370 | 370 | 'options' => wpinv_get_payment_gateways(), |
371 | 371 | ), |
372 | 372 | 'default_gateway' => array( |
373 | 373 | 'id' => 'default_gateway', |
374 | - 'name' => __( 'Default Gateway', 'invoicing' ), |
|
375 | - 'desc' => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ), |
|
374 | + 'name' => __('Default Gateway', 'invoicing'), |
|
375 | + 'desc' => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'), |
|
376 | 376 | 'type' => 'gateway_select', |
377 | 377 | 'std' => 'manual', |
378 | 378 | 'options' => wpinv_get_payment_gateways(), |
@@ -386,19 +386,19 @@ discard block |
||
386 | 386 | 'main' => array( |
387 | 387 | 'tax_settings' => array( |
388 | 388 | 'id' => 'tax_settings', |
389 | - 'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>', |
|
389 | + 'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>', |
|
390 | 390 | 'type' => 'header', |
391 | 391 | ), |
392 | 392 | 'enable_taxes' => array( |
393 | 393 | 'id' => 'enable_taxes', |
394 | - 'name' => __( 'Enable Taxes', 'invoicing' ), |
|
395 | - 'desc' => __( 'Check this to enable taxes on invoices.', 'invoicing' ), |
|
394 | + 'name' => __('Enable Taxes', 'invoicing'), |
|
395 | + 'desc' => __('Check this to enable taxes on invoices.', 'invoicing'), |
|
396 | 396 | 'type' => 'checkbox', |
397 | 397 | ), |
398 | 398 | 'tax_rate' => array( |
399 | 399 | 'id' => 'tax_rate', |
400 | - 'name' => __( 'Fallback Tax Rate', 'invoicing' ), |
|
401 | - 'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ), |
|
400 | + 'name' => __('Fallback Tax Rate', 'invoicing'), |
|
401 | + 'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'), |
|
402 | 402 | 'type' => 'number', |
403 | 403 | 'size' => 'small', |
404 | 404 | 'min' => '0', |
@@ -410,8 +410,8 @@ discard block |
||
410 | 410 | 'rates' => array( |
411 | 411 | 'tax_rates' => array( |
412 | 412 | 'id' => 'tax_rates', |
413 | - 'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>', |
|
414 | - 'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ), |
|
413 | + 'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>', |
|
414 | + 'desc' => __('Enter tax rates for specific regions.', 'invoicing'), |
|
415 | 415 | 'type' => 'tax_rates', |
416 | 416 | ), |
417 | 417 | ) |
@@ -423,62 +423,62 @@ discard block |
||
423 | 423 | 'main' => array( |
424 | 424 | 'email_settings_header' => array( |
425 | 425 | 'id' => 'email_settings_header', |
426 | - 'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>', |
|
426 | + 'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>', |
|
427 | 427 | 'type' => 'header', |
428 | 428 | ), |
429 | 429 | 'email_from_name' => array( |
430 | 430 | 'id' => 'email_from_name', |
431 | - 'name' => __( 'From Name', 'invoicing' ), |
|
432 | - 'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ), |
|
433 | - 'std' => esc_attr( get_bloginfo( 'name', 'display' ) ), |
|
431 | + 'name' => __('From Name', 'invoicing'), |
|
432 | + 'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'), |
|
433 | + 'std' => esc_attr(get_bloginfo('name', 'display')), |
|
434 | 434 | 'type' => 'text', |
435 | 435 | ), |
436 | 436 | 'email_from' => array( |
437 | 437 | 'id' => 'email_from', |
438 | - 'name' => __( 'From Email', 'invoicing' ), |
|
439 | - 'desc' => sprintf (__( 'Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing' ), $alert_wrapper_start, $alert_wrapper_close), |
|
440 | - 'std' => get_option( 'admin_email' ), |
|
438 | + 'name' => __('From Email', 'invoicing'), |
|
439 | + 'desc' => sprintf(__('Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing'), $alert_wrapper_start, $alert_wrapper_close), |
|
440 | + 'std' => get_option('admin_email'), |
|
441 | 441 | 'type' => 'text', |
442 | 442 | ), |
443 | 443 | 'overdue_settings_header' => array( |
444 | 444 | 'id' => 'overdue_settings_header', |
445 | - 'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>', |
|
445 | + 'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>', |
|
446 | 446 | 'type' => 'header', |
447 | 447 | ), |
448 | 448 | 'overdue_active' => array( |
449 | 449 | 'id' => 'overdue_active', |
450 | - 'name' => __( 'Enable Due Date', 'invoicing' ), |
|
451 | - 'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ), |
|
450 | + 'name' => __('Enable Due Date', 'invoicing'), |
|
451 | + 'desc' => __('Check this to enable due date option for invoices.', 'invoicing'), |
|
452 | 452 | 'type' => 'checkbox', |
453 | 453 | 'std' => false, |
454 | 454 | ), |
455 | 455 | 'overdue_days' => array( |
456 | 456 | 'id' => 'overdue_days', |
457 | - 'name' => __( 'Default Due Date', 'invoicing' ), |
|
458 | - 'desc' => __( 'Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing' ), |
|
457 | + 'name' => __('Default Due Date', 'invoicing'), |
|
458 | + 'desc' => __('Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing'), |
|
459 | 459 | 'type' => 'select', |
460 | 460 | 'options' => $due_payment_options, |
461 | 461 | 'chosen' => true, |
462 | 462 | 'std' => 0, |
463 | - 'placeholder' => __( 'Select a page', 'invoicing' ), |
|
463 | + 'placeholder' => __('Select a page', 'invoicing'), |
|
464 | 464 | ), |
465 | 465 | 'email_template_header' => array( |
466 | 466 | 'id' => 'email_template_header', |
467 | - 'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>', |
|
467 | + 'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>', |
|
468 | 468 | 'type' => 'header', |
469 | 469 | ), |
470 | 470 | 'email_header_image' => array( |
471 | 471 | 'id' => 'email_header_image', |
472 | - 'name' => __( 'Header Image', 'invoicing' ), |
|
473 | - 'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ), |
|
472 | + 'name' => __('Header Image', 'invoicing'), |
|
473 | + 'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'), |
|
474 | 474 | 'std' => '', |
475 | 475 | 'type' => 'text', |
476 | 476 | ), |
477 | 477 | 'email_footer_text' => array( |
478 | 478 | 'id' => 'email_footer_text', |
479 | - 'name' => __( 'Footer Text', 'invoicing' ), |
|
480 | - 'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ), |
|
481 | - 'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GeoDirectory', 'invoicing' ), |
|
479 | + 'name' => __('Footer Text', 'invoicing'), |
|
480 | + 'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'), |
|
481 | + 'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GeoDirectory', 'invoicing'), |
|
482 | 482 | 'type' => 'textarea', |
483 | 483 | 'class' => 'regular-text', |
484 | 484 | 'rows' => 2, |
@@ -486,29 +486,29 @@ discard block |
||
486 | 486 | ), |
487 | 487 | 'email_base_color' => array( |
488 | 488 | 'id' => 'email_base_color', |
489 | - 'name' => __( 'Base Color', 'invoicing' ), |
|
490 | - 'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ), |
|
489 | + 'name' => __('Base Color', 'invoicing'), |
|
490 | + 'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'), |
|
491 | 491 | 'std' => '#557da2', |
492 | 492 | 'type' => 'color', |
493 | 493 | ), |
494 | 494 | 'email_background_color' => array( |
495 | 495 | 'id' => 'email_background_color', |
496 | - 'name' => __( 'Background Color', 'invoicing' ), |
|
497 | - 'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ), |
|
496 | + 'name' => __('Background Color', 'invoicing'), |
|
497 | + 'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'), |
|
498 | 498 | 'std' => '#f5f5f5', |
499 | 499 | 'type' => 'color', |
500 | 500 | ), |
501 | 501 | 'email_body_background_color' => array( |
502 | 502 | 'id' => 'email_body_background_color', |
503 | - 'name' => __( 'Body Background Color', 'invoicing' ), |
|
504 | - 'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ), |
|
503 | + 'name' => __('Body Background Color', 'invoicing'), |
|
504 | + 'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'), |
|
505 | 505 | 'std' => '#fdfdfd', |
506 | 506 | 'type' => 'color', |
507 | 507 | ), |
508 | 508 | 'email_text_color' => array( |
509 | 509 | 'id' => 'email_text_color', |
510 | - 'name' => __( 'Body Text Color', 'invoicing' ), |
|
511 | - 'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ), |
|
510 | + 'name' => __('Body Text Color', 'invoicing'), |
|
511 | + 'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'), |
|
512 | 512 | 'std' => '#505050', |
513 | 513 | 'type' => 'color', |
514 | 514 | ), |
@@ -527,25 +527,25 @@ discard block |
||
527 | 527 | 'main' => array( |
528 | 528 | 'fields_settings' => array( |
529 | 529 | 'id' => 'fields_settings', |
530 | - 'name' => '<h3>' . __( 'Fields Settings', 'invoicing' ) . '</h3>', |
|
530 | + 'name' => '<h3>' . __('Fields Settings', 'invoicing') . '</h3>', |
|
531 | 531 | 'type' => 'header', |
532 | 532 | ), |
533 | 533 | 'phone_mandatory' => array( |
534 | 534 | 'id' => 'phone_mandatory', |
535 | - 'name' => __( 'Phone No. Mandatory?', 'invoicing' ), |
|
536 | - 'desc' => __( 'Tick this to make phone number mandatory in invoice address fields.', 'invoicing' ), |
|
535 | + 'name' => __('Phone No. Mandatory?', 'invoicing'), |
|
536 | + 'desc' => __('Tick this to make phone number mandatory in invoice address fields.', 'invoicing'), |
|
537 | 537 | 'type' => 'checkbox', |
538 | 538 | 'std' => true, |
539 | 539 | ), |
540 | 540 | 'invoice_number_format_settings' => array( |
541 | 541 | 'id' => 'invoice_number_format_settings', |
542 | - 'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>', |
|
542 | + 'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>', |
|
543 | 543 | 'type' => 'header', |
544 | 544 | ), |
545 | 545 | 'invoice_number_padd' => array( |
546 | 546 | 'id' => 'invoice_number_padd', |
547 | - 'name' => __( 'Minimum digits', 'invoicing' ), |
|
548 | - 'desc' => __( 'If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing' ), |
|
547 | + 'name' => __('Minimum digits', 'invoicing'), |
|
548 | + 'desc' => __('If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing'), |
|
549 | 549 | 'type' => 'select', |
550 | 550 | 'options' => $invoice_number_padd_options, |
551 | 551 | 'std' => 5, |
@@ -553,8 +553,8 @@ discard block |
||
553 | 553 | ), |
554 | 554 | 'invoice_number_prefix' => array( |
555 | 555 | 'id' => 'invoice_number_prefix', |
556 | - 'name' => __( 'Invoice Number prefix', 'invoicing' ), |
|
557 | - 'desc' => __( 'A prefix to prepend to all invoice numbers. Ex: WPINV-', 'invoicing' ), |
|
556 | + 'name' => __('Invoice Number prefix', 'invoicing'), |
|
557 | + 'desc' => __('A prefix to prepend to all invoice numbers. Ex: WPINV-', 'invoicing'), |
|
558 | 558 | 'type' => 'text', |
559 | 559 | 'size' => 'regular', |
560 | 560 | 'std' => 'WPINV-', |
@@ -562,25 +562,25 @@ discard block |
||
562 | 562 | ), |
563 | 563 | 'invoice_number_postfix' => array( |
564 | 564 | 'id' => 'invoice_number_postfix', |
565 | - 'name' => __( 'Invoice Number postfix', 'invoicing' ), |
|
566 | - 'desc' => __( 'A postfix to append to all invoice numbers.', 'invoicing' ), |
|
565 | + 'name' => __('Invoice Number postfix', 'invoicing'), |
|
566 | + 'desc' => __('A postfix to append to all invoice numbers.', 'invoicing'), |
|
567 | 567 | 'type' => 'text', |
568 | 568 | 'size' => 'regular', |
569 | 569 | 'std' => '' |
570 | 570 | ), |
571 | 571 | 'guest_checkout_settings' => array( |
572 | 572 | 'id' => 'guest_checkout_settings', |
573 | - 'name' => '<h3>' . __( 'Pay via Invoice Link', 'invoicing' ) . '</h3>', |
|
573 | + 'name' => '<h3>' . __('Pay via Invoice Link', 'invoicing') . '</h3>', |
|
574 | 574 | 'type' => 'header', |
575 | 575 | ), |
576 | 576 | 'guest_checkout' => array( |
577 | 577 | 'type' => 'radio', |
578 | 578 | 'id' => 'guest_checkout', |
579 | - 'name' => __( 'Pay via Invoice Link for non logged in user', 'invoicing' ), |
|
580 | - 'desc' => __( 'Select how invoice should be paid when non logged in user clicks on the invoice link that sent to them via for pay for invoice.', 'invoicing' ), |
|
579 | + 'name' => __('Pay via Invoice Link for non logged in user', 'invoicing'), |
|
580 | + 'desc' => __('Select how invoice should be paid when non logged in user clicks on the invoice link that sent to them via for pay for invoice.', 'invoicing'), |
|
581 | 581 | 'options' => array( |
582 | - 0 => __( 'Ask them to log-in and redirect back to invoice checkout to pay.', 'invoicing' ), |
|
583 | - 1 => __( 'Auto log-in the user via invoice link and take them to invoice checkout to pay.', 'invoicing' ), |
|
582 | + 0 => __('Ask them to log-in and redirect back to invoice checkout to pay.', 'invoicing'), |
|
583 | + 1 => __('Auto log-in the user via invoice link and take them to invoice checkout to pay.', 'invoicing'), |
|
584 | 584 | ), |
585 | 585 | 'std' => 0, |
586 | 586 | ), |
@@ -593,8 +593,8 @@ discard block |
||
593 | 593 | 'main' => array( |
594 | 594 | 'tool_settings' => array( |
595 | 595 | 'id' => 'tool_settings', |
596 | - 'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>', |
|
597 | - 'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ), |
|
596 | + 'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>', |
|
597 | + 'desc' => __('Invoicing diagnostic tools', 'invoicing'), |
|
598 | 598 | 'type' => 'tools', |
599 | 599 | ), |
600 | 600 | ), |
@@ -602,135 +602,135 @@ discard block |
||
602 | 602 | ) |
603 | 603 | ); |
604 | 604 | |
605 | - return apply_filters( 'wpinv_registered_settings', $wpinv_settings ); |
|
605 | + return apply_filters('wpinv_registered_settings', $wpinv_settings); |
|
606 | 606 | } |
607 | 607 | |
608 | -function wpinv_settings_sanitize( $input = array() ) { |
|
608 | +function wpinv_settings_sanitize($input = array()) { |
|
609 | 609 | global $wpinv_options; |
610 | 610 | |
611 | - if ( empty( $_POST['_wp_http_referer'] ) ) { |
|
611 | + if (empty($_POST['_wp_http_referer'])) { |
|
612 | 612 | return $input; |
613 | 613 | } |
614 | 614 | |
615 | - parse_str( $_POST['_wp_http_referer'], $referrer ); |
|
615 | + parse_str($_POST['_wp_http_referer'], $referrer); |
|
616 | 616 | |
617 | 617 | $settings = wpinv_get_registered_settings(); |
618 | - $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
|
619 | - $section = isset( $referrer['section'] ) ? $referrer['section'] : 'main'; |
|
618 | + $tab = isset($referrer['tab']) ? $referrer['tab'] : 'general'; |
|
619 | + $section = isset($referrer['section']) ? $referrer['section'] : 'main'; |
|
620 | 620 | |
621 | 621 | $input = $input ? $input : array(); |
622 | - $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input ); |
|
623 | - $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input ); |
|
622 | + $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input); |
|
623 | + $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input); |
|
624 | 624 | |
625 | 625 | // Loop through each setting being saved and pass it through a sanitization filter |
626 | - foreach ( $input as $key => $value ) { |
|
626 | + foreach ($input as $key => $value) { |
|
627 | 627 | // Get the setting type (checkbox, select, etc) |
628 | - $type = isset( $settings[ $tab ][ $key ]['type'] ) ? $settings[ $tab ][ $key ]['type'] : false; |
|
628 | + $type = isset($settings[$tab][$key]['type']) ? $settings[$tab][$key]['type'] : false; |
|
629 | 629 | |
630 | - if ( $type ) { |
|
630 | + if ($type) { |
|
631 | 631 | // Field type specific filter |
632 | - $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key ); |
|
632 | + $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key); |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | // General filter |
636 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
636 | + $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | // Loop through the whitelist and unset any that are empty for the tab being saved |
640 | - $main_settings = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections |
|
641 | - $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array(); |
|
640 | + $main_settings = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections |
|
641 | + $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array(); |
|
642 | 642 | |
643 | - $found_settings = array_merge( $main_settings, $section_settings ); |
|
643 | + $found_settings = array_merge($main_settings, $section_settings); |
|
644 | 644 | |
645 | - if ( ! empty( $found_settings ) ) { |
|
646 | - foreach ( $found_settings as $key => $value ) { |
|
645 | + if (!empty($found_settings)) { |
|
646 | + foreach ($found_settings as $key => $value) { |
|
647 | 647 | |
648 | 648 | // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work |
649 | - if ( is_numeric( $key ) ) { |
|
649 | + if (is_numeric($key)) { |
|
650 | 650 | $key = $value['id']; |
651 | 651 | } |
652 | 652 | |
653 | - if ( empty( $input[ $key ] ) ) { |
|
654 | - unset( $wpinv_options[ $key ] ); |
|
653 | + if (empty($input[$key])) { |
|
654 | + unset($wpinv_options[$key]); |
|
655 | 655 | } |
656 | 656 | } |
657 | 657 | } |
658 | 658 | |
659 | 659 | // Merge our new settings with the existing |
660 | - $output = array_merge( $wpinv_options, $input ); |
|
660 | + $output = array_merge($wpinv_options, $input); |
|
661 | 661 | |
662 | - add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' ); |
|
662 | + add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated'); |
|
663 | 663 | |
664 | 664 | return $output; |
665 | 665 | } |
666 | 666 | |
667 | -function wpinv_settings_sanitize_misc_accounting( $input ) { |
|
667 | +function wpinv_settings_sanitize_misc_accounting($input) { |
|
668 | 668 | global $wpinv_options, $wpi_session; |
669 | 669 | |
670 | - if ( !current_user_can( 'manage_options' ) ) { |
|
670 | + if (!current_user_can('manage_options')) { |
|
671 | 671 | return $input; |
672 | 672 | } |
673 | 673 | |
674 | - if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) { |
|
674 | + if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) { |
|
675 | 675 | // Shows an admin notice about upgrading previous order numbers |
676 | - $wpi_session->set( 'upgrade_sequential', '1' ); |
|
676 | + $wpi_session->set('upgrade_sequential', '1'); |
|
677 | 677 | } |
678 | 678 | |
679 | 679 | return $input; |
680 | 680 | } |
681 | -add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' ); |
|
681 | +add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting'); |
|
682 | 682 | |
683 | -function wpinv_settings_sanitize_tax_rates( $input ) { |
|
684 | - if( !current_user_can( 'manage_options' ) ) { |
|
683 | +function wpinv_settings_sanitize_tax_rates($input) { |
|
684 | + if (!current_user_can('manage_options')) { |
|
685 | 685 | return $input; |
686 | 686 | } |
687 | 687 | |
688 | - $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array(); |
|
688 | + $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array(); |
|
689 | 689 | |
690 | 690 | $tax_rates = array(); |
691 | 691 | |
692 | - if ( !empty( $new_rates ) ) { |
|
693 | - foreach ( $new_rates as $rate ) { |
|
694 | - if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) { |
|
692 | + if (!empty($new_rates)) { |
|
693 | + foreach ($new_rates as $rate) { |
|
694 | + if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) { |
|
695 | 695 | continue; |
696 | 696 | } |
697 | 697 | |
698 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'] ); |
|
698 | + $rate['rate'] = wpinv_sanitize_amount($rate['rate']); |
|
699 | 699 | |
700 | 700 | $tax_rates[] = $rate; |
701 | 701 | } |
702 | 702 | } |
703 | 703 | |
704 | - update_option( 'wpinv_tax_rates', $tax_rates ); |
|
704 | + update_option('wpinv_tax_rates', $tax_rates); |
|
705 | 705 | |
706 | 706 | return $input; |
707 | 707 | } |
708 | -add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' ); |
|
708 | +add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates'); |
|
709 | 709 | |
710 | -function wpinv_sanitize_text_field( $input ) { |
|
711 | - return trim( $input ); |
|
710 | +function wpinv_sanitize_text_field($input) { |
|
711 | + return trim($input); |
|
712 | 712 | } |
713 | -add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' ); |
|
713 | +add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field'); |
|
714 | 714 | |
715 | 715 | function wpinv_get_settings_tabs() { |
716 | 716 | $tabs = array(); |
717 | - $tabs['general'] = __( 'General', 'invoicing' ); |
|
718 | - $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
|
719 | - $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
|
720 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
721 | - $tabs['misc'] = __( 'Misc', 'invoicing' ); |
|
722 | - $tabs['tools'] = __( 'Tools', 'invoicing' ); |
|
723 | - |
|
724 | - return apply_filters( 'wpinv_settings_tabs', $tabs ); |
|
717 | + $tabs['general'] = __('General', 'invoicing'); |
|
718 | + $tabs['gateways'] = __('Payment Gateways', 'invoicing'); |
|
719 | + $tabs['taxes'] = __('Taxes', 'invoicing'); |
|
720 | + $tabs['emails'] = __('Emails', 'invoicing'); |
|
721 | + $tabs['misc'] = __('Misc', 'invoicing'); |
|
722 | + $tabs['tools'] = __('Tools', 'invoicing'); |
|
723 | + |
|
724 | + return apply_filters('wpinv_settings_tabs', $tabs); |
|
725 | 725 | } |
726 | 726 | |
727 | -function wpinv_get_settings_tab_sections( $tab = false ) { |
|
727 | +function wpinv_get_settings_tab_sections($tab = false) { |
|
728 | 728 | $tabs = false; |
729 | 729 | $sections = wpinv_get_registered_settings_sections(); |
730 | 730 | |
731 | - if( $tab && ! empty( $sections[ $tab ] ) ) { |
|
732 | - $tabs = $sections[ $tab ]; |
|
733 | - } else if ( $tab ) { |
|
731 | + if ($tab && !empty($sections[$tab])) { |
|
732 | + $tabs = $sections[$tab]; |
|
733 | + } else if ($tab) { |
|
734 | 734 | $tabs = false; |
735 | 735 | } |
736 | 736 | |
@@ -740,135 +740,135 @@ discard block |
||
740 | 740 | function wpinv_get_registered_settings_sections() { |
741 | 741 | static $sections = false; |
742 | 742 | |
743 | - if ( false !== $sections ) { |
|
743 | + if (false !== $sections) { |
|
744 | 744 | return $sections; |
745 | 745 | } |
746 | 746 | |
747 | 747 | $sections = array( |
748 | - 'general' => apply_filters( 'wpinv_settings_sections_general', array( |
|
749 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
750 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
751 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
752 | - ) ), |
|
753 | - 'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array( |
|
754 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
755 | - ) ), |
|
756 | - 'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array( |
|
757 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
758 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
759 | - ) ), |
|
760 | - 'emails' => apply_filters( 'wpinv_settings_sections_emails', array( |
|
761 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
762 | - ) ), |
|
763 | - 'misc' => apply_filters( 'wpinv_settings_sections_misc', array( |
|
764 | - 'main' => __( 'Misc Settings', 'invoicing' ), |
|
765 | - ) ), |
|
766 | - 'tools' => apply_filters( 'wpinv_settings_sections_tools', array( |
|
767 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
768 | - ) ), |
|
748 | + 'general' => apply_filters('wpinv_settings_sections_general', array( |
|
749 | + 'main' => __('General Settings', 'invoicing'), |
|
750 | + 'currency_section' => __('Currency Settings', 'invoicing'), |
|
751 | + 'labels' => __('Label Texts', 'invoicing'), |
|
752 | + )), |
|
753 | + 'gateways' => apply_filters('wpinv_settings_sections_gateways', array( |
|
754 | + 'main' => __('Gateway Settings', 'invoicing'), |
|
755 | + )), |
|
756 | + 'taxes' => apply_filters('wpinv_settings_sections_taxes', array( |
|
757 | + 'main' => __('Tax Settings', 'invoicing'), |
|
758 | + 'rates' => __('Tax Rates', 'invoicing'), |
|
759 | + )), |
|
760 | + 'emails' => apply_filters('wpinv_settings_sections_emails', array( |
|
761 | + 'main' => __('Email Settings', 'invoicing'), |
|
762 | + )), |
|
763 | + 'misc' => apply_filters('wpinv_settings_sections_misc', array( |
|
764 | + 'main' => __('Misc Settings', 'invoicing'), |
|
765 | + )), |
|
766 | + 'tools' => apply_filters('wpinv_settings_sections_tools', array( |
|
767 | + 'main' => __('Diagnostic Tools', 'invoicing'), |
|
768 | + )), |
|
769 | 769 | ); |
770 | 770 | |
771 | - $sections = apply_filters( 'wpinv_settings_sections', $sections ); |
|
771 | + $sections = apply_filters('wpinv_settings_sections', $sections); |
|
772 | 772 | |
773 | 773 | return $sections; |
774 | 774 | } |
775 | 775 | |
776 | -function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
|
776 | +function wpinv_get_pages($with_slug = false, $default_label = NULL) { |
|
777 | 777 | $pages_options = array(); |
778 | 778 | |
779 | - if( $default_label !== NULL && $default_label !== false ) { |
|
780 | - $pages_options = array( '' => $default_label ); // Blank option |
|
779 | + if ($default_label !== NULL && $default_label !== false) { |
|
780 | + $pages_options = array('' => $default_label); // Blank option |
|
781 | 781 | } |
782 | 782 | |
783 | 783 | $pages = get_pages(); |
784 | - if ( $pages ) { |
|
785 | - foreach ( $pages as $page ) { |
|
784 | + if ($pages) { |
|
785 | + foreach ($pages as $page) { |
|
786 | 786 | $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
787 | - $pages_options[ $page->ID ] = $title; |
|
787 | + $pages_options[$page->ID] = $title; |
|
788 | 788 | } |
789 | 789 | } |
790 | 790 | |
791 | 791 | return $pages_options; |
792 | 792 | } |
793 | 793 | |
794 | -function wpinv_header_callback( $args ) { |
|
795 | - if ( !empty( $args['desc'] ) ) { |
|
794 | +function wpinv_header_callback($args) { |
|
795 | + if (!empty($args['desc'])) { |
|
796 | 796 | echo $args['desc']; |
797 | 797 | } |
798 | 798 | } |
799 | 799 | |
800 | -function wpinv_hidden_callback( $args ) { |
|
800 | +function wpinv_hidden_callback($args) { |
|
801 | 801 | global $wpinv_options; |
802 | 802 | |
803 | - if ( isset( $args['set_value'] ) ) { |
|
803 | + if (isset($args['set_value'])) { |
|
804 | 804 | $value = $args['set_value']; |
805 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
806 | - $value = $wpinv_options[ $args['id'] ]; |
|
805 | + } elseif (isset($wpinv_options[$args['id']])) { |
|
806 | + $value = $wpinv_options[$args['id']]; |
|
807 | 807 | } else { |
808 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
808 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
809 | 809 | } |
810 | 810 | |
811 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
811 | + if (isset($args['faux']) && true === $args['faux']) { |
|
812 | 812 | $args['readonly'] = true; |
813 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
813 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
814 | 814 | $name = ''; |
815 | 815 | } else { |
816 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
816 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
817 | 817 | } |
818 | 818 | |
819 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
819 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />'; |
|
820 | 820 | |
821 | 821 | echo $html; |
822 | 822 | } |
823 | 823 | |
824 | -function wpinv_checkbox_callback( $args ) { |
|
824 | +function wpinv_checkbox_callback($args) { |
|
825 | 825 | global $wpinv_options; |
826 | 826 | |
827 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
827 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
828 | 828 | |
829 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
829 | + if (isset($args['faux']) && true === $args['faux']) { |
|
830 | 830 | $name = ''; |
831 | 831 | } else { |
832 | 832 | $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
833 | 833 | } |
834 | 834 | |
835 | - $checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : ''; |
|
835 | + $checked = isset($wpinv_options[$args['id']]) ? checked(1, $wpinv_options[$args['id']], false) : ''; |
|
836 | 836 | $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
837 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
837 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
838 | 838 | |
839 | 839 | echo $html; |
840 | 840 | } |
841 | 841 | |
842 | -function wpinv_multicheck_callback( $args ) { |
|
842 | +function wpinv_multicheck_callback($args) { |
|
843 | 843 | global $wpinv_options; |
844 | 844 | |
845 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
845 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
846 | 846 | |
847 | - if ( ! empty( $args['options'] ) ) { |
|
848 | - foreach( $args['options'] as $key => $option ): |
|
849 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
850 | - if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { |
|
847 | + if (!empty($args['options'])) { |
|
848 | + foreach ($args['options'] as $key => $option): |
|
849 | + $sanitize_key = wpinv_sanitize_key($key); |
|
850 | + if (isset($wpinv_options[$args['id']][$sanitize_key])) { |
|
851 | 851 | $enabled = $sanitize_key; |
852 | 852 | } else { |
853 | 853 | $enabled = NULL; |
854 | 854 | } |
855 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
856 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label><br/>'; |
|
855 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/> '; |
|
856 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label><br/>'; |
|
857 | 857 | endforeach; |
858 | 858 | echo '<p class="description">' . $args['desc'] . '</p>'; |
859 | 859 | } |
860 | 860 | } |
861 | 861 | |
862 | -function wpinv_payment_icons_callback( $args ) { |
|
862 | +function wpinv_payment_icons_callback($args) { |
|
863 | 863 | global $wpinv_options; |
864 | 864 | |
865 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
865 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
866 | 866 | |
867 | - if ( ! empty( $args['options'] ) ) { |
|
868 | - foreach( $args['options'] as $key => $option ) { |
|
869 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
867 | + if (!empty($args['options'])) { |
|
868 | + foreach ($args['options'] as $key => $option) { |
|
869 | + $sanitize_key = wpinv_sanitize_key($key); |
|
870 | 870 | |
871 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
871 | + if (isset($wpinv_options[$args['id']][$key])) { |
|
872 | 872 | $enabled = $option; |
873 | 873 | } else { |
874 | 874 | $enabled = NULL; |
@@ -876,194 +876,194 @@ discard block |
||
876 | 876 | |
877 | 877 | echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
878 | 878 | |
879 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
879 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/> '; |
|
880 | 880 | |
881 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
882 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
881 | + if (wpinv_string_is_image_url($key)) { |
|
882 | + echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
883 | 883 | } else { |
884 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
884 | + $card = strtolower(str_replace(' ', '', $option)); |
|
885 | 885 | |
886 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
887 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
886 | + if (has_filter('wpinv_accepted_payment_' . $card . '_image')) { |
|
887 | + $image = apply_filters('wpinv_accepted_payment_' . $card . '_image', ''); |
|
888 | 888 | } else { |
889 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
889 | + $image = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false); |
|
890 | 890 | $content_dir = WP_CONTENT_DIR; |
891 | 891 | |
892 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
892 | + if (function_exists('wp_normalize_path')) { |
|
893 | 893 | // Replaces backslashes with forward slashes for Windows systems |
894 | - $image = wp_normalize_path( $image ); |
|
895 | - $content_dir = wp_normalize_path( $content_dir ); |
|
894 | + $image = wp_normalize_path($image); |
|
895 | + $content_dir = wp_normalize_path($content_dir); |
|
896 | 896 | } |
897 | 897 | |
898 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
898 | + $image = str_replace($content_dir, content_url(), $image); |
|
899 | 899 | } |
900 | 900 | |
901 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
901 | + echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
902 | 902 | } |
903 | 903 | echo $option . '</label>'; |
904 | 904 | } |
905 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
905 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>'; |
|
906 | 906 | } |
907 | 907 | } |
908 | 908 | |
909 | -function wpinv_radio_callback( $args ) { |
|
909 | +function wpinv_radio_callback($args) { |
|
910 | 910 | global $wpinv_options; |
911 | 911 | |
912 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
912 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
913 | 913 | |
914 | - foreach ( $args['options'] as $key => $option ) : |
|
915 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
914 | + foreach ($args['options'] as $key => $option) : |
|
915 | + $sanitize_key = wpinv_sanitize_key($key); |
|
916 | 916 | |
917 | 917 | $checked = false; |
918 | 918 | |
919 | - if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
919 | + if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key) |
|
920 | 920 | $checked = true; |
921 | - elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
921 | + elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']])) |
|
922 | 922 | $checked = true; |
923 | 923 | |
924 | 924 | echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
925 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
925 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>'; |
|
926 | 926 | endforeach; |
927 | 927 | |
928 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
928 | + echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>'; |
|
929 | 929 | } |
930 | 930 | |
931 | -function wpinv_gateways_callback( $args ) { |
|
931 | +function wpinv_gateways_callback($args) { |
|
932 | 932 | global $wpinv_options; |
933 | 933 | |
934 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
934 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
935 | 935 | |
936 | - foreach ( $args['options'] as $key => $option ) : |
|
937 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
936 | + foreach ($args['options'] as $key => $option) : |
|
937 | + $sanitize_key = wpinv_sanitize_key($key); |
|
938 | 938 | |
939 | - if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
|
939 | + if (isset($wpinv_options['gateways'][$key])) |
|
940 | 940 | $enabled = '1'; |
941 | 941 | else |
942 | 942 | $enabled = null; |
943 | 943 | |
944 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
945 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
944 | + echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
945 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>'; |
|
946 | 946 | endforeach; |
947 | 947 | } |
948 | 948 | |
949 | 949 | function wpinv_gateway_select_callback($args) { |
950 | 950 | global $wpinv_options; |
951 | 951 | |
952 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
952 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
953 | 953 | |
954 | 954 | echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">'; |
955 | 955 | |
956 | - foreach ( $args['options'] as $key => $option ) : |
|
957 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
958 | - $selected = selected( $key, $args['selected'], false ); |
|
956 | + foreach ($args['options'] as $key => $option) : |
|
957 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
958 | + $selected = selected($key, $args['selected'], false); |
|
959 | 959 | } else { |
960 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
|
960 | + $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : ''; |
|
961 | 961 | } |
962 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
962 | + echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>'; |
|
963 | 963 | endforeach; |
964 | 964 | |
965 | 965 | echo '</select>'; |
966 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
966 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
967 | 967 | } |
968 | 968 | |
969 | -function wpinv_text_callback( $args ) { |
|
969 | +function wpinv_text_callback($args) { |
|
970 | 970 | global $wpinv_options; |
971 | 971 | |
972 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
972 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
973 | 973 | |
974 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
975 | - $value = $wpinv_options[ $args['id'] ]; |
|
974 | + if (isset($wpinv_options[$args['id']])) { |
|
975 | + $value = $wpinv_options[$args['id']]; |
|
976 | 976 | } else { |
977 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
977 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
978 | 978 | } |
979 | 979 | |
980 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
980 | + if (isset($args['faux']) && true === $args['faux']) { |
|
981 | 981 | $args['readonly'] = true; |
982 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
982 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
983 | 983 | $name = ''; |
984 | 984 | } else { |
985 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
985 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
986 | 986 | } |
987 | 987 | |
988 | 988 | $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
989 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
990 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
991 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
989 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
990 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>'; |
|
991 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
992 | 992 | |
993 | 993 | echo $html; |
994 | 994 | } |
995 | 995 | |
996 | -function wpinv_number_callback( $args ) { |
|
996 | +function wpinv_number_callback($args) { |
|
997 | 997 | global $wpinv_options; |
998 | 998 | |
999 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
999 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1000 | 1000 | |
1001 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1002 | - $value = $wpinv_options[ $args['id'] ]; |
|
1001 | + if (isset($wpinv_options[$args['id']])) { |
|
1002 | + $value = $wpinv_options[$args['id']]; |
|
1003 | 1003 | } else { |
1004 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1004 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1005 | 1005 | } |
1006 | 1006 | |
1007 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
1007 | + if (isset($args['faux']) && true === $args['faux']) { |
|
1008 | 1008 | $args['readonly'] = true; |
1009 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1009 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1010 | 1010 | $name = ''; |
1011 | 1011 | } else { |
1012 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
1012 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
1016 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
1017 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
1015 | + $max = isset($args['max']) ? $args['max'] : 999999; |
|
1016 | + $min = isset($args['min']) ? $args['min'] : 0; |
|
1017 | + $step = isset($args['step']) ? $args['step'] : 1; |
|
1018 | 1018 | |
1019 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1020 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
1021 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1019 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
1020 | + $html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
1021 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1022 | 1022 | |
1023 | 1023 | echo $html; |
1024 | 1024 | } |
1025 | 1025 | |
1026 | -function wpinv_textarea_callback( $args ) { |
|
1026 | +function wpinv_textarea_callback($args) { |
|
1027 | 1027 | global $wpinv_options; |
1028 | 1028 | |
1029 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1029 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1030 | 1030 | |
1031 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1032 | - $value = $wpinv_options[ $args['id'] ]; |
|
1031 | + if (isset($wpinv_options[$args['id']])) { |
|
1032 | + $value = $wpinv_options[$args['id']]; |
|
1033 | 1033 | } else { |
1034 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1034 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1035 | 1035 | } |
1036 | 1036 | |
1037 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1038 | - $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
|
1037 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
1038 | + $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text'; |
|
1039 | 1039 | |
1040 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
1041 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1040 | + $html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
1041 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1042 | 1042 | |
1043 | 1043 | echo $html; |
1044 | 1044 | } |
1045 | 1045 | |
1046 | -function wpinv_password_callback( $args ) { |
|
1046 | +function wpinv_password_callback($args) { |
|
1047 | 1047 | global $wpinv_options; |
1048 | 1048 | |
1049 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1049 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1050 | 1050 | |
1051 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1052 | - $value = $wpinv_options[ $args['id'] ]; |
|
1051 | + if (isset($wpinv_options[$args['id']])) { |
|
1052 | + $value = $wpinv_options[$args['id']]; |
|
1053 | 1053 | } else { |
1054 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1054 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1055 | 1055 | } |
1056 | 1056 | |
1057 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1058 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
1059 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1057 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
1058 | + $html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>'; |
|
1059 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1060 | 1060 | |
1061 | 1061 | echo $html; |
1062 | 1062 | } |
1063 | 1063 | |
1064 | 1064 | function wpinv_missing_callback($args) { |
1065 | 1065 | printf( |
1066 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
1066 | + __('The callback function used for the %s setting is missing.', 'invoicing'), |
|
1067 | 1067 | '<strong>' . $args['id'] . '</strong>' |
1068 | 1068 | ); |
1069 | 1069 | } |
@@ -1071,137 +1071,137 @@ discard block |
||
1071 | 1071 | function wpinv_select_callback($args) { |
1072 | 1072 | global $wpinv_options; |
1073 | 1073 | |
1074 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1074 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1075 | 1075 | |
1076 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1077 | - $value = $wpinv_options[ $args['id'] ]; |
|
1076 | + if (isset($wpinv_options[$args['id']])) { |
|
1077 | + $value = $wpinv_options[$args['id']]; |
|
1078 | 1078 | } else { |
1079 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1079 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1080 | 1080 | } |
1081 | 1081 | |
1082 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
1082 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
1083 | 1083 | $value = $args['selected']; |
1084 | 1084 | } |
1085 | 1085 | |
1086 | - if ( isset( $args['placeholder'] ) ) { |
|
1086 | + if (isset($args['placeholder'])) { |
|
1087 | 1087 | $placeholder = $args['placeholder']; |
1088 | 1088 | } else { |
1089 | 1089 | $placeholder = ''; |
1090 | 1090 | } |
1091 | 1091 | |
1092 | - if ( isset( $args['chosen'] ) ) { |
|
1092 | + if (isset($args['chosen'])) { |
|
1093 | 1093 | $chosen = 'class="wpinv-chosen"'; |
1094 | 1094 | } else { |
1095 | 1095 | $chosen = ''; |
1096 | 1096 | } |
1097 | 1097 | |
1098 | - if( !empty( $args['onchange'] ) ) { |
|
1099 | - $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
1098 | + if (!empty($args['onchange'])) { |
|
1099 | + $onchange = ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
1100 | 1100 | } else { |
1101 | 1101 | $onchange = ''; |
1102 | 1102 | } |
1103 | 1103 | |
1104 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" ' . $chosen . 'data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
1104 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" ' . $chosen . 'data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />'; |
|
1105 | 1105 | |
1106 | - foreach ( $args['options'] as $option => $name ) { |
|
1107 | - $selected = selected( $option, $value, false ); |
|
1108 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
1106 | + foreach ($args['options'] as $option => $name) { |
|
1107 | + $selected = selected($option, $value, false); |
|
1108 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | $html .= '</select>'; |
1112 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1112 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1113 | 1113 | |
1114 | 1114 | echo $html; |
1115 | 1115 | } |
1116 | 1116 | |
1117 | -function wpinv_color_select_callback( $args ) { |
|
1117 | +function wpinv_color_select_callback($args) { |
|
1118 | 1118 | global $wpinv_options; |
1119 | 1119 | |
1120 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1120 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1121 | 1121 | |
1122 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1123 | - $value = $wpinv_options[ $args['id'] ]; |
|
1122 | + if (isset($wpinv_options[$args['id']])) { |
|
1123 | + $value = $wpinv_options[$args['id']]; |
|
1124 | 1124 | } else { |
1125 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1125 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1126 | 1126 | } |
1127 | 1127 | |
1128 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
1128 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>'; |
|
1129 | 1129 | |
1130 | - foreach ( $args['options'] as $option => $color ) { |
|
1131 | - $selected = selected( $option, $value, false ); |
|
1132 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
1130 | + foreach ($args['options'] as $option => $color) { |
|
1131 | + $selected = selected($option, $value, false); |
|
1132 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>'; |
|
1133 | 1133 | } |
1134 | 1134 | |
1135 | 1135 | $html .= '</select>'; |
1136 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1136 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1137 | 1137 | |
1138 | 1138 | echo $html; |
1139 | 1139 | } |
1140 | 1140 | |
1141 | -function wpinv_rich_editor_callback( $args ) { |
|
1141 | +function wpinv_rich_editor_callback($args) { |
|
1142 | 1142 | global $wpinv_options, $wp_version; |
1143 | 1143 | |
1144 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1144 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1145 | 1145 | |
1146 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1147 | - $value = $wpinv_options[ $args['id'] ]; |
|
1146 | + if (isset($wpinv_options[$args['id']])) { |
|
1147 | + $value = $wpinv_options[$args['id']]; |
|
1148 | 1148 | |
1149 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
1150 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1149 | + if (empty($args['allow_blank']) && empty($value)) { |
|
1150 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1151 | 1151 | } |
1152 | 1152 | } else { |
1153 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1153 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1154 | 1154 | } |
1155 | 1155 | |
1156 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
1156 | + $rows = isset($args['size']) ? $args['size'] : 20; |
|
1157 | 1157 | |
1158 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
1158 | + if ($wp_version >= 3.3 && function_exists('wp_editor')) { |
|
1159 | 1159 | ob_start(); |
1160 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ) ) ); |
|
1160 | + wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows))); |
|
1161 | 1161 | $html = ob_get_clean(); |
1162 | 1162 | } else { |
1163 | - $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
1163 | + $html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | - $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1166 | + $html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1167 | 1167 | |
1168 | 1168 | echo $html; |
1169 | 1169 | } |
1170 | 1170 | |
1171 | -function wpinv_upload_callback( $args ) { |
|
1171 | +function wpinv_upload_callback($args) { |
|
1172 | 1172 | global $wpinv_options; |
1173 | 1173 | |
1174 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1174 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1175 | 1175 | |
1176 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1176 | + if (isset($wpinv_options[$args['id']])) { |
|
1177 | 1177 | $value = $wpinv_options[$args['id']]; |
1178 | 1178 | } else { |
1179 | 1179 | $value = isset($args['std']) ? $args['std'] : ''; |
1180 | 1180 | } |
1181 | 1181 | |
1182 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
1183 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
1184 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
1185 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1182 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
1183 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
1184 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>'; |
|
1185 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1186 | 1186 | |
1187 | 1187 | echo $html; |
1188 | 1188 | } |
1189 | 1189 | |
1190 | -function wpinv_color_callback( $args ) { |
|
1190 | +function wpinv_color_callback($args) { |
|
1191 | 1191 | global $wpinv_options; |
1192 | 1192 | |
1193 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1193 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1194 | 1194 | |
1195 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
1196 | - $value = $wpinv_options[ $args['id'] ]; |
|
1195 | + if (isset($wpinv_options[$args['id']])) { |
|
1196 | + $value = $wpinv_options[$args['id']]; |
|
1197 | 1197 | } else { |
1198 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
1198 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
1199 | 1199 | } |
1200 | 1200 | |
1201 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
1201 | + $default = isset($args['std']) ? $args['std'] : ''; |
|
1202 | 1202 | |
1203 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
1204 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1203 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />'; |
|
1204 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1205 | 1205 | |
1206 | 1206 | echo $html; |
1207 | 1207 | } |
@@ -1209,9 +1209,9 @@ discard block |
||
1209 | 1209 | function wpinv_country_states_callback($args) { |
1210 | 1210 | global $wpinv_options; |
1211 | 1211 | |
1212 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
1212 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
1213 | 1213 | |
1214 | - if ( isset( $args['placeholder'] ) ) { |
|
1214 | + if (isset($args['placeholder'])) { |
|
1215 | 1215 | $placeholder = $args['placeholder']; |
1216 | 1216 | } else { |
1217 | 1217 | $placeholder = ''; |
@@ -1219,17 +1219,17 @@ discard block |
||
1219 | 1219 | |
1220 | 1220 | $states = wpinv_get_country_states(); |
1221 | 1221 | |
1222 | - $chosen = ( $args['chosen'] ? ' wpinv-chosen' : '' ); |
|
1223 | - $class = empty( $states ) ? ' class="wpinv-no-states' . $chosen . '"' : 'class="' . $chosen . '"'; |
|
1224 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
1222 | + $chosen = ($args['chosen'] ? ' wpinv-chosen' : ''); |
|
1223 | + $class = empty($states) ? ' class="wpinv-no-states' . $chosen . '"' : 'class="' . $chosen . '"'; |
|
1224 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>'; |
|
1225 | 1225 | |
1226 | - foreach ( $states as $option => $name ) { |
|
1227 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
1228 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
1226 | + foreach ($states as $option => $name) { |
|
1227 | + $selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : ''; |
|
1228 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | $html .= '</select>'; |
1232 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
1232 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
1233 | 1233 | |
1234 | 1234 | echo $html; |
1235 | 1235 | } |
@@ -1244,25 +1244,25 @@ discard block |
||
1244 | 1244 | <table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts"> |
1245 | 1245 | <thead> |
1246 | 1246 | <tr> |
1247 | - <th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
1248 | - <th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th> |
|
1249 | - <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e( 'Apply rate to whole country, regardless of state / province', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
1250 | - <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
1251 | - <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th> |
|
1252 | - <th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th> |
|
1247 | + <th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th> |
|
1248 | + <th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th> |
|
1249 | + <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e('Apply rate to whole country, regardless of state / province', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
1250 | + <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
1251 | + <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th> |
|
1252 | + <th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th> |
|
1253 | 1253 | </tr> |
1254 | 1254 | </thead> |
1255 | 1255 | <tbody> |
1256 | - <?php if( !empty( $rates ) ) : ?> |
|
1257 | - <?php foreach( $rates as $key => $rate ) : ?> |
|
1256 | + <?php if (!empty($rates)) : ?> |
|
1257 | + <?php foreach ($rates as $key => $rate) : ?> |
|
1258 | 1258 | <?php |
1259 | - $sanitized_key = wpinv_sanitize_key( $key ); |
|
1259 | + $sanitized_key = wpinv_sanitize_key($key); |
|
1260 | 1260 | ?> |
1261 | 1261 | <tr> |
1262 | 1262 | <td class="wpinv_tax_country"> |
1263 | 1263 | <?php |
1264 | - echo wpinv_html_select( array( |
|
1265 | - 'options' => wpinv_get_country_list( true ), |
|
1264 | + echo wpinv_html_select(array( |
|
1265 | + 'options' => wpinv_get_country_list(true), |
|
1266 | 1266 | 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
1267 | 1267 | 'id' => 'tax_rates[' . $sanitized_key . '][country]', |
1268 | 1268 | 'selected' => $rate['country'], |
@@ -1270,72 +1270,72 @@ discard block |
||
1270 | 1270 | 'show_option_none' => false, |
1271 | 1271 | 'class' => 'wpinv-tax-country', |
1272 | 1272 | 'chosen' => false, |
1273 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
1274 | - ) ); |
|
1273 | + 'placeholder' => __('Choose a country', 'invoicing') |
|
1274 | + )); |
|
1275 | 1275 | ?> |
1276 | 1276 | </td> |
1277 | 1277 | <td class="wpinv_tax_state"> |
1278 | 1278 | <?php |
1279 | - $states = wpinv_get_country_states( $rate['country'] ); |
|
1280 | - if( !empty( $states ) ) { |
|
1281 | - echo wpinv_html_select( array( |
|
1282 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
1279 | + $states = wpinv_get_country_states($rate['country']); |
|
1280 | + if (!empty($states)) { |
|
1281 | + echo wpinv_html_select(array( |
|
1282 | + 'options' => array_merge(array('' => ''), $states), |
|
1283 | 1283 | 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
1284 | 1284 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
1285 | 1285 | 'selected' => $rate['state'], |
1286 | 1286 | 'show_option_all' => false, |
1287 | 1287 | 'show_option_none' => false, |
1288 | 1288 | 'chosen' => false, |
1289 | - 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
1290 | - ) ); |
|
1289 | + 'placeholder' => __('Choose a state', 'invoicing') |
|
1290 | + )); |
|
1291 | 1291 | } else { |
1292 | - echo wpinv_html_text( array( |
|
1292 | + echo wpinv_html_text(array( |
|
1293 | 1293 | 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
1294 | - 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
1294 | + 'value' => !empty($rate['state']) ? $rate['state'] : '', |
|
1295 | 1295 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
1296 | - ) ); |
|
1296 | + )); |
|
1297 | 1297 | } |
1298 | 1298 | ?> |
1299 | 1299 | </td> |
1300 | 1300 | <td class="wpinv_tax_global"> |
1301 | - <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/> |
|
1302 | - <label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
1301 | + <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked(true, !empty($rate['global'])); ?>/> |
|
1302 | + <label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
1303 | 1303 | </td> |
1304 | - <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html( $rate['rate'] ); ?>"/></td> |
|
1305 | - <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html( $rate['name'] ); ?>"/></td> |
|
1306 | - <td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td> |
|
1304 | + <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html($rate['rate']); ?>"/></td> |
|
1305 | + <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html($rate['name']); ?>"/></td> |
|
1306 | + <td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td> |
|
1307 | 1307 | </tr> |
1308 | 1308 | <?php endforeach; ?> |
1309 | 1309 | <?php else : ?> |
1310 | 1310 | <tr> |
1311 | 1311 | <td class="wpinv_tax_country"> |
1312 | 1312 | <?php |
1313 | - echo wpinv_html_select( array( |
|
1314 | - 'options' => wpinv_get_country_list( true ), |
|
1313 | + echo wpinv_html_select(array( |
|
1314 | + 'options' => wpinv_get_country_list(true), |
|
1315 | 1315 | 'name' => 'tax_rates[0][country]', |
1316 | 1316 | 'show_option_all' => false, |
1317 | 1317 | 'show_option_none' => false, |
1318 | 1318 | 'class' => 'wpinv-tax-country', |
1319 | 1319 | 'chosen' => false, |
1320 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
1321 | - ) ); ?> |
|
1320 | + 'placeholder' => __('Choose a country', 'invoicing') |
|
1321 | + )); ?> |
|
1322 | 1322 | </td> |
1323 | 1323 | <td class="wpinv_tax_state"> |
1324 | - <?php echo wpinv_html_text( array( |
|
1324 | + <?php echo wpinv_html_text(array( |
|
1325 | 1325 | 'name' => 'tax_rates[0][state]' |
1326 | - ) ); ?> |
|
1326 | + )); ?> |
|
1327 | 1327 | </td> |
1328 | 1328 | <td class="wpinv_tax_global"> |
1329 | 1329 | <input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/> |
1330 | - <label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
1330 | + <label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
1331 | 1331 | </td> |
1332 | - <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>" value="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>"/></td> |
|
1332 | + <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>" value="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>"/></td> |
|
1333 | 1333 | <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td> |
1334 | - <td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td> |
|
1334 | + <td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td> |
|
1335 | 1335 | </tr> |
1336 | 1336 | <?php endif; ?> |
1337 | 1337 | </tbody> |
1338 | - <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot> |
|
1338 | + <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e('Add Tax Rate', 'invoicing'); ?></span></td></tr></tfoot> |
|
1339 | 1339 | </table> |
1340 | 1340 | <?php |
1341 | 1341 | echo ob_get_clean(); |
@@ -1346,44 +1346,44 @@ discard block |
||
1346 | 1346 | ob_start(); ?> |
1347 | 1347 | </td><tr> |
1348 | 1348 | <td colspan="2" class="wpinv_tools_tdbox"> |
1349 | - <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
1350 | - <?php do_action( 'wpinv_tools_before' ); ?> |
|
1349 | + <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
1350 | + <?php do_action('wpinv_tools_before'); ?> |
|
1351 | 1351 | <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts"> |
1352 | 1352 | <thead> |
1353 | 1353 | <tr> |
1354 | - <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th> |
|
1355 | - <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th> |
|
1356 | - <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th> |
|
1354 | + <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th> |
|
1355 | + <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th> |
|
1356 | + <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th> |
|
1357 | 1357 | </tr> |
1358 | 1358 | </thead> |
1359 | - <?php do_action( 'wpinv_tools_row' ); ?> |
|
1359 | + <?php do_action('wpinv_tools_row'); ?> |
|
1360 | 1360 | <tbody> |
1361 | 1361 | </tbody> |
1362 | 1362 | </table> |
1363 | - <?php do_action( 'wpinv_tools_after' ); ?> |
|
1363 | + <?php do_action('wpinv_tools_after'); ?> |
|
1364 | 1364 | <?php |
1365 | 1365 | echo ob_get_clean(); |
1366 | 1366 | } |
1367 | 1367 | |
1368 | -function wpinv_descriptive_text_callback( $args ) { |
|
1369 | - echo wp_kses_post( $args['desc'] ); |
|
1368 | +function wpinv_descriptive_text_callback($args) { |
|
1369 | + echo wp_kses_post($args['desc']); |
|
1370 | 1370 | } |
1371 | 1371 | |
1372 | -function wpinv_hook_callback( $args ) { |
|
1373 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1372 | +function wpinv_hook_callback($args) { |
|
1373 | + do_action('wpinv_' . $args['id'], $args); |
|
1374 | 1374 | } |
1375 | 1375 | |
1376 | 1376 | function wpinv_set_settings_cap() { |
1377 | 1377 | return 'manage_options'; |
1378 | 1378 | } |
1379 | -add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
|
1379 | +add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap'); |
|
1380 | 1380 | |
1381 | -function wpinv_settings_sanitize_input( $value, $key ) { |
|
1382 | - if ( $key == 'tax_rate' || $key == 'eu_fallback_rate' ) { |
|
1383 | - $value = wpinv_sanitize_amount( $value ); |
|
1381 | +function wpinv_settings_sanitize_input($value, $key) { |
|
1382 | + if ($key == 'tax_rate' || $key == 'eu_fallback_rate') { |
|
1383 | + $value = wpinv_sanitize_amount($value); |
|
1384 | 1384 | $value = $value >= 100 ? 99 : $value; |
1385 | 1385 | } |
1386 | 1386 | |
1387 | 1387 | return $value; |
1388 | 1388 | } |
1389 | -add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 ); |
|
1390 | 1389 | \ No newline at end of file |
1390 | +add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2); |
|
1391 | 1391 | \ 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,68 +21,68 @@ 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' ), 'manage_options', 'wpinv-reports', array( $this, 'reports_page' ) ); |
|
61 | + $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), 'manage_options', '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 | 81 | <div class="wpi-reports-content wpi-reports-<?php echo $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 |
@@ -90,97 +90,97 @@ discard block |
||
90 | 90 | |
91 | 91 | public function export() { |
92 | 92 | $statuses = wpinv_get_invoice_statuses(); |
93 | - $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses ); |
|
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' => '', |
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,130 +188,130 @@ 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'] ) || !current_user_can( 'manage_options' ) ) { |
|
194 | - wp_send_json( $response ); |
|
193 | + if (empty($_POST['data']) || !current_user_can('manage_options')) { |
|
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 | 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 ); |
|
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 | - 'id' => __( 'ID', 'invoicing' ), |
|
259 | - 'date' => __( 'Date', 'invoicing' ) |
|
258 | + 'id' => __('ID', 'invoicing'), |
|
259 | + 'date' => __('Date', 'invoicing') |
|
260 | 260 | ); |
261 | 261 | |
262 | - return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns ); |
|
262 | + return apply_filters('wpinv_export_get_columns_' . $this->export, $columns); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | protected function get_export_file() { |
266 | 266 | $file = ''; |
267 | 267 | |
268 | - if ( $this->wp_filesystem->exists( $this->file ) ) { |
|
269 | - $file = $this->wp_filesystem->get_contents( $this->file ); |
|
268 | + if ($this->wp_filesystem->exists($this->file)) { |
|
269 | + $file = $this->wp_filesystem->get_contents($this->file); |
|
270 | 270 | } else { |
271 | - $this->wp_filesystem->put_contents( $this->file, '' ); |
|
271 | + $this->wp_filesystem->put_contents($this->file, ''); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | return $file; |
275 | 275 | } |
276 | 276 | |
277 | - protected function attach_export_data( $data = '' ) { |
|
278 | - $filedata = $this->get_export_file(); |
|
279 | - $filedata .= $data; |
|
277 | + protected function attach_export_data($data = '') { |
|
278 | + $filedata = $this->get_export_file(); |
|
279 | + $filedata .= $data; |
|
280 | 280 | |
281 | - $this->wp_filesystem->put_contents( $this->file, $filedata ); |
|
281 | + $this->wp_filesystem->put_contents($this->file, $filedata); |
|
282 | 282 | |
283 | - $rows = file( $this->file, FILE_SKIP_EMPTY_LINES ); |
|
283 | + $rows = file($this->file, FILE_SKIP_EMPTY_LINES); |
|
284 | 284 | $columns = $this->get_columns(); |
285 | - $columns = empty( $columns ) ? 0 : 1; |
|
285 | + $columns = empty($columns) ? 0 : 1; |
|
286 | 286 | |
287 | - $this->empty = count( $rows ) == $columns ? true : false; |
|
287 | + $this->empty = count($rows) == $columns ? true : false; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | public function print_columns() { |
291 | 291 | $column_data = ''; |
292 | 292 | $columns = $this->get_columns(); |
293 | 293 | $i = 1; |
294 | - foreach( $columns as $key => $column ) { |
|
295 | - $column_data .= '"' . addslashes( $column ) . '"'; |
|
296 | - $column_data .= $i == count( $columns ) ? '' : ','; |
|
294 | + foreach ($columns as $key => $column) { |
|
295 | + $column_data .= '"' . addslashes($column) . '"'; |
|
296 | + $column_data .= $i == count($columns) ? '' : ','; |
|
297 | 297 | $i++; |
298 | 298 | } |
299 | 299 | $column_data .= "\r\n"; |
300 | 300 | |
301 | - $this->attach_export_data( $column_data ); |
|
301 | + $this->attach_export_data($column_data); |
|
302 | 302 | |
303 | 303 | return $column_data; |
304 | 304 | } |
305 | 305 | |
306 | 306 | public function process_export_step() { |
307 | - if ( $this->step < 2 ) { |
|
308 | - @unlink( $this->file ); |
|
307 | + if ($this->step < 2) { |
|
308 | + @unlink($this->file); |
|
309 | 309 | $this->print_columns(); |
310 | 310 | } |
311 | 311 | |
312 | 312 | $return = $this->print_rows(); |
313 | 313 | |
314 | - if ( $return ) { |
|
314 | + if ($return) { |
|
315 | 315 | return true; |
316 | 316 | } else { |
317 | 317 | return false; |
@@ -320,23 +320,23 @@ discard block |
||
320 | 320 | |
321 | 321 | public function get_export_status() { |
322 | 322 | $status = 100; |
323 | - return apply_filters( 'wpinv_get_export_status_' . $this->export, $status ); |
|
323 | + return apply_filters('wpinv_get_export_status_' . $this->export, $status); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | public function get_export_data() { |
327 | 327 | $data = array( |
328 | 328 | 0 => array( |
329 | 329 | 'id' => '', |
330 | - 'data' => date( 'F j, Y' ) |
|
330 | + 'data' => date('F j, Y') |
|
331 | 331 | ), |
332 | 332 | 1 => array( |
333 | 333 | 'id' => '', |
334 | - 'data' => date( 'F j, Y' ) |
|
334 | + 'data' => date('F j, Y') |
|
335 | 335 | ) |
336 | 336 | ); |
337 | 337 | |
338 | - $data = apply_filters( 'wpinv_export_get_data', $data ); |
|
339 | - $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data ); |
|
338 | + $data = apply_filters('wpinv_export_get_data', $data); |
|
339 | + $data = apply_filters('wpinv_export_get_data_' . $this->export, $data); |
|
340 | 340 | |
341 | 341 | return $data; |
342 | 342 | } |
@@ -346,20 +346,20 @@ discard block |
||
346 | 346 | $data = $this->get_export_data(); |
347 | 347 | $columns = $this->get_columns(); |
348 | 348 | |
349 | - if ( $data ) { |
|
350 | - foreach ( $data as $row ) { |
|
349 | + if ($data) { |
|
350 | + foreach ($data as $row) { |
|
351 | 351 | $i = 1; |
352 | - foreach ( $row as $key => $column ) { |
|
353 | - if ( array_key_exists( $key, $columns ) ) { |
|
354 | - $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"'; |
|
355 | - $row_data .= $i == count( $columns ) ? '' : ','; |
|
352 | + foreach ($row as $key => $column) { |
|
353 | + if (array_key_exists($key, $columns)) { |
|
354 | + $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"'; |
|
355 | + $row_data .= $i == count($columns) ? '' : ','; |
|
356 | 356 | $i++; |
357 | 357 | } |
358 | 358 | } |
359 | 359 | $row_data .= "\r\n"; |
360 | 360 | } |
361 | 361 | |
362 | - $this->attach_export_data( $row_data ); |
|
362 | + $this->attach_export_data($row_data); |
|
363 | 363 | |
364 | 364 | return $row_data; |
365 | 365 | } |
@@ -368,46 +368,46 @@ discard block |
||
368 | 368 | } |
369 | 369 | |
370 | 370 | // Export Invoices. |
371 | - public function set_invoices_export( $request ) { |
|
372 | - $this->from_date = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : ''; |
|
373 | - $this->to_date = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : ''; |
|
374 | - $this->status = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publich'; |
|
371 | + public function set_invoices_export($request) { |
|
372 | + $this->from_date = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : ''; |
|
373 | + $this->to_date = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : ''; |
|
374 | + $this->status = isset($request['status']) ? sanitize_text_field($request['status']) : 'publich'; |
|
375 | 375 | } |
376 | 376 | |
377 | - public function get_invoices_columns( $columns = array() ) { |
|
377 | + public function get_invoices_columns($columns = array()) { |
|
378 | 378 | $columns = array( |
379 | - 'id' => __( 'ID', 'invoicing' ), |
|
380 | - 'number' => __( 'Number', 'invoicing' ), |
|
381 | - 'date' => __( 'Date', 'invoicing' ), |
|
382 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
383 | - 'status_nicename' => __( 'Status Nicename', 'invoicing' ), |
|
384 | - 'status' => __( 'Status', 'invoicing' ), |
|
385 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
386 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
387 | - 'user_id' => __( 'User ID', 'invoicing' ), |
|
388 | - 'email' => __( 'Email', 'invoicing' ), |
|
389 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
390 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
391 | - 'address' => __( 'Address', 'invoicing' ), |
|
392 | - 'city' => __( 'City', 'invoicing' ), |
|
393 | - 'state' => __( 'State', 'invoicing' ), |
|
394 | - 'country' => __( 'Country', 'invoicing' ), |
|
395 | - 'zip' => __( 'Zipcode', 'invoicing' ), |
|
396 | - 'phone' => __( 'Phone', 'invoicing' ), |
|
397 | - 'company' => __( 'Company', 'invoicing' ), |
|
398 | - 'vat_number' => __( 'Vat Number', 'invoicing' ), |
|
399 | - 'ip' => __( 'IP', 'invoicing' ), |
|
400 | - 'gateway' => __( 'Gateway', 'invoicing' ), |
|
401 | - 'gateway_nicename' => __( 'Gateway Nicename', 'invoicing' ), |
|
402 | - 'transaction_id'=> __( 'Transaction ID', 'invoicing' ), |
|
403 | - 'currency' => __( 'Currency', 'invoicing' ), |
|
404 | - 'due_date' => __( 'Due Date', 'invoicing' ), |
|
379 | + 'id' => __('ID', 'invoicing'), |
|
380 | + 'number' => __('Number', 'invoicing'), |
|
381 | + 'date' => __('Date', 'invoicing'), |
|
382 | + 'amount' => __('Amount', 'invoicing'), |
|
383 | + 'status_nicename' => __('Status Nicename', 'invoicing'), |
|
384 | + 'status' => __('Status', 'invoicing'), |
|
385 | + 'tax' => __('Tax', 'invoicing'), |
|
386 | + 'discount' => __('Discount', 'invoicing'), |
|
387 | + 'user_id' => __('User ID', 'invoicing'), |
|
388 | + 'email' => __('Email', 'invoicing'), |
|
389 | + 'first_name' => __('First Name', 'invoicing'), |
|
390 | + 'last_name' => __('Last Name', 'invoicing'), |
|
391 | + 'address' => __('Address', 'invoicing'), |
|
392 | + 'city' => __('City', 'invoicing'), |
|
393 | + 'state' => __('State', 'invoicing'), |
|
394 | + 'country' => __('Country', 'invoicing'), |
|
395 | + 'zip' => __('Zipcode', 'invoicing'), |
|
396 | + 'phone' => __('Phone', 'invoicing'), |
|
397 | + 'company' => __('Company', 'invoicing'), |
|
398 | + 'vat_number' => __('Vat Number', 'invoicing'), |
|
399 | + 'ip' => __('IP', 'invoicing'), |
|
400 | + 'gateway' => __('Gateway', 'invoicing'), |
|
401 | + 'gateway_nicename' => __('Gateway Nicename', 'invoicing'), |
|
402 | + 'transaction_id'=> __('Transaction ID', 'invoicing'), |
|
403 | + 'currency' => __('Currency', 'invoicing'), |
|
404 | + 'due_date' => __('Due Date', 'invoicing'), |
|
405 | 405 | ); |
406 | 406 | |
407 | 407 | return $columns; |
408 | 408 | } |
409 | 409 | |
410 | - public function get_invoices_data( $response = array() ) { |
|
410 | + public function get_invoices_data($response = array()) { |
|
411 | 411 | $args = array( |
412 | 412 | 'limit' => $this->per_page, |
413 | 413 | 'page' => $this->step, |
@@ -415,35 +415,35 @@ discard block |
||
415 | 415 | 'orderby' => 'date', |
416 | 416 | ); |
417 | 417 | |
418 | - if ( $this->status != 'any' ) { |
|
418 | + if ($this->status != 'any') { |
|
419 | 419 | $args['status'] = $this->status; |
420 | 420 | } |
421 | 421 | |
422 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
422 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
423 | 423 | $args['date_query'] = array( |
424 | 424 | array( |
425 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
426 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
425 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
426 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
427 | 427 | 'inclusive' => true |
428 | 428 | ) |
429 | 429 | ); |
430 | 430 | } |
431 | 431 | |
432 | - $invoices = wpinv_get_invoices( $args ); |
|
432 | + $invoices = wpinv_get_invoices($args); |
|
433 | 433 | |
434 | 434 | $data = array(); |
435 | 435 | |
436 | - if ( !empty( $invoices ) ) { |
|
437 | - foreach ( $invoices as $invoice ) { |
|
436 | + if (!empty($invoices)) { |
|
437 | + foreach ($invoices as $invoice) { |
|
438 | 438 | $row = array( |
439 | 439 | 'id' => $invoice->ID, |
440 | 440 | 'number' => $invoice->get_number(), |
441 | - 'date' => $invoice->get_invoice_date( false ), |
|
442 | - 'amount' => wpinv_round_amount( $invoice->get_total() ), |
|
443 | - 'status_nicename' => $invoice->get_status( true ), |
|
441 | + 'date' => $invoice->get_invoice_date(false), |
|
442 | + 'amount' => wpinv_round_amount($invoice->get_total()), |
|
443 | + 'status_nicename' => $invoice->get_status(true), |
|
444 | 444 | 'status' => $invoice->get_status(), |
445 | - 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '', |
|
446 | - 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '', |
|
445 | + 'tax' => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '', |
|
446 | + 'discount' => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '', |
|
447 | 447 | 'user_id' => $invoice->get_user_id(), |
448 | 448 | 'email' => $invoice->get_email(), |
449 | 449 | 'first_name' => $invoice->get_first_name(), |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | 'due_date' => $invoice->needs_payment() ? $invoice->get_due_date() : '', |
465 | 465 | ); |
466 | 466 | |
467 | - $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice ); |
|
467 | + $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice); |
|
468 | 468 | } |
469 | 469 | |
470 | 470 | return $data; |
@@ -480,29 +480,29 @@ discard block |
||
480 | 480 | 'return' => 'ids', |
481 | 481 | ); |
482 | 482 | |
483 | - if ( $this->status != 'any' ) { |
|
483 | + if ($this->status != 'any') { |
|
484 | 484 | $args['status'] = $this->status; |
485 | 485 | } |
486 | 486 | |
487 | - if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) { |
|
487 | + if (!empty($this->from_date) || !empty($this->to_date)) { |
|
488 | 488 | $args['date_query'] = array( |
489 | 489 | array( |
490 | - 'after' => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ), |
|
491 | - 'before' => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ), |
|
490 | + 'after' => date('Y-n-d 00:00:00', strtotime($this->from_date)), |
|
491 | + 'before' => date('Y-n-d 23:59:59', strtotime($this->to_date)), |
|
492 | 492 | 'inclusive' => true |
493 | 493 | ) |
494 | 494 | ); |
495 | 495 | } |
496 | 496 | |
497 | - $invoices = wpinv_get_invoices( $args ); |
|
498 | - $total = !empty( $invoices ) ? count( $invoices ) : 0; |
|
497 | + $invoices = wpinv_get_invoices($args); |
|
498 | + $total = !empty($invoices) ? count($invoices) : 0; |
|
499 | 499 | $status = 100; |
500 | 500 | |
501 | - if ( $total > 0 ) { |
|
502 | - $status = ( ( $this->per_page * $this->step ) / $total ) * 100; |
|
501 | + if ($total > 0) { |
|
502 | + $status = (($this->per_page * $this->step) / $total) * 100; |
|
503 | 503 | } |
504 | 504 | |
505 | - if ( $status > 100 ) { |
|
505 | + if ($status > 100) { |
|
506 | 506 | $status = 100; |
507 | 507 | } |
508 | 508 |
@@ -1,60 +1,60 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' ); |
|
5 | +add_filter('wpinv_authorizenet_support_subscription', '__return_true'); |
|
6 | 6 | |
7 | -function wpinv_authorizenet_cc_form( $invoice_id ) { |
|
8 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
9 | - $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : ''; |
|
7 | +function wpinv_authorizenet_cc_form($invoice_id) { |
|
8 | + $invoice = wpinv_get_invoice($invoice_id); |
|
9 | + $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : ''; |
|
10 | 10 | ?> |
11 | 11 | <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default"> |
12 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div> |
|
12 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div> |
|
13 | 13 | <div class="panel-body"> |
14 | 14 | <div class="form-group required"> |
15 | - <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label> |
|
15 | + <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e('Card Owner', 'invoicing'); ?></label> |
|
16 | 16 | <div class="col-sm-8"> |
17 | - <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]"> |
|
17 | + <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]"> |
|
18 | 18 | </div> |
19 | 19 | </div> |
20 | 20 | <div class="form-group required"> |
21 | - <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label> |
|
21 | + <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e('Card Number', 'invoicing'); ?></label> |
|
22 | 22 | <div class="col-sm-8"> |
23 | - <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]"> |
|
23 | + <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]"> |
|
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | <div class="form-group required"> |
27 | - <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label> |
|
27 | + <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label> |
|
28 | 28 | <div class="col-sm-2"> |
29 | 29 | <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]"> |
30 | - <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
31 | - <option value="<?php echo $value;?>"><?php echo $value;?></option> |
|
30 | + <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
31 | + <option value="<?php echo $value; ?>"><?php echo $value; ?></option> |
|
32 | 32 | <?php } ?> |
33 | 33 | </select> |
34 | 34 | </div> |
35 | 35 | <div class="col-sm-2"> |
36 | 36 | <select class="form-control" name="authorizenet[cc_expire_year]"> |
37 | - <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?> |
|
38 | - <option value="<?php echo $i;?>"><?php echo $i;?></option> |
|
37 | + <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?> |
|
38 | + <option value="<?php echo $i; ?>"><?php echo $i; ?></option> |
|
39 | 39 | <?php } ?> |
40 | 40 | </select> |
41 | 41 | </div> |
42 | 42 | </div> |
43 | 43 | <div class="form-group required"> |
44 | - <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label> |
|
44 | + <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label> |
|
45 | 45 | <div class="col-sm-8"> |
46 | - <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]""> |
|
46 | + <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]""> |
|
47 | 47 | </div> |
48 | 48 | </div> |
49 | 49 | </div> |
50 | 50 | </div> |
51 | 51 | <?php |
52 | 52 | } |
53 | -add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 ); |
|
53 | +add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1); |
|
54 | 54 | |
55 | -function wpinv_process_authorizenet_payment( $purchase_data ) { |
|
56 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
57 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
55 | +function wpinv_process_authorizenet_payment($purchase_data) { |
|
56 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
57 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Collect payment data |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | ); |
73 | 73 | |
74 | 74 | // Record the pending payment |
75 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
75 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
76 | 76 | |
77 | - if ( !empty( $invoice ) ) { |
|
78 | - $authorizenet_card = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array(); |
|
77 | + if (!empty($invoice)) { |
|
78 | + $authorizenet_card = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array(); |
|
79 | 79 | $card_defaults = array( |
80 | 80 | 'cc_owner' => $invoice->get_user_full_name(), |
81 | 81 | 'cc_number' => false, |
@@ -83,27 +83,27 @@ discard block |
||
83 | 83 | 'cc_expire_year' => false, |
84 | 84 | 'cc_cvv2' => false, |
85 | 85 | ); |
86 | - $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults ); |
|
86 | + $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults); |
|
87 | 87 | |
88 | - if ( empty( $authorizenet_card['cc_owner'] ) ) { |
|
89 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
88 | + if (empty($authorizenet_card['cc_owner'])) { |
|
89 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
90 | 90 | } |
91 | - if ( empty( $authorizenet_card['cc_number'] ) ) { |
|
92 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
91 | + if (empty($authorizenet_card['cc_number'])) { |
|
92 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
93 | 93 | } |
94 | - if ( empty( $authorizenet_card['cc_expire_month'] ) ) { |
|
95 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
94 | + if (empty($authorizenet_card['cc_expire_month'])) { |
|
95 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
96 | 96 | } |
97 | - if ( empty( $authorizenet_card['cc_expire_year'] ) ) { |
|
98 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
97 | + if (empty($authorizenet_card['cc_expire_year'])) { |
|
98 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
99 | 99 | } |
100 | - if ( empty( $authorizenet_card['cc_cvv2'] ) ) { |
|
101 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
100 | + if (empty($authorizenet_card['cc_cvv2'])) { |
|
101 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $errors = wpinv_get_errors(); |
105 | 105 | |
106 | - if ( empty( $errors ) ) { |
|
106 | + if (empty($errors)) { |
|
107 | 107 | $invoice_id = $invoice->ID; |
108 | 108 | $quantities_enabled = wpinv_item_quantities_enabled(); |
109 | 109 | $use_taxes = wpinv_use_taxes(); |
@@ -112,141 +112,141 @@ discard block |
||
112 | 112 | $authorizeAIM->first_name = $invoice->get_first_name(); |
113 | 113 | $authorizeAIM->last_name = $invoice->get_last_name(); |
114 | 114 | $authorizeAIM->company = $invoice->company; |
115 | - $authorizeAIM->address = wp_strip_all_tags( $invoice->get_address(), true ); |
|
115 | + $authorizeAIM->address = wp_strip_all_tags($invoice->get_address(), true); |
|
116 | 116 | $authorizeAIM->city = $invoice->city; |
117 | 117 | $authorizeAIM->state = $invoice->state; |
118 | 118 | $authorizeAIM->zip = $invoice->zip; |
119 | 119 | $authorizeAIM->country = $invoice->country; |
120 | 120 | $authorizeAIM->phone = $invoice->phone; |
121 | 121 | $authorizeAIM->email = $invoice->get_email(); |
122 | - $authorizeAIM->amount = wpinv_sanitize_amount( $invoice->get_total() ); |
|
123 | - $authorizeAIM->card_num = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) ); |
|
124 | - $authorizeAIM->exp_date = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] ); |
|
125 | - $authorizeAIM->card_code = sanitize_text_field( $authorizenet_card['cc_cvv2'] ); |
|
122 | + $authorizeAIM->amount = wpinv_sanitize_amount($invoice->get_total()); |
|
123 | + $authorizeAIM->card_num = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number'])); |
|
124 | + $authorizeAIM->exp_date = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']); |
|
125 | + $authorizeAIM->card_code = sanitize_text_field($authorizenet_card['cc_cvv2']); |
|
126 | 126 | $authorizeAIM->invoice_num = $invoice->ID; |
127 | 127 | |
128 | 128 | $item_desc = array(); |
129 | - foreach ( $invoice->get_cart_details() as $item ) { |
|
130 | - $quantity = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | - $item_desc[] = $item['name'] . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')'; |
|
129 | + foreach ($invoice->get_cart_details() as $item) { |
|
130 | + $quantity = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1; |
|
131 | + $item_desc[] = $item['name'] . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')'; |
|
132 | 132 | |
133 | - $authorizeAIM->addLineItem( $item['id'], $item['name'], '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) ); |
|
133 | + $authorizeAIM->addLineItem($item['id'], $item['name'], '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N')); |
|
134 | 134 | } |
135 | 135 | |
136 | - $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc ); |
|
136 | + $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc); |
|
137 | 137 | |
138 | - if ( $use_taxes && $invoice->get_tax() > 0 ) { |
|
139 | - $authorizeAIM->tax = $invoice->get_tax(); |
|
138 | + if ($use_taxes && $invoice->get_tax() > 0) { |
|
139 | + $authorizeAIM->tax = $invoice->get_tax(); |
|
140 | 140 | |
141 | - $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) ); |
|
141 | + $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true)); |
|
142 | 142 | } |
143 | 143 | |
144 | - if ( $invoice->get_discount() > 0 ) { |
|
145 | - $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) ); |
|
144 | + if ($invoice->get_discount() > 0) { |
|
145 | + $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true)); |
|
146 | 146 | } |
147 | 147 | |
148 | - $authorizeAIM->description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' ); |
|
148 | + $authorizeAIM->description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8'); |
|
149 | 149 | |
150 | 150 | $is_recurring = $invoice->is_recurring(); // Recurring payment. |
151 | 151 | |
152 | - if ( $is_recurring ) { |
|
152 | + if ($is_recurring) { |
|
153 | 153 | $authorizeAIM->recurring_billing = true; |
154 | 154 | } |
155 | 155 | |
156 | 156 | try { |
157 | - if ( $is_recurring ) { |
|
157 | + if ($is_recurring) { |
|
158 | 158 | $response = $authorizeAIM->authorizeOnly(); |
159 | 159 | } else { |
160 | 160 | $response = $authorizeAIM->authorizeAndCapture(); |
161 | 161 | } |
162 | 162 | |
163 | - if ( $response->approved || $response->held ) { |
|
164 | - if ( $response->approved ) { |
|
165 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
163 | + if ($response->approved || $response->held) { |
|
164 | + if ($response->approved) { |
|
165 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
166 | 166 | } |
167 | - wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id ); |
|
167 | + wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id); |
|
168 | 168 | |
169 | - $message = wp_sprintf( __( 'Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing' ), $response->response_reason_text, $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ); |
|
169 | + $message = wp_sprintf(__('Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing'), $response->response_reason_text, $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code); |
|
170 | 170 | |
171 | - wpinv_insert_payment_note( $invoice_id, $message ); |
|
171 | + wpinv_insert_payment_note($invoice_id, $message); |
|
172 | 172 | |
173 | - do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card ); |
|
173 | + do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card); |
|
174 | 174 | |
175 | 175 | wpinv_clear_errors(); |
176 | 176 | wpinv_empty_cart(); |
177 | 177 | |
178 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
178 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
179 | 179 | } else { |
180 | - if ( !empty( $response->response_reason_text ) ) { |
|
181 | - $error = __( $response->response_reason_text, 'invoicing' ); |
|
182 | - } else if ( !empty( $response->error_message ) ) { |
|
183 | - $error = __( $response->error_message, 'invoicing' ); |
|
180 | + if (!empty($response->response_reason_text)) { |
|
181 | + $error = __($response->response_reason_text, 'invoicing'); |
|
182 | + } else if (!empty($response->error_message)) { |
|
183 | + $error = __($response->error_message, 'invoicing'); |
|
184 | 184 | } else { |
185 | - $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) ); |
|
185 | + $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true)); |
|
186 | 186 | } |
187 | 187 | |
188 | - $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error ); |
|
188 | + $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error); |
|
189 | 189 | |
190 | - wpinv_set_error( 'payment_error', $error ); |
|
191 | - wpinv_record_gateway_error( $error, $response ); |
|
192 | - wpinv_insert_payment_note( $invoice_id, $error ); |
|
190 | + wpinv_set_error('payment_error', $error); |
|
191 | + wpinv_record_gateway_error($error, $response); |
|
192 | + wpinv_insert_payment_note($invoice_id, $error); |
|
193 | 193 | |
194 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
194 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
195 | 195 | } |
196 | - } catch ( AuthorizeNetException $e ) { |
|
197 | - wpinv_set_error( 'request_error', $e->getMessage() ); |
|
198 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) ); |
|
199 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
196 | + } catch (AuthorizeNetException $e) { |
|
197 | + wpinv_set_error('request_error', $e->getMessage()); |
|
198 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage())); |
|
199 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
200 | 200 | } |
201 | 201 | } else { |
202 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
202 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
203 | 203 | } |
204 | 204 | } else { |
205 | - wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice ); |
|
206 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
205 | + wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice); |
|
206 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
207 | 207 | } |
208 | 208 | } |
209 | -add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' ); |
|
209 | +add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment'); |
|
210 | 210 | |
211 | -function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) { |
|
212 | - if ( empty( $subscription_id ) ) { |
|
211 | +function wpinv_authorizenet_cancel_subscription($subscription_id = '') { |
|
212 | + if (empty($subscription_id)) { |
|
213 | 213 | return false; |
214 | 214 | } |
215 | 215 | |
216 | 216 | try { |
217 | 217 | $authnetXML = wpinv_authorizenet_XML(); |
218 | - $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) ); |
|
218 | + $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id)); |
|
219 | 219 | |
220 | 220 | return $authnetXML->isSuccessful(); |
221 | - } catch( Exception $e ) { |
|
222 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
221 | + } catch (Exception $e) { |
|
222 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | return false; |
226 | 226 | } |
227 | 227 | |
228 | -function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) { |
|
229 | - $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' ); |
|
230 | - if ( empty( $authorizenet_md5_hash ) ) { |
|
228 | +function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) { |
|
229 | + $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash'); |
|
230 | + if (empty($authorizenet_md5_hash)) { |
|
231 | 231 | return true; |
232 | 232 | } |
233 | 233 | |
234 | - $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) ); |
|
234 | + $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount)); |
|
235 | 235 | |
236 | - return hash_equals( $compare_md5, $md5_hash ); |
|
236 | + return hash_equals($compare_md5, $md5_hash); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | function wpinv_authorizenet_AIM() { |
240 | - if ( !class_exists( 'AuthorizeNetException' ) ) { |
|
241 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
240 | + if (!class_exists('AuthorizeNetException')) { |
|
241 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php'; |
|
242 | 242 | } |
243 | 243 | |
244 | - $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) ); |
|
244 | + $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key')); |
|
245 | 245 | |
246 | - if ( wpinv_is_test_mode( 'authorizenet' ) ) { |
|
247 | - $authorizeAIM->setSandbox( true ); |
|
246 | + if (wpinv_is_test_mode('authorizenet')) { |
|
247 | + $authorizeAIM->setSandbox(true); |
|
248 | 248 | } else { |
249 | - $authorizeAIM->setSandbox( false ); |
|
249 | + $authorizeAIM->setSandbox(false); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | $authorizeAIM->customer_ip = wpinv_get_ip(); |
@@ -255,164 +255,164 @@ discard block |
||
255 | 255 | } |
256 | 256 | |
257 | 257 | function wpinv_authorizenet_XML() { |
258 | - if ( !class_exists( 'AuthnetXML' ) ) { |
|
259 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
258 | + if (!class_exists('AuthnetXML')) { |
|
259 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php'; |
|
260 | 260 | } |
261 | 261 | |
262 | - $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) ); |
|
262 | + $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet')); |
|
263 | 263 | |
264 | 264 | return $authnetXML; |
265 | 265 | } |
266 | 266 | |
267 | -function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) { |
|
268 | - if ( empty( $response ) || empty( $invoice ) ) { |
|
267 | +function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) { |
|
268 | + if (empty($response) || empty($invoice)) { |
|
269 | 269 | return false; |
270 | 270 | } |
271 | 271 | |
272 | - if ( !empty( $response->approved ) ) { |
|
273 | - $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info ); |
|
272 | + if (!empty($response->approved)) { |
|
273 | + $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info); |
|
274 | 274 | |
275 | - if ( !empty( $subscription ) && $subscription->isSuccessful() ) { |
|
276 | - do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' ); |
|
275 | + if (!empty($subscription) && $subscription->isSuccessful()) { |
|
276 | + do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet'); |
|
277 | 277 | |
278 | - wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ); |
|
278 | + wpinv_authorizenet_subscription_record_signup($subscription, $invoice); |
|
279 | 279 | |
280 | - do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' ); |
|
280 | + do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet'); |
|
281 | 281 | } else { |
282 | - if ( isset( $subscription->messages->message ) ) { |
|
282 | + if (isset($subscription->messages->message)) { |
|
283 | 283 | $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text; |
284 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' ); |
|
284 | + wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing'); |
|
285 | 285 | } else { |
286 | - $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' ); |
|
287 | - wpinv_set_error( 'wpinv_authorize_recurring_error', $error ); |
|
286 | + $error = __('Your subscription cannot be created due to an error.', 'invoicing'); |
|
287 | + wpinv_set_error('wpinv_authorize_recurring_error', $error); |
|
288 | 288 | } |
289 | 289 | |
290 | - wpinv_record_gateway_error( $error, $subscription ); |
|
290 | + wpinv_record_gateway_error($error, $subscription); |
|
291 | 291 | |
292 | - wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ) ); |
|
292 | + wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error)); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 | } |
296 | -add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 ); |
|
296 | +add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3); |
|
297 | 297 | |
298 | -function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) { |
|
299 | - if ( empty( $invoice ) ) { |
|
298 | +function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) { |
|
299 | + if (empty($invoice)) { |
|
300 | 300 | return false; |
301 | 301 | } |
302 | 302 | |
303 | - $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response ); |
|
303 | + $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response); |
|
304 | 304 | |
305 | 305 | try { |
306 | 306 | $authnetXML = wpinv_authorizenet_XML(); |
307 | - $authnetXML->ARBCreateSubscriptionRequest( $params ); |
|
308 | - } catch( Exception $e ) { |
|
307 | + $authnetXML->ARBCreateSubscriptionRequest($params); |
|
308 | + } catch (Exception $e) { |
|
309 | 309 | $authnetXML = array(); |
310 | - wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) ); |
|
310 | + wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing')); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | return $authnetXML; |
314 | 314 | } |
315 | 315 | |
316 | -function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) { |
|
317 | - if ( empty( $invoice ) ) { |
|
316 | +function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) { |
|
317 | + if (empty($invoice)) { |
|
318 | 318 | return false; |
319 | 319 | } |
320 | 320 | |
321 | - $subscription_item = $invoice->get_recurring( true ); |
|
322 | - if ( empty( $subscription_item ) ) { |
|
321 | + $subscription_item = $invoice->get_recurring(true); |
|
322 | + if (empty($subscription_item)) { |
|
323 | 323 | return false; |
324 | 324 | } |
325 | 325 | |
326 | - $card_details = wpinv_authorizenet_generate_card_info( $card_info ); |
|
326 | + $card_details = wpinv_authorizenet_generate_card_info($card_info); |
|
327 | 327 | $subscription_name = $invoice->get_subscription_name(); |
328 | - $initial_amount = wpinv_round_amount( $invoice->get_total() ); |
|
329 | - $recurring_amount = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) ); |
|
328 | + $initial_amount = wpinv_round_amount($invoice->get_total()); |
|
329 | + $recurring_amount = wpinv_round_amount($invoice->get_recurring_details('total')); |
|
330 | 330 | $interval = $subscription_item->get_recurring_interval(); |
331 | 331 | $period = $subscription_item->get_recurring_period(); |
332 | 332 | $bill_times = (int)$subscription_item->get_recurring_limit(); |
333 | 333 | $bill_times = $bill_times > 0 ? $bill_times : 9999; |
334 | 334 | |
335 | - $time_period = wpinv_authorizenet_get_time_period( $interval, $period ); |
|
335 | + $time_period = wpinv_authorizenet_get_time_period($interval, $period); |
|
336 | 336 | $interval = $time_period['interval']; |
337 | 337 | $period = $time_period['period']; |
338 | 338 | |
339 | 339 | $current_tz = date_default_timezone_get(); |
340 | - date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
341 | - $today = date( 'Y-m-d' ); |
|
342 | - date_default_timezone_set( $current_tz ); |
|
340 | + date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts. |
|
341 | + $today = date('Y-m-d'); |
|
342 | + date_default_timezone_set($current_tz); |
|
343 | 343 | |
344 | 344 | $free_trial = $invoice->is_free_trial(); |
345 | - if ( $free_trial && $subscription_item->has_free_trial() ) { |
|
345 | + if ($free_trial && $subscription_item->has_free_trial()) { |
|
346 | 346 | $trial_interval = $subscription_item->get_trial_interval(); |
347 | - $trial_period = $subscription_item->get_trial_period( true ); |
|
347 | + $trial_period = $subscription_item->get_trial_period(true); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | $subscription = array(); |
351 | 351 | $subscription['name'] = $subscription_name; |
352 | 352 | |
353 | 353 | $subscription['paymentSchedule'] = array( |
354 | - 'interval' => array( 'length' => $interval, 'unit' => $period ), |
|
354 | + 'interval' => array('length' => $interval, 'unit' => $period), |
|
355 | 355 | 'startDate' => $today, |
356 | 356 | 'totalOccurrences' => $bill_times, |
357 | - 'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0, |
|
357 | + 'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0, |
|
358 | 358 | ); |
359 | 359 | |
360 | 360 | $subscription['amount'] = $recurring_amount; |
361 | 361 | $subscription['trialAmount'] = $initial_amount; |
362 | - $subscription['payment'] = array( 'creditCard' => $card_details ); |
|
363 | - $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() ); |
|
364 | - $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone ); |
|
362 | + $subscription['payment'] = array('creditCard' => $card_details); |
|
363 | + $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number()); |
|
364 | + $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone); |
|
365 | 365 | |
366 | 366 | $subscription['billTo'] = array( |
367 | 367 | 'firstName' => $invoice->get_first_name(), |
368 | 368 | 'lastName' => $invoice->get_last_name(), |
369 | 369 | 'company' => $invoice->company, |
370 | - 'address' => wp_strip_all_tags( $invoice->get_address(), true ), |
|
370 | + 'address' => wp_strip_all_tags($invoice->get_address(), true), |
|
371 | 371 | 'city' => $invoice->city, |
372 | 372 | 'state' => $invoice->state, |
373 | 373 | 'zip' => $invoice->zip, |
374 | 374 | 'country' => $invoice->country, |
375 | 375 | ); |
376 | 376 | |
377 | - $params = array( 'subscription' => $subscription ); |
|
377 | + $params = array('subscription' => $subscription); |
|
378 | 378 | |
379 | - return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response ); |
|
379 | + return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response); |
|
380 | 380 | } |
381 | 381 | |
382 | -function wpinv_authorizenet_generate_card_info( $card_info = array() ) { |
|
383 | - $card_defaults = array( |
|
382 | +function wpinv_authorizenet_generate_card_info($card_info = array()) { |
|
383 | + $card_defaults = array( |
|
384 | 384 | 'cc_owner' => null, |
385 | 385 | 'cc_number' => null, |
386 | 386 | 'cc_expire_month' => null, |
387 | 387 | 'cc_expire_year' => null, |
388 | 388 | 'cc_cvv2' => null, |
389 | 389 | ); |
390 | - $card_info = wp_parse_args( $card_info, $card_defaults ); |
|
390 | + $card_info = wp_parse_args($card_info, $card_defaults); |
|
391 | 391 | |
392 | 392 | $card_details = array( |
393 | - 'cardNumber' => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ), |
|
394 | - 'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ), |
|
395 | - 'cardCode' => sanitize_text_field( $card_info['cc_cvv2'] ), |
|
393 | + 'cardNumber' => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])), |
|
394 | + 'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']), |
|
395 | + 'cardCode' => sanitize_text_field($card_info['cc_cvv2']), |
|
396 | 396 | ); |
397 | 397 | |
398 | 398 | return $card_details; |
399 | 399 | } |
400 | 400 | |
401 | -function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) { |
|
402 | - if ( empty( $invoice ) || empty( $subscription ) ) { |
|
401 | +function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) { |
|
402 | + if (empty($invoice) || empty($subscription)) { |
|
403 | 403 | return false; |
404 | 404 | } |
405 | 405 | |
406 | - $subscription_item = $invoice->get_recurring( true ); |
|
407 | - if ( empty( $subscription_item ) ) { |
|
406 | + $subscription_item = $invoice->get_recurring(true); |
|
407 | + if (empty($subscription_item)) { |
|
408 | 408 | return false; |
409 | 409 | } |
410 | 410 | |
411 | 411 | $invoice_id = $invoice->ID; |
412 | 412 | $subscriptionId = (array)$subscription->subscriptionId; |
413 | - $subscription_id = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $invoice_id; |
|
413 | + $subscription_id = !empty($subscriptionId[0]) ? $subscriptionId[0] : $invoice_id; |
|
414 | 414 | |
415 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ) ); |
|
415 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id)); |
|
416 | 416 | |
417 | 417 | $status = $invoice->is_free_trial() && $subscription_item->has_free_trial() ? 'trialing' : 'active'; |
418 | 418 | |
@@ -420,16 +420,16 @@ discard block |
||
420 | 420 | 'profile_id' => $subscription_id, |
421 | 421 | 'item_id' => $subscription_item->ID, |
422 | 422 | 'initial_amount' => $invoice->get_total(), |
423 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
423 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
424 | 424 | 'period' => $subscription_item->get_recurring_period(), |
425 | 425 | 'interval' => $subscription_item->get_recurring_interval(), |
426 | 426 | 'bill_times' => $subscription_item->get_recurring_limit(), |
427 | - 'expiration' => $invoice->get_new_expiration( $subscription_item->ID ), |
|
427 | + 'expiration' => $invoice->get_new_expiration($subscription_item->ID), |
|
428 | 428 | 'status' => $status, |
429 | - 'created' => current_time( 'mysql', 0 ) |
|
429 | + 'created' => current_time('mysql', 0) |
|
430 | 430 | ); |
431 | 431 | |
432 | - if ( $invoice->is_free_trial() && $subscription_item->has_free_trial() ) { |
|
432 | + if ($invoice->is_free_trial() && $subscription_item->has_free_trial()) { |
|
433 | 433 | $args['trial_period'] = $subscription_item->get_trial_period(); |
434 | 434 | $args['trial_interval'] = $subscription_item->get_trial_interval(); |
435 | 435 | } else { |
@@ -437,58 +437,58 @@ discard block |
||
437 | 437 | $args['trial_interval'] = 0; |
438 | 438 | } |
439 | 439 | |
440 | - return $invoice->update_subscription( $args ); |
|
440 | + return $invoice->update_subscription($args); |
|
441 | 441 | } |
442 | 442 | |
443 | -function wpinv_authorizenet_validate_checkout( $valid_data, $post ) { |
|
444 | - if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) { |
|
443 | +function wpinv_authorizenet_validate_checkout($valid_data, $post) { |
|
444 | + if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') { |
|
445 | 445 | $error = false; |
446 | 446 | |
447 | - if ( empty( $post['authorizenet']['cc_owner'] ) ) { |
|
447 | + if (empty($post['authorizenet']['cc_owner'])) { |
|
448 | 448 | $error = true; |
449 | - wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing')); |
|
449 | + wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing')); |
|
450 | 450 | } |
451 | - if ( empty( $post['authorizenet']['cc_number'] ) ) { |
|
451 | + if (empty($post['authorizenet']['cc_number'])) { |
|
452 | 452 | $error = true; |
453 | - wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing')); |
|
453 | + wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing')); |
|
454 | 454 | } |
455 | - if ( empty( $post['authorizenet']['cc_expire_month'] ) ) { |
|
455 | + if (empty($post['authorizenet']['cc_expire_month'])) { |
|
456 | 456 | $error = true; |
457 | - wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing')); |
|
457 | + wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing')); |
|
458 | 458 | } |
459 | - if ( empty( $post['authorizenet']['cc_expire_year'] ) ) { |
|
459 | + if (empty($post['authorizenet']['cc_expire_year'])) { |
|
460 | 460 | $error = true; |
461 | - wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing')); |
|
461 | + wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing')); |
|
462 | 462 | } |
463 | - if ( empty( $post['authorizenet']['cc_cvv2'] ) ) { |
|
463 | + if (empty($post['authorizenet']['cc_cvv2'])) { |
|
464 | 464 | $error = true; |
465 | - wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) ); |
|
465 | + wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing')); |
|
466 | 466 | } |
467 | 467 | |
468 | - if ( $error ) { |
|
468 | + if ($error) { |
|
469 | 469 | return; |
470 | 470 | } |
471 | 471 | |
472 | 472 | $invoice = wpinv_get_invoice_cart(); |
473 | 473 | |
474 | - if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) { |
|
475 | - $subscription_item = $invoice->get_recurring( true ); |
|
474 | + if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) { |
|
475 | + $subscription_item = $invoice->get_recurring(true); |
|
476 | 476 | |
477 | 477 | $interval = $subscription_item->get_recurring_interval(); |
478 | 478 | $period = $subscription_item->get_recurring_period(); |
479 | 479 | |
480 | - if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) { |
|
481 | - wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) ); |
|
480 | + if ($period == 'D' && ($interval < 7 || $interval > 365)) { |
|
481 | + wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing')); |
|
482 | 482 | } |
483 | 483 | } |
484 | 484 | } |
485 | 485 | } |
486 | -add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 ); |
|
486 | +add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2); |
|
487 | 487 | |
488 | -function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) { |
|
489 | - $subscription_interval = absint( $subscription_interval ); |
|
488 | +function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) { |
|
489 | + $subscription_interval = absint($subscription_interval); |
|
490 | 490 | |
491 | - switch( $subscription_period ) { |
|
491 | + switch ($subscription_period) { |
|
492 | 492 | case 'W': |
493 | 493 | case 'week': |
494 | 494 | case 'weeks': |
@@ -498,14 +498,14 @@ discard block |
||
498 | 498 | case 'M': |
499 | 499 | case 'month': |
500 | 500 | case 'months': |
501 | - if ( $subscription_interval > 12 ) { |
|
501 | + if ($subscription_interval > 12) { |
|
502 | 502 | $subscription_interval = 12; |
503 | 503 | } |
504 | 504 | |
505 | 505 | $interval = $subscription_interval; |
506 | 506 | $period = 'months'; |
507 | 507 | |
508 | - if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) { |
|
508 | + if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) { |
|
509 | 509 | $interval = $subscription_interval * 30; |
510 | 510 | $period = 'days'; |
511 | 511 | } |
@@ -522,40 +522,40 @@ discard block |
||
522 | 522 | break; |
523 | 523 | } |
524 | 524 | |
525 | - return compact( 'interval', 'period' ); |
|
525 | + return compact('interval', 'period'); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | function wpinv_authorizenet_process_ipn() { |
529 | - if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) { |
|
529 | + if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) { |
|
530 | 530 | return; |
531 | 531 | } |
532 | 532 | |
533 | - $subscription_id = intval( $_POST['x_subscription_id'] ); |
|
533 | + $subscription_id = intval($_POST['x_subscription_id']); |
|
534 | 534 | |
535 | - if ( $subscription_id ) { |
|
536 | - $transaction_id = sanitize_text_field( $_POST['x_trans_id'] ); |
|
537 | - $renewal_amount = sanitize_text_field( $_POST['x_amount'] ); |
|
538 | - $response_code = intval( $_POST['x_response_code'] ); |
|
539 | - $reason_code = intval( $_POST['x_response_reason_code'] ); |
|
535 | + if ($subscription_id) { |
|
536 | + $transaction_id = sanitize_text_field($_POST['x_trans_id']); |
|
537 | + $renewal_amount = sanitize_text_field($_POST['x_amount']); |
|
538 | + $response_code = intval($_POST['x_response_code']); |
|
539 | + $reason_code = intval($_POST['x_response_reason_code']); |
|
540 | 540 | |
541 | - if ( 1 == $response_code ) { |
|
541 | + if (1 == $response_code) { |
|
542 | 542 | // Approved |
543 | - do_action( 'wpinv_authorizenet_renewal_payment', $transaction_id ); |
|
544 | - } else if ( 2 == $response_code ) { |
|
543 | + do_action('wpinv_authorizenet_renewal_payment', $transaction_id); |
|
544 | + } else if (2 == $response_code) { |
|
545 | 545 | // Declined |
546 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id ); |
|
547 | - do_action( 'wpinv_authorizenet_renewal_error', $transaction_id ); |
|
548 | - } else if ( 3 == $response_code || 8 == $reason_code ) { |
|
546 | + do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id); |
|
547 | + do_action('wpinv_authorizenet_renewal_error', $transaction_id); |
|
548 | + } else if (3 == $response_code || 8 == $reason_code) { |
|
549 | 549 | // An expired card |
550 | - do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id ); |
|
551 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $transaction_id ); |
|
550 | + do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id); |
|
551 | + do_action('wpinv_authorizenet_renewal_payment_error', $transaction_id); |
|
552 | 552 | |
553 | 553 | } else { |
554 | 554 | // Other Error |
555 | - do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription ); |
|
555 | + do_action('wpinv_authorizenet_renewal_payment_error', $subscription); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | exit; |
559 | 559 | } |
560 | 560 | } |
561 | -add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' ); |
|
562 | 561 | \ No newline at end of file |
562 | +add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn'); |
|
563 | 563 | \ No newline at end of file |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -add_action( 'wpinv_paypal_cc_form', '__return_false' ); |
|
6 | -add_filter( 'wpinv_paypal_support_subscription', '__return_true' ); |
|
5 | +add_action('wpinv_paypal_cc_form', '__return_false'); |
|
6 | +add_filter('wpinv_paypal_support_subscription', '__return_true'); |
|
7 | 7 | |
8 | -function wpinv_process_paypal_payment( $purchase_data ) { |
|
9 | - if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) { |
|
10 | - wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
8 | +function wpinv_process_paypal_payment($purchase_data) { |
|
9 | + if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) { |
|
10 | + wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403)); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | // Collect payment data |
@@ -21,34 +21,34 @@ discard block |
||
21 | 21 | 'user_info' => $purchase_data['user_info'], |
22 | 22 | 'cart_details' => $purchase_data['cart_details'], |
23 | 23 | 'gateway' => 'paypal', |
24 | - 'status' => !empty( $purchase_data['buy_now'] ) ? 'private' : 'pending' |
|
24 | + 'status' => !empty($purchase_data['buy_now']) ? 'private' : 'pending' |
|
25 | 25 | ); |
26 | 26 | |
27 | 27 | // Record the pending payment |
28 | - $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] ); |
|
28 | + $invoice = wpinv_get_invoice($purchase_data['invoice_id']); |
|
29 | 29 | |
30 | 30 | // Check payment |
31 | - if ( ! $invoice ) { |
|
31 | + if (!$invoice) { |
|
32 | 32 | // Record the error |
33 | - wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $payment ); |
|
33 | + wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $payment); |
|
34 | 34 | // Problems? send back |
35 | - wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] ); |
|
35 | + wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']); |
|
36 | 36 | } else { |
37 | 37 | // Only send to PayPal if the pending payment is created successfully |
38 | - $listener_url = wpinv_get_ipn_url( 'paypal' ); |
|
38 | + $listener_url = wpinv_get_ipn_url('paypal'); |
|
39 | 39 | |
40 | 40 | // Get the success url |
41 | - $return_url = add_query_arg( array( |
|
41 | + $return_url = add_query_arg(array( |
|
42 | 42 | 'payment-confirm' => 'paypal', |
43 | 43 | 'invoice-id' => $invoice->ID |
44 | - ), get_permalink( wpinv_get_option( 'success_page', false ) ) ); |
|
44 | + ), get_permalink(wpinv_get_option('success_page', false))); |
|
45 | 45 | |
46 | 46 | // Get the PayPal redirect uri |
47 | - $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?'; |
|
47 | + $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?'; |
|
48 | 48 | |
49 | 49 | // Setup PayPal arguments |
50 | 50 | $paypal_args = array( |
51 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
51 | + 'business' => wpinv_get_option('paypal_email', false), |
|
52 | 52 | 'email' => $invoice->get_email(), |
53 | 53 | 'first_name' => $invoice->get_first_name(), |
54 | 54 | 'last_name' => $invoice->get_last_name(), |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | 'shipping' => '0', |
58 | 58 | 'no_note' => '1', |
59 | 59 | 'currency_code' => wpinv_get_currency(), |
60 | - 'charset' => get_bloginfo( 'charset' ), |
|
60 | + 'charset' => get_bloginfo('charset'), |
|
61 | 61 | 'custom' => $invoice->ID, |
62 | 62 | 'rm' => '2', |
63 | 63 | 'return' => $return_url, |
64 | - 'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ), |
|
64 | + 'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID), |
|
65 | 65 | 'notify_url' => $listener_url, |
66 | - 'cbt' => get_bloginfo( 'name' ), |
|
66 | + 'cbt' => get_bloginfo('name'), |
|
67 | 67 | 'bn' => 'WPInvoicing_SP', |
68 | 68 | 'lc' => 'US' // this will force paypal site to english |
69 | 69 | ); |
@@ -79,57 +79,57 @@ discard block |
||
79 | 79 | 'upload' => '1' |
80 | 80 | ); |
81 | 81 | |
82 | - $paypal_args = array_merge( $paypal_extra_args, $paypal_args ); |
|
82 | + $paypal_args = array_merge($paypal_extra_args, $paypal_args); |
|
83 | 83 | |
84 | 84 | // Add cart items |
85 | 85 | $i = 1; |
86 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
87 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
86 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
87 | + foreach ($purchase_data['cart_details'] as $item) { |
|
88 | 88 | $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1; |
89 | - $item_amount = round( $item['subtotal'] / $item['quantity'], 2 ); |
|
89 | + $item_amount = round($item['subtotal'] / $item['quantity'], 2); |
|
90 | 90 | |
91 | - if ( $item_amount <= 0 ) { |
|
91 | + if ($item_amount <= 0) { |
|
92 | 92 | $item_amount = 0; |
93 | 93 | } |
94 | 94 | |
95 | - $paypal_args['item_number_' . $i ] = $item['id']; |
|
96 | - $paypal_args['item_name_' . $i ] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) ); |
|
97 | - $paypal_args['quantity_' . $i ] = $item['quantity']; |
|
98 | - $paypal_args['amount_' . $i ] = $item_amount; |
|
99 | - $paypal_args['discount_amount_' . $i ] = $item['discount']; |
|
95 | + $paypal_args['item_number_' . $i] = $item['id']; |
|
96 | + $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8')); |
|
97 | + $paypal_args['quantity_' . $i] = $item['quantity']; |
|
98 | + $paypal_args['amount_' . $i] = $item_amount; |
|
99 | + $paypal_args['discount_amount_' . $i] = $item['discount']; |
|
100 | 100 | |
101 | 101 | $i++; |
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | 105 | // Add taxes to the cart |
106 | - if ( wpinv_use_taxes() ) { |
|
107 | - $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax() ); |
|
106 | + if (wpinv_use_taxes()) { |
|
107 | + $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax()); |
|
108 | 108 | } |
109 | 109 | |
110 | - $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice ); |
|
110 | + $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice); |
|
111 | 111 | |
112 | 112 | // Build query |
113 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
113 | + $paypal_redirect .= http_build_query($paypal_args); |
|
114 | 114 | |
115 | 115 | // Fix for some sites that encode the entities |
116 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
116 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
117 | 117 | |
118 | 118 | // Get rid of cart contents |
119 | 119 | wpinv_empty_cart(); |
120 | 120 | |
121 | 121 | // Redirect to PayPal |
122 | - wp_redirect( $paypal_redirect ); |
|
122 | + wp_redirect($paypal_redirect); |
|
123 | 123 | exit; |
124 | 124 | } |
125 | 125 | } |
126 | -add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' ); |
|
126 | +add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment'); |
|
127 | 127 | |
128 | -function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) { |
|
129 | - if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) { |
|
130 | - $item = new WPInv_Item( $item_id ); |
|
128 | +function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) { |
|
129 | + if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) { |
|
130 | + $item = new WPInv_Item($item_id); |
|
131 | 131 | |
132 | - if ( empty( $item ) ) { |
|
132 | + if (empty($item)) { |
|
133 | 133 | return $paypal_args; |
134 | 134 | } |
135 | 135 | |
@@ -137,24 +137,24 @@ discard block |
||
137 | 137 | $interval = $item->get_recurring_interval(); |
138 | 138 | $bill_times = (int)$item->get_recurring_limit(); |
139 | 139 | |
140 | - $initial_amount = wpinv_round_amount( $invoice->get_total() ); |
|
141 | - $recurring_amount = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) ); |
|
140 | + $initial_amount = wpinv_round_amount($invoice->get_total()); |
|
141 | + $recurring_amount = wpinv_round_amount($invoice->get_recurring_details('total')); |
|
142 | 142 | |
143 | 143 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
144 | 144 | $paypal_args['sra'] = '1'; |
145 | 145 | $paypal_args['src'] = '1'; |
146 | 146 | |
147 | 147 | // Set item description |
148 | - $paypal_args['item_name'] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( array( 'id' => $item->ID ) ), ENT_COMPAT, 'UTF-8' ) ); |
|
148 | + $paypal_args['item_name'] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name(array('id' => $item->ID)), ENT_COMPAT, 'UTF-8')); |
|
149 | 149 | |
150 | - if ( $invoice->is_free_trial() && $item->has_free_trial() ) { |
|
150 | + if ($invoice->is_free_trial() && $item->has_free_trial()) { |
|
151 | 151 | $paypal_args['a1'] = $initial_amount; |
152 | 152 | $paypal_args['p1'] = $item->get_trial_interval(); |
153 | 153 | $paypal_args['t1'] = $item->get_trial_period(); |
154 | 154 | |
155 | 155 | // Set the recurring amount |
156 | 156 | $paypal_args['a3'] = $recurring_amount; |
157 | - } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) { |
|
157 | + } else if ($initial_amount != $recurring_amount && $bill_times != 1) { |
|
158 | 158 | $paypal_args['a1'] = $initial_amount; |
159 | 159 | $paypal_args['p1'] = $interval; |
160 | 160 | $paypal_args['t1'] = $period; |
@@ -162,63 +162,63 @@ discard block |
||
162 | 162 | // Set the recurring amount |
163 | 163 | $paypal_args['a3'] = $recurring_amount; |
164 | 164 | |
165 | - if ( $bill_times > 1 ) { |
|
165 | + if ($bill_times > 1) { |
|
166 | 166 | $bill_times--; |
167 | 167 | } |
168 | 168 | } else { |
169 | - $paypal_args['a3'] = $initial_amount; |
|
169 | + $paypal_args['a3'] = $initial_amount; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | $paypal_args['p3'] = $interval; |
173 | 173 | $paypal_args['t3'] = $period; |
174 | 174 | |
175 | - if ( $bill_times > 1 ) { |
|
175 | + if ($bill_times > 1) { |
|
176 | 176 | // Make sure it's not over the max of 52 |
177 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
177 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | // Remove cart items |
181 | 181 | $i = 1; |
182 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
183 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
184 | - if ( isset( $paypal_args['item_number_' . $i] ) ) { |
|
185 | - unset( $paypal_args['item_number_' . $i] ); |
|
182 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
183 | + foreach ($purchase_data['cart_details'] as $item) { |
|
184 | + if (isset($paypal_args['item_number_' . $i])) { |
|
185 | + unset($paypal_args['item_number_' . $i]); |
|
186 | 186 | } |
187 | - if ( isset( $paypal_args['item_name_' . $i] ) ) { |
|
188 | - unset( $paypal_args['item_name_' . $i] ); |
|
187 | + if (isset($paypal_args['item_name_' . $i])) { |
|
188 | + unset($paypal_args['item_name_' . $i]); |
|
189 | 189 | } |
190 | - if ( isset( $paypal_args['quantity_' . $i] ) ) { |
|
191 | - unset( $paypal_args['quantity_' . $i] ); |
|
190 | + if (isset($paypal_args['quantity_' . $i])) { |
|
191 | + unset($paypal_args['quantity_' . $i]); |
|
192 | 192 | } |
193 | - if ( isset( $paypal_args['amount_' . $i] ) ) { |
|
194 | - unset( $paypal_args['amount_' . $i] ); |
|
193 | + if (isset($paypal_args['amount_' . $i])) { |
|
194 | + unset($paypal_args['amount_' . $i]); |
|
195 | 195 | } |
196 | - if ( isset( $paypal_args['discount_amount_' . $i] ) ) { |
|
197 | - unset( $paypal_args['discount_amount_' . $i] ); |
|
196 | + if (isset($paypal_args['discount_amount_' . $i])) { |
|
197 | + unset($paypal_args['discount_amount_' . $i]); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | $i++; |
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
204 | - if ( isset( $paypal_args['tax_cart'] ) ) { |
|
205 | - unset( $paypal_args['tax_cart'] ); |
|
204 | + if (isset($paypal_args['tax_cart'])) { |
|
205 | + unset($paypal_args['tax_cart']); |
|
206 | 206 | } |
207 | 207 | |
208 | - if ( isset( $paypal_args['upload'] ) ) { |
|
209 | - unset( $paypal_args['upload'] ); |
|
208 | + if (isset($paypal_args['upload'])) { |
|
209 | + unset($paypal_args['upload']); |
|
210 | 210 | } |
211 | 211 | |
212 | - $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice ); |
|
212 | + $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | return $paypal_args; |
216 | 216 | } |
217 | -add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
|
217 | +add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3); |
|
218 | 218 | |
219 | 219 | function wpinv_process_paypal_ipn() { |
220 | 220 | // Check the request method is POST |
221 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
221 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
222 | 222 | return; |
223 | 223 | } |
224 | 224 | |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | $post_data = ''; |
227 | 227 | |
228 | 228 | // Fallback just in case post_max_size is lower than needed |
229 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
230 | - $post_data = file_get_contents( 'php://input' ); |
|
229 | + if (ini_get('allow_url_fopen')) { |
|
230 | + $post_data = file_get_contents('php://input'); |
|
231 | 231 | } else { |
232 | 232 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
233 | - ini_set( 'post_max_size', '12M' ); |
|
233 | + ini_set('post_max_size', '12M'); |
|
234 | 234 | } |
235 | 235 | // Start the encoded data collection with notification command |
236 | 236 | $encoded_data = 'cmd=_notify-validate'; |
@@ -239,43 +239,43 @@ discard block |
||
239 | 239 | $arg_separator = wpinv_get_php_arg_separator_output(); |
240 | 240 | |
241 | 241 | // Verify there is a post_data |
242 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
242 | + if ($post_data || strlen($post_data) > 0) { |
|
243 | 243 | // Append the data |
244 | - $encoded_data .= $arg_separator.$post_data; |
|
244 | + $encoded_data .= $arg_separator . $post_data; |
|
245 | 245 | } else { |
246 | 246 | // Check if POST is empty |
247 | - if ( empty( $_POST ) ) { |
|
247 | + if (empty($_POST)) { |
|
248 | 248 | // Nothing to do |
249 | 249 | return; |
250 | 250 | } else { |
251 | 251 | // Loop through each POST |
252 | - foreach ( $_POST as $key => $value ) { |
|
252 | + foreach ($_POST as $key => $value) { |
|
253 | 253 | // Encode the value and append the data |
254 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
254 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
255 | 255 | } |
256 | 256 | } |
257 | 257 | } |
258 | 258 | |
259 | 259 | // Convert collected post data to an array |
260 | - parse_str( $encoded_data, $encoded_data_array ); |
|
260 | + parse_str($encoded_data, $encoded_data_array); |
|
261 | 261 | |
262 | - foreach ( $encoded_data_array as $key => $value ) { |
|
263 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
264 | - $new_key = str_replace( '&', '&', $key ); |
|
265 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
262 | + foreach ($encoded_data_array as $key => $value) { |
|
263 | + if (false !== strpos($key, 'amp;')) { |
|
264 | + $new_key = str_replace('&', '&', $key); |
|
265 | + $new_key = str_replace('amp;', '&', $new_key); |
|
266 | 266 | |
267 | - unset( $encoded_data_array[ $key ] ); |
|
268 | - $encoded_data_array[ $new_key ] = $value; |
|
267 | + unset($encoded_data_array[$key]); |
|
268 | + $encoded_data_array[$new_key] = $value; |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Get the PayPal redirect uri |
273 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
273 | + $paypal_redirect = wpinv_get_paypal_redirect(true); |
|
274 | 274 | |
275 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
275 | + if (!wpinv_get_option('disable_paypal_verification', false)) { |
|
276 | 276 | // Validate the IPN |
277 | 277 | |
278 | - $remote_post_vars = array( |
|
278 | + $remote_post_vars = array( |
|
279 | 279 | 'method' => 'POST', |
280 | 280 | 'timeout' => 45, |
281 | 281 | 'redirection' => 5, |
@@ -293,21 +293,21 @@ discard block |
||
293 | 293 | ); |
294 | 294 | |
295 | 295 | // Get response |
296 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
296 | + $api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars); |
|
297 | 297 | |
298 | - if ( is_wp_error( $api_response ) ) { |
|
299 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
298 | + if (is_wp_error($api_response)) { |
|
299 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
300 | 300 | return; // Something went wrong |
301 | 301 | } |
302 | 302 | |
303 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
304 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
303 | + if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) { |
|
304 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
305 | 305 | return; // Response not okay |
306 | 306 | } |
307 | 307 | } |
308 | 308 | |
309 | 309 | // Check if $post_data_array has been populated |
310 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
310 | + if (!is_array($encoded_data_array) && !empty($encoded_data_array)) |
|
311 | 311 | return; |
312 | 312 | |
313 | 313 | $defaults = array( |
@@ -315,215 +315,215 @@ discard block |
||
315 | 315 | 'payment_status' => '' |
316 | 316 | ); |
317 | 317 | |
318 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
318 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
319 | 319 | |
320 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
320 | + $invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
321 | 321 | |
322 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
322 | + wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__); |
|
323 | 323 | |
324 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
324 | + if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) { |
|
325 | 325 | // Allow PayPal IPN types to be processed separately |
326 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
326 | + do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id); |
|
327 | 327 | } else { |
328 | 328 | // Fallback to web accept just in case the txn_type isn't present |
329 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
329 | + do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id); |
|
330 | 330 | } |
331 | 331 | exit; |
332 | 332 | } |
333 | -add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
|
333 | +add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn'); |
|
334 | 334 | |
335 | -function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
|
336 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
335 | +function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) { |
|
336 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
337 | 337 | return; |
338 | 338 | } |
339 | 339 | |
340 | - if( empty( $invoice_id ) ) { |
|
340 | + if (empty($invoice_id)) { |
|
341 | 341 | return; |
342 | 342 | } |
343 | 343 | |
344 | 344 | // Collect payment details |
345 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
345 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
346 | 346 | $paypal_amount = $data['mc_gross']; |
347 | - $payment_status = strtolower( $data['payment_status'] ); |
|
348 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
349 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
350 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
347 | + $payment_status = strtolower($data['payment_status']); |
|
348 | + $currency_code = strtolower($data['mc_currency']); |
|
349 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
350 | + $payment_meta = wpinv_get_invoice_meta($invoice_id); |
|
351 | 351 | |
352 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
352 | + if (wpinv_get_payment_gateway($invoice_id) != 'paypal') { |
|
353 | 353 | return; // this isn't a PayPal standard IPN |
354 | 354 | } |
355 | 355 | |
356 | 356 | // Verify payment recipient |
357 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
358 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
359 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
360 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) ); |
|
357 | + if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) { |
|
358 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
359 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
360 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing')); |
|
361 | 361 | return; |
362 | 362 | } |
363 | 363 | |
364 | 364 | // Verify payment currency |
365 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
366 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
367 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
368 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) ); |
|
365 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
366 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
367 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
368 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing')); |
|
369 | 369 | return; |
370 | 370 | } |
371 | 371 | |
372 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
372 | + if (!wpinv_get_payment_user_email($invoice_id)) { |
|
373 | 373 | // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
374 | 374 | // No email associated with purchase, so store from PayPal |
375 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
375 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']); |
|
376 | 376 | |
377 | 377 | // Setup and store the customer's details |
378 | 378 | $user_info = array( |
379 | 379 | 'user_id' => '-1', |
380 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
381 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
382 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
380 | + 'email' => sanitize_text_field($data['payer_email']), |
|
381 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
382 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
383 | 383 | 'discount' => '', |
384 | 384 | ); |
385 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
386 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
387 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
388 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
389 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
385 | + $user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
386 | + $user_info['city'] = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
387 | + $user_info['state'] = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
388 | + $user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
389 | + $user_info['zip'] = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
390 | 390 | |
391 | 391 | $payment_meta['user_info'] = $user_info; |
392 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
392 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta); |
|
393 | 393 | } |
394 | 394 | |
395 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
395 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
396 | 396 | // Process a refund |
397 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
397 | + wpinv_process_paypal_refund($data, $invoice_id); |
|
398 | 398 | } else { |
399 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
399 | + if (get_post_status($invoice_id) == 'publish') { |
|
400 | 400 | return; // Only paid payments once |
401 | 401 | } |
402 | 402 | |
403 | 403 | // Retrieve the total purchase amount (before PayPal) |
404 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
404 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
405 | 405 | |
406 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
406 | + if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
407 | 407 | // The prices don't match |
408 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
409 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
410 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) ); |
|
408 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
409 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
410 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing')); |
|
411 | 411 | return; |
412 | 412 | } |
413 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
413 | + if ($purchase_key != wpinv_get_payment_key($invoice_id)) { |
|
414 | 414 | // Purchase keys don't match |
415 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
416 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
417 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) ); |
|
415 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
416 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
417 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing')); |
|
418 | 418 | return; |
419 | 419 | } |
420 | 420 | |
421 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
422 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) ); |
|
423 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
424 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
425 | - } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
421 | + if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) { |
|
422 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id'])); |
|
423 | + wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']); |
|
424 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
425 | + } else if ('pending' == $payment_status && isset($data['pending_reason'])) { |
|
426 | 426 | // Look for possible pending reasons, such as an echeck |
427 | 427 | $note = ''; |
428 | 428 | |
429 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
429 | + switch (strtolower($data['pending_reason'])) { |
|
430 | 430 | case 'echeck' : |
431 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
431 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing'); |
|
432 | 432 | break; |
433 | 433 | |
434 | 434 | case 'address' : |
435 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
435 | + $note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing'); |
|
436 | 436 | break; |
437 | 437 | |
438 | 438 | case 'intl' : |
439 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
439 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing'); |
|
440 | 440 | break; |
441 | 441 | |
442 | 442 | case 'multi-currency' : |
443 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
443 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing'); |
|
444 | 444 | break; |
445 | 445 | |
446 | 446 | case 'paymentreview' : |
447 | 447 | case 'regulatory_review' : |
448 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
448 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing'); |
|
449 | 449 | break; |
450 | 450 | |
451 | 451 | case 'unilateral' : |
452 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
452 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing'); |
|
453 | 453 | break; |
454 | 454 | |
455 | 455 | case 'upgrade' : |
456 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
456 | + $note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing'); |
|
457 | 457 | break; |
458 | 458 | |
459 | 459 | case 'verify' : |
460 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
460 | + $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing'); |
|
461 | 461 | break; |
462 | 462 | |
463 | 463 | case 'other' : |
464 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
464 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing'); |
|
465 | 465 | break; |
466 | 466 | } |
467 | 467 | |
468 | - if ( ! empty( $note ) ) { |
|
469 | - wpinv_insert_payment_note( $invoice_id, $note ); |
|
468 | + if (!empty($note)) { |
|
469 | + wpinv_insert_payment_note($invoice_id, $note); |
|
470 | 470 | } |
471 | 471 | } else { |
472 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) ); |
|
472 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status)); |
|
473 | 473 | } |
474 | 474 | } |
475 | 475 | } |
476 | -add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
|
476 | +add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2); |
|
477 | 477 | |
478 | 478 | // Process PayPal subscription sign ups |
479 | -add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' ); |
|
479 | +add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup'); |
|
480 | 480 | |
481 | 481 | // Process PayPal subscription payments |
482 | -add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' ); |
|
482 | +add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment'); |
|
483 | 483 | |
484 | 484 | // Process PayPal subscription cancellations |
485 | -add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' ); |
|
485 | +add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel'); |
|
486 | 486 | |
487 | 487 | // Process PayPal subscription end of term notices |
488 | -add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' ); |
|
488 | +add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot'); |
|
489 | 489 | |
490 | 490 | // Process PayPal payment failed |
491 | -add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' ); |
|
491 | +add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed'); |
|
492 | 492 | |
493 | 493 | |
494 | 494 | /** |
495 | 495 | * Process the subscription started IPN. |
496 | 496 | */ |
497 | -function wpinv_process_paypal_subscr_signup( $ipn_data ) { |
|
498 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
499 | - if( empty( $parent_invoice_id ) ) { |
|
497 | +function wpinv_process_paypal_subscr_signup($ipn_data) { |
|
498 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
499 | + if (empty($parent_invoice_id)) { |
|
500 | 500 | return; |
501 | 501 | } |
502 | 502 | |
503 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
504 | - if ( empty( $invoice ) ) { |
|
503 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
504 | + if (empty($invoice)) { |
|
505 | 505 | return; |
506 | 506 | } |
507 | 507 | |
508 | - if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) { |
|
509 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ) ); |
|
510 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['invoice'] ); |
|
508 | + if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) { |
|
509 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice'])); |
|
510 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['invoice']); |
|
511 | 511 | } |
512 | 512 | |
513 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
513 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
514 | 514 | sleep(1); |
515 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ) ); |
|
515 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id'])); |
|
516 | 516 | |
517 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
518 | - if ( false === $subscription ) { |
|
517 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
518 | + if (false === $subscription) { |
|
519 | 519 | return; |
520 | 520 | } |
521 | 521 | |
522 | - $cart_details = $invoice->cart_details; |
|
522 | + $cart_details = $invoice->cart_details; |
|
523 | 523 | |
524 | - if ( !empty( $cart_details ) ) { |
|
525 | - foreach ( $cart_details as $cart_item ) { |
|
526 | - $item = new WPInv_Item( $cart_item['id'] ); |
|
524 | + if (!empty($cart_details)) { |
|
525 | + foreach ($cart_details as $cart_item) { |
|
526 | + $item = new WPInv_Item($cart_item['id']); |
|
527 | 527 | |
528 | 528 | $status = $invoice->is_free_trial() && $item->has_free_trial() ? 'trialing' : 'active'; |
529 | 529 | |
@@ -532,15 +532,15 @@ discard block |
||
532 | 532 | 'status' => $status, |
533 | 533 | 'period' => $item->get_recurring_period(), |
534 | 534 | 'initial_amount' => $invoice->get_total(), |
535 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
535 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
536 | 536 | 'interval' => $item->get_recurring_interval(), |
537 | 537 | 'bill_times' => $item->get_recurring_limit(), |
538 | - 'expiration' => $invoice->get_new_expiration( $cart_item['id'] ), |
|
538 | + 'expiration' => $invoice->get_new_expiration($cart_item['id']), |
|
539 | 539 | 'profile_id' => $ipn_data['subscr_id'], |
540 | - 'created' => date_i18n( 'Y-m-d H:i:s', strtotime( $ipn_data['subscr_date'] ) ) |
|
540 | + 'created' => date_i18n('Y-m-d H:i:s', strtotime($ipn_data['subscr_date'])) |
|
541 | 541 | ); |
542 | 542 | |
543 | - if ( $item->has_free_trial() ) { |
|
543 | + if ($item->has_free_trial()) { |
|
544 | 544 | $args['trial_period'] = $item->get_trial_period(); |
545 | 545 | $args['trial_interval'] = $item->get_trial_interval(); |
546 | 546 | } else { |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | } |
550 | 550 | |
551 | 551 | |
552 | - $subscription->update_subscription( $args ); |
|
552 | + $subscription->update_subscription($args); |
|
553 | 553 | } |
554 | 554 | } |
555 | 555 | } |
@@ -557,39 +557,39 @@ discard block |
||
557 | 557 | /** |
558 | 558 | * Process the subscription payment received IPN. |
559 | 559 | */ |
560 | -function wpinv_process_paypal_subscr_payment( $ipn_data ) { |
|
561 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
560 | +function wpinv_process_paypal_subscr_payment($ipn_data) { |
|
561 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
562 | 562 | |
563 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
564 | - if ( false === $subscription ) { |
|
563 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
564 | + if (false === $subscription) { |
|
565 | 565 | return; |
566 | 566 | } |
567 | 567 | |
568 | - $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id ); |
|
569 | - $signup_date = strtotime( $subscription->get_subscription_created() ); |
|
570 | - $today = date_i18n( 'Y-m-d', $signup_date ) == date_i18n( 'Y-m-d', strtotime( $ipn_data['payment_date'] ) ); |
|
568 | + $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id); |
|
569 | + $signup_date = strtotime($subscription->get_subscription_created()); |
|
570 | + $today = date_i18n('Y-m-d', $signup_date) == date_i18n('Y-m-d', strtotime($ipn_data['payment_date'])); |
|
571 | 571 | |
572 | 572 | // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet. |
573 | - if ( $today && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) { |
|
574 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
573 | + if ($today && (!$transaction_id || $transaction_id == $parent_invoice_id)) { |
|
574 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
575 | 575 | sleep(1); |
576 | 576 | |
577 | 577 | // This is the very first payment |
578 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
579 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) ); |
|
578 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
579 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id'])); |
|
580 | 580 | return; |
581 | 581 | } |
582 | 582 | |
583 | - if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) { |
|
583 | + if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) { |
|
584 | 584 | return; // Payment already recorded |
585 | 585 | } |
586 | 586 | |
587 | - $currency_code = strtolower( $ipn_data['mc_currency'] ); |
|
587 | + $currency_code = strtolower($ipn_data['mc_currency']); |
|
588 | 588 | |
589 | 589 | // verify details |
590 | - if ( $currency_code != strtolower( wpinv_get_currency() ) ) { |
|
590 | + if ($currency_code != strtolower(wpinv_get_currency())) { |
|
591 | 591 | // the currency code is invalid |
592 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) ); |
|
592 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data))); |
|
593 | 593 | return; |
594 | 594 | } |
595 | 595 | |
@@ -598,11 +598,11 @@ discard block |
||
598 | 598 | 'transaction_id' => $ipn_data['txn_id'] |
599 | 599 | ); |
600 | 600 | |
601 | - $invoice = wpinv_recurring_add_subscription_payment( $parent_invoice_id, $args ); |
|
601 | + $invoice = wpinv_recurring_add_subscription_payment($parent_invoice_id, $args); |
|
602 | 602 | |
603 | - if ( !empty( $invoice ) ) { |
|
603 | + if (!empty($invoice)) { |
|
604 | 604 | sleep(1); |
605 | - wpinv_insert_payment_note( $invoice->ID, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) ); |
|
605 | + wpinv_insert_payment_note($invoice->ID, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id'])); |
|
606 | 606 | |
607 | 607 | $invoice->renew_subscription(); |
608 | 608 | } |
@@ -611,10 +611,10 @@ discard block |
||
611 | 611 | /** |
612 | 612 | * Process the subscription canceled IPN. |
613 | 613 | */ |
614 | -function wpinv_process_paypal_subscr_cancel( $ipn_data ) { |
|
615 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
614 | +function wpinv_process_paypal_subscr_cancel($ipn_data) { |
|
615 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
616 | 616 | |
617 | - if( false === $subscription ) { |
|
617 | + if (false === $subscription) { |
|
618 | 618 | return; |
619 | 619 | } |
620 | 620 | |
@@ -624,10 +624,10 @@ discard block |
||
624 | 624 | /** |
625 | 625 | * Process the subscription expired IPN. |
626 | 626 | */ |
627 | -function wpinv_process_paypal_subscr_eot( $ipn_data ) { |
|
628 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
627 | +function wpinv_process_paypal_subscr_eot($ipn_data) { |
|
628 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
629 | 629 | |
630 | - if( false === $subscription ) { |
|
630 | + if (false === $subscription) { |
|
631 | 631 | return; |
632 | 632 | } |
633 | 633 | |
@@ -637,45 +637,45 @@ discard block |
||
637 | 637 | /** |
638 | 638 | * Process the subscription payment failed IPN. |
639 | 639 | */ |
640 | -function wpinv_process_paypal_subscr_failed( $ipn_data ) { |
|
641 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
640 | +function wpinv_process_paypal_subscr_failed($ipn_data) { |
|
641 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
642 | 642 | |
643 | - if( false === $subscription ) { |
|
643 | + if (false === $subscription) { |
|
644 | 644 | return; |
645 | 645 | } |
646 | 646 | |
647 | 647 | $subscription->failing_subscription(); |
648 | 648 | |
649 | - do_action( 'wpinv_recurring_payment_failed', $subscription ); |
|
649 | + do_action('wpinv_recurring_payment_failed', $subscription); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | /** |
653 | 653 | * Retrieve the subscription this IPN notice is for. |
654 | 654 | */ |
655 | -function wpinv_get_paypal_subscription( $ipn_data = array() ) { |
|
656 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
655 | +function wpinv_get_paypal_subscription($ipn_data = array()) { |
|
656 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
657 | 657 | |
658 | - if( empty( $parent_invoice_id ) ) { |
|
658 | + if (empty($parent_invoice_id)) { |
|
659 | 659 | return false; |
660 | 660 | } |
661 | 661 | |
662 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
663 | - if ( empty( $invoice ) ) { |
|
662 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
663 | + if (empty($invoice)) { |
|
664 | 664 | return false; |
665 | 665 | } |
666 | 666 | |
667 | - $subscription = wpinv_get_subscription( $ipn_data['subscr_id'], true ); |
|
667 | + $subscription = wpinv_get_subscription($ipn_data['subscr_id'], true); |
|
668 | 668 | |
669 | - if ( empty( $subscription ) ) { |
|
670 | - $subs = wpinv_get_subscriptions( array( 'parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1 ) ); |
|
671 | - $subscription = reset( $subs ); |
|
669 | + if (empty($subscription)) { |
|
670 | + $subs = wpinv_get_subscriptions(array('parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1)); |
|
671 | + $subscription = reset($subs); |
|
672 | 672 | |
673 | - if ( $subscription && $subscription->ID > 0 ) { |
|
673 | + if ($subscription && $subscription->ID > 0) { |
|
674 | 674 | // Update the profile ID so it is set for future renewals |
675 | - $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
675 | + $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
676 | 676 | } else { |
677 | 677 | $subscription = $invoice; |
678 | - $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
678 | + $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
679 | 679 | // No subscription found with a matching payment ID, bail |
680 | 680 | //return false; |
681 | 681 | } |
@@ -685,39 +685,39 @@ discard block |
||
685 | 685 | |
686 | 686 | } |
687 | 687 | |
688 | -function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
|
688 | +function wpinv_process_paypal_refund($data, $invoice_id = 0) { |
|
689 | 689 | // Collect payment details |
690 | 690 | |
691 | - if( empty( $invoice_id ) ) { |
|
691 | + if (empty($invoice_id)) { |
|
692 | 692 | return; |
693 | 693 | } |
694 | 694 | |
695 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
695 | + if (get_post_status($invoice_id) == 'wpi-refunded') { |
|
696 | 696 | return; // Only refund payments once |
697 | 697 | } |
698 | 698 | |
699 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
699 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
700 | 700 | $refund_amount = $data['mc_gross'] * -1; |
701 | 701 | |
702 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
703 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) ); |
|
702 | + if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
703 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Partial PayPal refund processed: %s', 'invoicing'), $data['parent_txn_id'])); |
|
704 | 704 | return; // This is a partial refund |
705 | 705 | } |
706 | 706 | |
707 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) ); |
|
708 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) ); |
|
709 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
707 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code'])); |
|
708 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id'])); |
|
709 | + wpinv_update_payment_status($invoice_id, 'wpi-refunded'); |
|
710 | 710 | } |
711 | 711 | |
712 | -function wpinv_get_paypal_redirect( $ssl_check = false ) { |
|
713 | - if ( is_ssl() || ! $ssl_check ) { |
|
712 | +function wpinv_get_paypal_redirect($ssl_check = false) { |
|
713 | + if (is_ssl() || !$ssl_check) { |
|
714 | 714 | $protocol = 'https://'; |
715 | 715 | } else { |
716 | 716 | $protocol = 'http://'; |
717 | 717 | } |
718 | 718 | |
719 | 719 | // Check the current payment mode |
720 | - if ( wpinv_is_test_mode( 'paypal' ) ) { |
|
720 | + if (wpinv_is_test_mode('paypal')) { |
|
721 | 721 | // Test mode |
722 | 722 | $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
723 | 723 | } else { |
@@ -725,67 +725,67 @@ discard block |
||
725 | 725 | $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr'; |
726 | 726 | } |
727 | 727 | |
728 | - return apply_filters( 'wpinv_paypal_uri', $paypal_uri ); |
|
728 | + return apply_filters('wpinv_paypal_uri', $paypal_uri); |
|
729 | 729 | } |
730 | 730 | |
731 | -function wpinv_paypal_success_page_content( $content ) { |
|
731 | +function wpinv_paypal_success_page_content($content) { |
|
732 | 732 | global $wpi_invoice; |
733 | 733 | |
734 | 734 | $session = wpinv_get_checkout_session(); |
735 | 735 | |
736 | - if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] ) ) { |
|
736 | + if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) { |
|
737 | 737 | return $content; |
738 | 738 | } |
739 | 739 | |
740 | - $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] ); |
|
740 | + $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']); |
|
741 | 741 | |
742 | - if ( empty( $invoice_id ) ) { |
|
742 | + if (empty($invoice_id)) { |
|
743 | 743 | return $content; |
744 | 744 | } |
745 | 745 | |
746 | - $wpi_invoice = wpinv_get_invoice( $invoice_id ); |
|
746 | + $wpi_invoice = wpinv_get_invoice($invoice_id); |
|
747 | 747 | |
748 | - if ( !empty( $wpi_invoice ) && 'pending' == $wpi_invoice->status ) { |
|
748 | + if (!empty($wpi_invoice) && 'pending' == $wpi_invoice->status) { |
|
749 | 749 | // Payment is still pending so show processing indicator to fix the Race Condition, issue # |
750 | 750 | ob_start(); |
751 | - wpinv_get_template_part( 'wpinv-payment-processing' ); |
|
751 | + wpinv_get_template_part('wpinv-payment-processing'); |
|
752 | 752 | $content = ob_get_clean(); |
753 | 753 | } |
754 | 754 | |
755 | 755 | return $content; |
756 | 756 | } |
757 | -add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' ); |
|
757 | +add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content'); |
|
758 | 758 | |
759 | -function wpinv_paypal_get_transaction_id( $invoice_id ) { |
|
759 | +function wpinv_paypal_get_transaction_id($invoice_id) { |
|
760 | 760 | $transaction_id = ''; |
761 | - $notes = wpinv_get_invoice_notes( $invoice_id ); |
|
761 | + $notes = wpinv_get_invoice_notes($invoice_id); |
|
762 | 762 | |
763 | - foreach ( $notes as $note ) { |
|
764 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
763 | + foreach ($notes as $note) { |
|
764 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
765 | 765 | $transaction_id = $match[1]; |
766 | 766 | continue; |
767 | 767 | } |
768 | 768 | } |
769 | 769 | |
770 | - return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id ); |
|
770 | + return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id); |
|
771 | 771 | } |
772 | -add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 ); |
|
772 | +add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1); |
|
773 | 773 | |
774 | -function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
775 | - if ( $invoice->is_free_trial() || $transaction_id == $invoice_id ) { // Free trial does not have transaction at PayPal. |
|
774 | +function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
775 | + if ($invoice->is_free_trial() || $transaction_id == $invoice_id) { // Free trial does not have transaction at PayPal. |
|
776 | 776 | $transaction_url = $invoice->get_view_url(); |
777 | 777 | } else { |
778 | - $sandbox = wpinv_is_test_mode( 'paypal' ) ? '.sandbox' : ''; |
|
778 | + $sandbox = wpinv_is_test_mode('paypal') ? '.sandbox' : ''; |
|
779 | 779 | $transaction_url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . $transaction_id; |
780 | 780 | } |
781 | 781 | |
782 | - $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
782 | + $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
783 | 783 | |
784 | - return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice ); |
|
784 | + return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice); |
|
785 | 785 | } |
786 | -add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 ); |
|
786 | +add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3); |
|
787 | 787 | |
788 | 788 | function wpinv_gateway_paypal_button_label($label) { |
789 | - return __( 'Proceed to PayPal', 'invoicing' ); |
|
789 | + return __('Proceed to PayPal', 'invoicing'); |
|
790 | 790 | } |
791 | -add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 ); |
|
792 | 791 | \ No newline at end of file |
792 | +add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1); |
|
793 | 793 | \ No newline at end of file |
@@ -1,19 +1,19 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Exit if accessed directly |
3 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
3 | +if (!defined('ABSPATH')) exit; |
|
4 | 4 | |
5 | -function wpinv_get_item_by( $field = '', $value = '', $type = '' ) { |
|
6 | - if( empty( $field ) || empty( $value ) ) { |
|
5 | +function wpinv_get_item_by($field = '', $value = '', $type = '') { |
|
6 | + if (empty($field) || empty($value)) { |
|
7 | 7 | return false; |
8 | 8 | } |
9 | 9 | |
10 | 10 | $posts = array(); |
11 | 11 | |
12 | - switch( strtolower( $field ) ) { |
|
12 | + switch (strtolower($field)) { |
|
13 | 13 | case 'id': |
14 | - $item = get_post( $value ); |
|
14 | + $item = get_post($value); |
|
15 | 15 | |
16 | - if( get_post_type( $item ) != 'wpi_item' ) { |
|
16 | + if (get_post_type($item) != 'wpi_item') { |
|
17 | 17 | return false; |
18 | 18 | } |
19 | 19 | |
@@ -21,16 +21,16 @@ discard block |
||
21 | 21 | |
22 | 22 | case 'slug': |
23 | 23 | case 'name': |
24 | - $posts = get_posts( array( |
|
24 | + $posts = get_posts(array( |
|
25 | 25 | 'post_type' => 'wpi_item', |
26 | 26 | 'name' => $value, |
27 | 27 | 'posts_per_page' => 1, |
28 | 28 | 'post_status' => 'any' |
29 | - ) ); |
|
29 | + )); |
|
30 | 30 | |
31 | 31 | break; |
32 | 32 | case 'package_id': |
33 | - $posts = get_posts( array( |
|
33 | + $posts = get_posts(array( |
|
34 | 34 | 'post_type' => 'wpi_item', |
35 | 35 | 'posts_per_page' => 1, |
36 | 36 | 'post_status' => 'any', |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | 'value' => 'package', |
47 | 47 | ) |
48 | 48 | ) |
49 | - ) ); |
|
49 | + )); |
|
50 | 50 | |
51 | 51 | break; |
52 | 52 | case 'item_id': |
53 | - if ( empty( $value ) ) { |
|
53 | + if (empty($value)) { |
|
54 | 54 | return false; |
55 | 55 | } |
56 | 56 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | 'key' => '_wpinv_post_id', |
60 | 60 | 'value' => $value, |
61 | 61 | ); |
62 | - if ( !empty( $type ) ) { |
|
62 | + if (!empty($type)) { |
|
63 | 63 | $meta_query[] = array( |
64 | 64 | 'key' => '_wpinv_type', |
65 | 65 | 'value' => $type, |
@@ -72,14 +72,14 @@ discard block |
||
72 | 72 | 'post_status' => 'any', |
73 | 73 | 'orderby' => 'ID', |
74 | 74 | 'order' => 'ASC', |
75 | - 'meta_query' => array( $meta_query ) |
|
75 | + 'meta_query' => array($meta_query) |
|
76 | 76 | ); |
77 | 77 | |
78 | - $posts = get_posts( $args ); |
|
78 | + $posts = get_posts($args); |
|
79 | 79 | |
80 | 80 | break; |
81 | 81 | case 'custom': |
82 | - if ( empty( $value ) || empty( $type ) ) { |
|
82 | + if (empty($value) || empty($type)) { |
|
83 | 83 | return false; |
84 | 84 | } |
85 | 85 | |
@@ -99,10 +99,10 @@ discard block |
||
99 | 99 | 'post_status' => 'any', |
100 | 100 | 'orderby' => 'ID', |
101 | 101 | 'order' => 'ASC', |
102 | - 'meta_query' => array( $meta_query ) |
|
102 | + 'meta_query' => array($meta_query) |
|
103 | 103 | ); |
104 | 104 | |
105 | - $posts = get_posts( $args ); |
|
105 | + $posts = get_posts($args); |
|
106 | 106 | |
107 | 107 | break; |
108 | 108 | |
@@ -110,17 +110,17 @@ discard block |
||
110 | 110 | return false; |
111 | 111 | } |
112 | 112 | |
113 | - if ( !empty( $posts[0] ) ) { |
|
114 | - return new WPInv_Item( $posts[0]->ID ); |
|
113 | + if (!empty($posts[0])) { |
|
114 | + return new WPInv_Item($posts[0]->ID); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | return false; |
118 | 118 | } |
119 | 119 | |
120 | -function wpinv_get_item( $item = 0 ) { |
|
121 | - if ( is_numeric( $item ) ) { |
|
122 | - $item = get_post( $item ); |
|
123 | - if ( ! $item || 'wpi_item' !== $item->post_type ) |
|
120 | +function wpinv_get_item($item = 0) { |
|
121 | + if (is_numeric($item)) { |
|
122 | + $item = get_post($item); |
|
123 | + if (!$item || 'wpi_item' !== $item->post_type) |
|
124 | 124 | return null; |
125 | 125 | return $item; |
126 | 126 | } |
@@ -133,136 +133,136 @@ discard block |
||
133 | 133 | |
134 | 134 | $item = get_posts($args); |
135 | 135 | |
136 | - if ( $item ) { |
|
136 | + if ($item) { |
|
137 | 137 | return $item[0]; |
138 | 138 | } |
139 | 139 | |
140 | 140 | return null; |
141 | 141 | } |
142 | 142 | |
143 | -function wpinv_is_free_item( $item_id = 0 ) { |
|
144 | - if( empty( $item_id ) ) { |
|
143 | +function wpinv_is_free_item($item_id = 0) { |
|
144 | + if (empty($item_id)) { |
|
145 | 145 | return false; |
146 | 146 | } |
147 | 147 | |
148 | - $item = new WPInv_Item( $item_id ); |
|
148 | + $item = new WPInv_Item($item_id); |
|
149 | 149 | |
150 | 150 | return $item->is_free(); |
151 | 151 | } |
152 | 152 | |
153 | -function wpinv_get_item_price( $item_id = 0 ) { |
|
154 | - if( empty( $item_id ) ) { |
|
153 | +function wpinv_get_item_price($item_id = 0) { |
|
154 | + if (empty($item_id)) { |
|
155 | 155 | return false; |
156 | 156 | } |
157 | 157 | |
158 | - $item = new WPInv_Item( $item_id ); |
|
158 | + $item = new WPInv_Item($item_id); |
|
159 | 159 | |
160 | 160 | return $item->get_price(); |
161 | 161 | } |
162 | 162 | |
163 | -function wpinv_is_recurring_item( $item_id = 0 ) { |
|
164 | - if( empty( $item_id ) ) { |
|
163 | +function wpinv_is_recurring_item($item_id = 0) { |
|
164 | + if (empty($item_id)) { |
|
165 | 165 | return false; |
166 | 166 | } |
167 | 167 | |
168 | - $item = new WPInv_Item( $item_id ); |
|
168 | + $item = new WPInv_Item($item_id); |
|
169 | 169 | |
170 | 170 | return $item->is_recurring(); |
171 | 171 | } |
172 | 172 | |
173 | -function wpinv_item_price( $item_id = 0 ) { |
|
174 | - if( empty( $item_id ) ) { |
|
173 | +function wpinv_item_price($item_id = 0) { |
|
174 | + if (empty($item_id)) { |
|
175 | 175 | return false; |
176 | 176 | } |
177 | 177 | |
178 | - $price = wpinv_get_item_price( $item_id ); |
|
179 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
178 | + $price = wpinv_get_item_price($item_id); |
|
179 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
180 | 180 | |
181 | - return apply_filters( 'wpinv_item_price', $price, $item_id ); |
|
181 | + return apply_filters('wpinv_item_price', $price, $item_id); |
|
182 | 182 | } |
183 | 183 | |
184 | -function wpinv_item_show_price( $item_id = 0, $echo = true ) { |
|
185 | - if ( empty( $item_id ) ) { |
|
184 | +function wpinv_item_show_price($item_id = 0, $echo = true) { |
|
185 | + if (empty($item_id)) { |
|
186 | 186 | $item_id = get_the_ID(); |
187 | 187 | } |
188 | 188 | |
189 | - $price = wpinv_item_price( $item_id ); |
|
189 | + $price = wpinv_item_price($item_id); |
|
190 | 190 | |
191 | - $price = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id ); |
|
191 | + $price = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id); |
|
192 | 192 | $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>'; |
193 | - $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price ); |
|
193 | + $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price); |
|
194 | 194 | |
195 | - if ( $echo ) { |
|
195 | + if ($echo) { |
|
196 | 196 | echo $formatted_price; |
197 | 197 | } else { |
198 | 198 | return $formatted_price; |
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
202 | -function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) { |
|
203 | - if ( is_null( $amount_override ) ) { |
|
204 | - $original_price = get_post_meta( $item_id, '_wpinv_price', true ); |
|
202 | +function wpinv_get_item_final_price($item_id = 0, $amount_override = null) { |
|
203 | + if (is_null($amount_override)) { |
|
204 | + $original_price = get_post_meta($item_id, '_wpinv_price', true); |
|
205 | 205 | } else { |
206 | 206 | $original_price = $amount_override; |
207 | 207 | } |
208 | 208 | |
209 | 209 | $price = $original_price; |
210 | 210 | |
211 | - return apply_filters( 'wpinv_get_item_final_price', $price, $item_id ); |
|
211 | + return apply_filters('wpinv_get_item_final_price', $price, $item_id); |
|
212 | 212 | } |
213 | 213 | |
214 | -function wpinv_item_cpt_singular_name( $item_id ) { |
|
215 | - if( empty( $item_id ) ) { |
|
214 | +function wpinv_item_cpt_singular_name($item_id) { |
|
215 | + if (empty($item_id)) { |
|
216 | 216 | return false; |
217 | 217 | } |
218 | 218 | |
219 | - $item = new WPInv_Item( $item_id ); |
|
219 | + $item = new WPInv_Item($item_id); |
|
220 | 220 | |
221 | 221 | return $item->get_cpt_singular_name(); |
222 | 222 | } |
223 | 223 | |
224 | 224 | function wpinv_get_item_types() { |
225 | 225 | $item_types = array( |
226 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
227 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
226 | + 'custom' => __('Standard', 'invoicing'), |
|
227 | + 'fee' => __('Fee', 'invoicing'), |
|
228 | 228 | ); |
229 | - return apply_filters( 'wpinv_get_item_types', $item_types ); |
|
229 | + return apply_filters('wpinv_get_item_types', $item_types); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | function wpinv_item_types() { |
233 | 233 | $item_types = wpinv_get_item_types(); |
234 | 234 | |
235 | - return ( !empty( $item_types ) ? array_keys( $item_types ) : array() ); |
|
235 | + return (!empty($item_types) ? array_keys($item_types) : array()); |
|
236 | 236 | } |
237 | 237 | |
238 | -function wpinv_get_item_type( $item_id ) { |
|
239 | - if( empty( $item_id ) ) { |
|
238 | +function wpinv_get_item_type($item_id) { |
|
239 | + if (empty($item_id)) { |
|
240 | 240 | return false; |
241 | 241 | } |
242 | 242 | |
243 | - $item = new WPInv_Item( $item_id ); |
|
243 | + $item = new WPInv_Item($item_id); |
|
244 | 244 | |
245 | 245 | return $item->get_type(); |
246 | 246 | } |
247 | 247 | |
248 | -function wpinv_item_type( $item_id ) { |
|
248 | +function wpinv_item_type($item_id) { |
|
249 | 249 | $item_types = wpinv_get_item_types(); |
250 | 250 | |
251 | - $item_type = wpinv_get_item_type( $item_id ); |
|
251 | + $item_type = wpinv_get_item_type($item_id); |
|
252 | 252 | |
253 | - if ( empty( $item_type ) ) { |
|
253 | + if (empty($item_type)) { |
|
254 | 254 | $item_type = '-'; |
255 | 255 | } |
256 | 256 | |
257 | - $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' ); |
|
257 | + $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing'); |
|
258 | 258 | |
259 | - return apply_filters( 'wpinv_item_type', $item_type, $item_id ); |
|
259 | + return apply_filters('wpinv_item_type', $item_type, $item_id); |
|
260 | 260 | } |
261 | 261 | |
262 | -function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) { |
|
262 | +function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) { |
|
263 | 263 | global $wpinv_logs; |
264 | 264 | |
265 | - if ( empty( $wpinv_logs ) ) { |
|
265 | + if (empty($wpinv_logs)) { |
|
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | 'log_type' => 'wpi_item' |
272 | 272 | ); |
273 | 273 | |
274 | - $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1; |
|
274 | + $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1; |
|
275 | 275 | |
276 | 276 | $log_meta = array( |
277 | 277 | 'user_info' => $user_info, |
@@ -281,247 +281,247 @@ discard block |
||
281 | 281 | 'invoice_id'=> $invoice_id, |
282 | 282 | ); |
283 | 283 | |
284 | - $wpinv_logs->insert_log( $log_data, $log_meta ); |
|
284 | + $wpinv_logs->insert_log($log_data, $log_meta); |
|
285 | 285 | } |
286 | 286 | |
287 | -function wpinv_remove_item_logs_on_delete( $item_id = 0 ) { |
|
288 | - if ( 'wpi_item' !== get_post_type( $item_id ) ) |
|
287 | +function wpinv_remove_item_logs_on_delete($item_id = 0) { |
|
288 | + if ('wpi_item' !== get_post_type($item_id)) |
|
289 | 289 | return; |
290 | 290 | |
291 | 291 | global $wpinv_logs; |
292 | 292 | |
293 | - if ( empty( $wpinv_logs ) ) { |
|
293 | + if (empty($wpinv_logs)) { |
|
294 | 294 | return false; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Remove all log entries related to this item |
298 | - $wpinv_logs->delete_logs( $item_id ); |
|
298 | + $wpinv_logs->delete_logs($item_id); |
|
299 | 299 | } |
300 | -add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' ); |
|
300 | +add_action('delete_post', 'wpinv_remove_item_logs_on_delete'); |
|
301 | 301 | |
302 | -function wpinv_get_random_item( $post_ids = true ) { |
|
303 | - wpinv_get_random_items( 1, $post_ids ); |
|
302 | +function wpinv_get_random_item($post_ids = true) { |
|
303 | + wpinv_get_random_items(1, $post_ids); |
|
304 | 304 | } |
305 | 305 | |
306 | -function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
|
307 | - if ( $post_ids ) { |
|
308 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' ); |
|
306 | +function wpinv_get_random_items($num = 3, $post_ids = true) { |
|
307 | + if ($post_ids) { |
|
308 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids'); |
|
309 | 309 | } else { |
310 | - $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num ); |
|
310 | + $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num); |
|
311 | 311 | } |
312 | 312 | |
313 | - $args = apply_filters( 'wpinv_get_random_items', $args ); |
|
313 | + $args = apply_filters('wpinv_get_random_items', $args); |
|
314 | 314 | |
315 | - return get_posts( $args ); |
|
315 | + return get_posts($args); |
|
316 | 316 | } |
317 | 317 | |
318 | -function wpinv_get_item_token( $url = '' ) { |
|
318 | +function wpinv_get_item_token($url = '') { |
|
319 | 319 | $args = array(); |
320 | - $hash = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' ); |
|
321 | - $secret = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) ); |
|
320 | + $hash = apply_filters('wpinv_get_url_token_algorithm', 'sha256'); |
|
321 | + $secret = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt())); |
|
322 | 322 | |
323 | - $parts = parse_url( $url ); |
|
323 | + $parts = parse_url($url); |
|
324 | 324 | $options = array(); |
325 | 325 | |
326 | - if ( isset( $parts['query'] ) ) { |
|
327 | - wp_parse_str( $parts['query'], $query_args ); |
|
326 | + if (isset($parts['query'])) { |
|
327 | + wp_parse_str($parts['query'], $query_args); |
|
328 | 328 | |
329 | - if ( ! empty( $query_args['o'] ) ) { |
|
330 | - $options = explode( ':', rawurldecode( $query_args['o'] ) ); |
|
329 | + if (!empty($query_args['o'])) { |
|
330 | + $options = explode(':', rawurldecode($query_args['o'])); |
|
331 | 331 | |
332 | - if ( in_array( 'ip', $options ) ) { |
|
332 | + if (in_array('ip', $options)) { |
|
333 | 333 | $args['ip'] = wpinv_get_ip(); |
334 | 334 | } |
335 | 335 | |
336 | - if ( in_array( 'ua', $options ) ) { |
|
336 | + if (in_array('ua', $options)) { |
|
337 | 337 | $ua = wpinv_get_user_agent(); |
338 | - $args['user_agent'] = rawurlencode( $ua ); |
|
338 | + $args['user_agent'] = rawurlencode($ua); |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
343 | - $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options ); |
|
343 | + $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options); |
|
344 | 344 | |
345 | 345 | $args['secret'] = $secret; |
346 | 346 | $args['token'] = false; |
347 | 347 | |
348 | - $url = add_query_arg( $args, $url ); |
|
349 | - $parts = parse_url( $url ); |
|
348 | + $url = add_query_arg($args, $url); |
|
349 | + $parts = parse_url($url); |
|
350 | 350 | |
351 | - if ( ! isset( $parts['path'] ) ) { |
|
351 | + if (!isset($parts['path'])) { |
|
352 | 352 | $parts['path'] = ''; |
353 | 353 | } |
354 | 354 | |
355 | - $token = md5( $parts['path'] . '?' . $parts['query'] ); |
|
355 | + $token = md5($parts['path'] . '?' . $parts['query']); |
|
356 | 356 | |
357 | 357 | return $token; |
358 | 358 | } |
359 | 359 | |
360 | -function wpinv_validate_url_token( $url = '' ) { |
|
360 | +function wpinv_validate_url_token($url = '') { |
|
361 | 361 | $ret = false; |
362 | - $parts = parse_url( $url ); |
|
362 | + $parts = parse_url($url); |
|
363 | 363 | |
364 | - if ( isset( $parts['query'] ) ) { |
|
365 | - wp_parse_str( $parts['query'], $query_args ); |
|
364 | + if (isset($parts['query'])) { |
|
365 | + wp_parse_str($parts['query'], $query_args); |
|
366 | 366 | |
367 | - $allowed = apply_filters( 'wpinv_url_token_allowed_params', array( |
|
367 | + $allowed = apply_filters('wpinv_url_token_allowed_params', array( |
|
368 | 368 | 'item', |
369 | 369 | 'ttl', |
370 | 370 | 'token' |
371 | - ) ); |
|
371 | + )); |
|
372 | 372 | |
373 | 373 | $remove = array(); |
374 | 374 | |
375 | - foreach( $query_args as $key => $value ) { |
|
376 | - if( false === in_array( $key, $allowed ) ) { |
|
375 | + foreach ($query_args as $key => $value) { |
|
376 | + if (false === in_array($key, $allowed)) { |
|
377 | 377 | $remove[] = $key; |
378 | 378 | } |
379 | 379 | } |
380 | 380 | |
381 | - if( ! empty( $remove ) ) { |
|
382 | - $url = remove_query_arg( $remove, $url ); |
|
381 | + if (!empty($remove)) { |
|
382 | + $url = remove_query_arg($remove, $url); |
|
383 | 383 | } |
384 | 384 | |
385 | - if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) { |
|
386 | - wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) ); |
|
385 | + if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) { |
|
386 | + wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403)); |
|
387 | 387 | } |
388 | 388 | |
389 | - if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) { |
|
389 | + if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) { |
|
390 | 390 | $ret = true; |
391 | 391 | } |
392 | 392 | |
393 | 393 | } |
394 | 394 | |
395 | - return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args ); |
|
395 | + return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args); |
|
396 | 396 | } |
397 | 397 | |
398 | -function wpinv_item_in_cart( $item_id = 0, $options = array() ) { |
|
398 | +function wpinv_item_in_cart($item_id = 0, $options = array()) { |
|
399 | 399 | $cart_items = wpinv_get_cart_contents(); |
400 | 400 | |
401 | 401 | $ret = false; |
402 | 402 | |
403 | - if ( is_array( $cart_items ) ) { |
|
404 | - foreach ( $cart_items as $item ) { |
|
405 | - if ( $item['id'] == $item_id ) { |
|
403 | + if (is_array($cart_items)) { |
|
404 | + foreach ($cart_items as $item) { |
|
405 | + if ($item['id'] == $item_id) { |
|
406 | 406 | $ret = true; |
407 | 407 | break; |
408 | 408 | } |
409 | 409 | } |
410 | 410 | } |
411 | 411 | |
412 | - return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options ); |
|
412 | + return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options); |
|
413 | 413 | } |
414 | 414 | |
415 | -function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) { |
|
415 | +function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) { |
|
416 | 416 | $tax = 0; |
417 | - if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
418 | - $country = !empty( $_POST['country'] ) ? $_POST['country'] : false; |
|
419 | - $state = isset( $_POST['state'] ) ? $_POST['state'] : ''; |
|
417 | + if (!wpinv_item_is_tax_exclusive($item_id)) { |
|
418 | + $country = !empty($_POST['country']) ? $_POST['country'] : false; |
|
419 | + $state = isset($_POST['state']) ? $_POST['state'] : ''; |
|
420 | 420 | |
421 | - $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id ); |
|
421 | + $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id); |
|
422 | 422 | } |
423 | 423 | |
424 | - return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options ); |
|
424 | + return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options); |
|
425 | 425 | } |
426 | 426 | |
427 | -function wpinv_cart_item_price( $item ) { |
|
427 | +function wpinv_cart_item_price($item) { |
|
428 | 428 | $use_taxes = wpinv_use_taxes(); |
429 | - $item_id = isset( $item['id'] ) ? $item['id'] : 0; |
|
430 | - $price = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0; |
|
431 | - $options = isset( $item['options'] ) ? $item['options'] : array(); |
|
432 | - $price_id = isset( $options['price_id'] ) ? $options['price_id'] : false; |
|
433 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
434 | - |
|
435 | - if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) { |
|
436 | - if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) { |
|
429 | + $item_id = isset($item['id']) ? $item['id'] : 0; |
|
430 | + $price = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0; |
|
431 | + $options = isset($item['options']) ? $item['options'] : array(); |
|
432 | + $price_id = isset($options['price_id']) ? $options['price_id'] : false; |
|
433 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
434 | + |
|
435 | + if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) { |
|
436 | + if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) { |
|
437 | 437 | $price += $tax; |
438 | 438 | } |
439 | 439 | |
440 | - if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) { |
|
440 | + if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) { |
|
441 | 441 | $price -= $tax; |
442 | 442 | } |
443 | 443 | } |
444 | 444 | |
445 | - $price = wpinv_price( wpinv_format_amount( $price ) ); |
|
445 | + $price = wpinv_price(wpinv_format_amount($price)); |
|
446 | 446 | |
447 | - return apply_filters( 'wpinv_cart_item_price_label', $price, $item ); |
|
447 | + return apply_filters('wpinv_cart_item_price_label', $price, $item); |
|
448 | 448 | } |
449 | 449 | |
450 | -function wpinv_cart_item_subtotal( $item ) { |
|
451 | - $subtotal = isset( $item['subtotal'] ) ? $item['subtotal'] : 0; |
|
452 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal ) ); |
|
450 | +function wpinv_cart_item_subtotal($item) { |
|
451 | + $subtotal = isset($item['subtotal']) ? $item['subtotal'] : 0; |
|
452 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal)); |
|
453 | 453 | |
454 | - return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item ); |
|
454 | + return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item); |
|
455 | 455 | } |
456 | 456 | |
457 | -function wpinv_cart_item_tax( $item ) { |
|
457 | +function wpinv_cart_item_tax($item) { |
|
458 | 458 | $tax = ''; |
459 | 459 | $tax_rate = ''; |
460 | 460 | |
461 | - if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) { |
|
462 | - $tax = wpinv_price( wpinv_format_amount( $item['tax'] ) ); |
|
463 | - $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100; |
|
464 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate ) : ''; |
|
461 | + if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) { |
|
462 | + $tax = wpinv_price(wpinv_format_amount($item['tax'])); |
|
463 | + $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100; |
|
464 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate) : ''; |
|
465 | 465 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : ''; |
466 | 466 | } |
467 | 467 | |
468 | - $tax = $tax . $tax_rate; |
|
468 | + $tax = $tax . $tax_rate; |
|
469 | 469 | |
470 | - if ( $tax === '' ) { |
|
470 | + if ($tax === '') { |
|
471 | 471 | $tax = 0; // Zero tax |
472 | 472 | } |
473 | 473 | |
474 | - return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item ); |
|
474 | + return apply_filters('wpinv_cart_item_tax_label', $tax, $item); |
|
475 | 475 | } |
476 | 476 | |
477 | -function wpinv_get_cart_item_price( $item_id = 0, $options = array(), $remove_tax_from_inclusive = false ) { |
|
477 | +function wpinv_get_cart_item_price($item_id = 0, $options = array(), $remove_tax_from_inclusive = false) { |
|
478 | 478 | $price = 0; |
479 | - $variable_prices = wpinv_has_variable_prices( $item_id ); |
|
479 | + $variable_prices = wpinv_has_variable_prices($item_id); |
|
480 | 480 | |
481 | - if ( $variable_prices ) { |
|
482 | - $prices = wpinv_get_variable_prices( $item_id ); |
|
481 | + if ($variable_prices) { |
|
482 | + $prices = wpinv_get_variable_prices($item_id); |
|
483 | 483 | |
484 | - if ( $prices ) { |
|
485 | - if( ! empty( $options ) ) { |
|
486 | - $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false; |
|
484 | + if ($prices) { |
|
485 | + if (!empty($options)) { |
|
486 | + $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false; |
|
487 | 487 | } else { |
488 | 488 | $price = false; |
489 | 489 | } |
490 | 490 | } |
491 | 491 | } |
492 | 492 | |
493 | - if( ! $variable_prices || false === $price ) { |
|
493 | + if (!$variable_prices || false === $price) { |
|
494 | 494 | // Get the standard Item price if not using variable prices |
495 | - $price = wpinv_get_item_price( $item_id ); |
|
495 | + $price = wpinv_get_item_price($item_id); |
|
496 | 496 | } |
497 | 497 | |
498 | - if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) { |
|
499 | - $price -= wpinv_get_cart_item_tax( $item_id, $price, $options ); |
|
498 | + if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) { |
|
499 | + $price -= wpinv_get_cart_item_tax($item_id, $price, $options); |
|
500 | 500 | } |
501 | 501 | |
502 | - return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $options ); |
|
502 | + return apply_filters('wpinv_cart_item_price', $price, $item_id, $options); |
|
503 | 503 | } |
504 | 504 | |
505 | -function wpinv_get_cart_item_price_id( $item = array() ) { |
|
506 | - if( isset( $item['item_number'] ) ) { |
|
507 | - $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null; |
|
505 | +function wpinv_get_cart_item_price_id($item = array()) { |
|
506 | + if (isset($item['item_number'])) { |
|
507 | + $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null; |
|
508 | 508 | } else { |
509 | - $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null; |
|
509 | + $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null; |
|
510 | 510 | } |
511 | 511 | return $price_id; |
512 | 512 | } |
513 | 513 | |
514 | -function wpinv_get_cart_item_price_name( $item = array() ) { |
|
515 | - $price_id = (int)wpinv_get_cart_item_price_id( $item ); |
|
516 | - $prices = wpinv_get_variable_prices( $item['id'] ); |
|
517 | - $name = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : ''; |
|
518 | - return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item ); |
|
514 | +function wpinv_get_cart_item_price_name($item = array()) { |
|
515 | + $price_id = (int)wpinv_get_cart_item_price_id($item); |
|
516 | + $prices = wpinv_get_variable_prices($item['id']); |
|
517 | + $name = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : ''; |
|
518 | + return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item); |
|
519 | 519 | } |
520 | 520 | |
521 | -function wpinv_get_cart_item_name( $item = array() ) { |
|
522 | - $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] ); |
|
521 | +function wpinv_get_cart_item_name($item = array()) { |
|
522 | + $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']); |
|
523 | 523 | |
524 | - if ( empty( $item_title ) ) { |
|
524 | + if (empty($item_title)) { |
|
525 | 525 | $item_title = $item['id']; |
526 | 526 | } |
527 | 527 | |
@@ -531,23 +531,23 @@ discard block |
||
531 | 531 | } |
532 | 532 | */ |
533 | 533 | |
534 | - return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item ); |
|
534 | + return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item); |
|
535 | 535 | } |
536 | 536 | |
537 | -function wpinv_has_variable_prices( $item_id = 0 ) { |
|
537 | +function wpinv_has_variable_prices($item_id = 0) { |
|
538 | 538 | return false; |
539 | 539 | } |
540 | 540 | |
541 | -function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) { |
|
541 | +function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) { |
|
542 | 542 | $cart_items = wpinv_get_cart_contents(); |
543 | 543 | |
544 | - if ( !is_array( $cart_items ) ) { |
|
544 | + if (!is_array($cart_items)) { |
|
545 | 545 | return false; // Empty cart |
546 | 546 | } else { |
547 | - foreach ( $cart_items as $position => $item ) { |
|
548 | - if ( $item['id'] == $item_id ) { |
|
549 | - if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) { |
|
550 | - if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) { |
|
547 | + foreach ($cart_items as $position => $item) { |
|
548 | + if ($item['id'] == $item_id) { |
|
549 | + if (isset($options['price_id']) && isset($item['options']['price_id'])) { |
|
550 | + if ((int)$options['price_id'] == (int)$item['options']['price_id']) { |
|
551 | 551 | return $position; |
552 | 552 | } |
553 | 553 | } else { |
@@ -560,80 +560,80 @@ discard block |
||
560 | 560 | return false; // Not found |
561 | 561 | } |
562 | 562 | |
563 | -function wpinv_get_cart_item_quantity( $item ) { |
|
564 | - if ( wpinv_item_quantities_enabled() ) { |
|
565 | - $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
563 | +function wpinv_get_cart_item_quantity($item) { |
|
564 | + if (wpinv_item_quantities_enabled()) { |
|
565 | + $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
566 | 566 | } else { |
567 | 567 | $quantity = 1; |
568 | 568 | } |
569 | 569 | |
570 | - if ( $quantity < 1 ) { |
|
570 | + if ($quantity < 1) { |
|
571 | 571 | $quantity = 1; |
572 | 572 | } |
573 | 573 | |
574 | - return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item ); |
|
574 | + return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item); |
|
575 | 575 | } |
576 | 576 | |
577 | -function wpinv_get_item_suffix( $item, $html = true ) { |
|
578 | - if ( empty( $item ) ) { |
|
577 | +function wpinv_get_item_suffix($item, $html = true) { |
|
578 | + if (empty($item)) { |
|
579 | 579 | return NULL; |
580 | 580 | } |
581 | 581 | |
582 | - if ( is_int( $item ) ) { |
|
583 | - $item = new WPInv_Item( $item ); |
|
582 | + if (is_int($item)) { |
|
583 | + $item = new WPInv_Item($item); |
|
584 | 584 | } |
585 | 585 | |
586 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
586 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
587 | 587 | return NULL; |
588 | 588 | } |
589 | 589 | |
590 | - $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : ''; |
|
590 | + $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''; |
|
591 | 591 | |
592 | - if ( !$html && $suffix ) { |
|
593 | - $suffix = strip_tags( $suffix ); |
|
592 | + if (!$html && $suffix) { |
|
593 | + $suffix = strip_tags($suffix); |
|
594 | 594 | } |
595 | 595 | |
596 | - return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html ); |
|
596 | + return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html); |
|
597 | 597 | } |
598 | 598 | |
599 | -function wpinv_remove_item( $item = 0, $force_delete = false ) { |
|
600 | - if ( empty( $item ) ) { |
|
599 | +function wpinv_remove_item($item = 0, $force_delete = false) { |
|
600 | + if (empty($item)) { |
|
601 | 601 | return NULL; |
602 | 602 | } |
603 | 603 | |
604 | - if ( is_int( $item ) ) { |
|
605 | - $item = new WPInv_Item( $item ); |
|
604 | + if (is_int($item)) { |
|
605 | + $item = new WPInv_Item($item); |
|
606 | 606 | } |
607 | 607 | |
608 | - if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) { |
|
608 | + if (!(is_object($item) && is_a($item, 'WPInv_Item'))) { |
|
609 | 609 | return NULL; |
610 | 610 | } |
611 | 611 | |
612 | - do_action( 'wpinv_pre_delete_item', $item ); |
|
612 | + do_action('wpinv_pre_delete_item', $item); |
|
613 | 613 | |
614 | - wp_delete_post( $item->ID, $force_delete ); |
|
614 | + wp_delete_post($item->ID, $force_delete); |
|
615 | 615 | |
616 | - do_action( 'wpinv_post_delete_item', $item ); |
|
616 | + do_action('wpinv_post_delete_item', $item); |
|
617 | 617 | } |
618 | 618 | |
619 | -function wpinv_can_delete_item( $post_id ) { |
|
620 | - $return = current_user_can( 'manage_options' ) ? true : false; |
|
619 | +function wpinv_can_delete_item($post_id) { |
|
620 | + $return = current_user_can('manage_options') ? true : false; |
|
621 | 621 | |
622 | - if ( $return && wpinv_item_in_use( $post_id ) ) { |
|
622 | + if ($return && wpinv_item_in_use($post_id)) { |
|
623 | 623 | $return = false; // Don't delete item already use in invoices. |
624 | 624 | } |
625 | 625 | |
626 | - return apply_filters( 'wpinv_can_delete_item', $return, $post_id ); |
|
626 | + return apply_filters('wpinv_can_delete_item', $return, $post_id); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | function wpinv_admin_action_delete() { |
630 | 630 | $screen = get_current_screen(); |
631 | 631 | |
632 | - if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) { |
|
632 | + if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) { |
|
633 | 633 | $post_ids = array(); |
634 | 634 | |
635 | - foreach ( $_REQUEST['post'] as $post_id ) { |
|
636 | - if ( !wpinv_can_delete_item( $post_id ) ) { |
|
635 | + foreach ($_REQUEST['post'] as $post_id) { |
|
636 | + if (!wpinv_can_delete_item($post_id)) { |
|
637 | 637 | continue; |
638 | 638 | } |
639 | 639 | |
@@ -643,83 +643,83 @@ discard block |
||
643 | 643 | $_REQUEST['post'] = $post_ids; |
644 | 644 | } |
645 | 645 | } |
646 | -add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 ); |
|
647 | -add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 ); |
|
646 | +add_action('admin_action_trash', 'wpinv_admin_action_delete', -10); |
|
647 | +add_action('admin_action_delete', 'wpinv_admin_action_delete', -10); |
|
648 | 648 | |
649 | -function wpinv_check_delete_item( $check, $post, $force_delete ) { |
|
650 | - if ( $post->post_type == 'wpi_item' ) { |
|
651 | - if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) { |
|
649 | +function wpinv_check_delete_item($check, $post, $force_delete) { |
|
650 | + if ($post->post_type == 'wpi_item') { |
|
651 | + if ($force_delete && !wpinv_can_delete_item($post->ID)) { |
|
652 | 652 | return true; |
653 | 653 | } |
654 | 654 | } |
655 | 655 | |
656 | 656 | return $check; |
657 | 657 | } |
658 | -add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 ); |
|
658 | +add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3); |
|
659 | 659 | |
660 | -function wpinv_item_in_use( $item_id ) { |
|
660 | +function wpinv_item_in_use($item_id) { |
|
661 | 661 | global $wpdb, $wpi_items_in_use; |
662 | 662 | |
663 | - if ( !$item_id > 0 ) { |
|
663 | + if (!$item_id > 0) { |
|
664 | 664 | return false; |
665 | 665 | } |
666 | 666 | |
667 | - if ( !empty( $wpi_items_in_use ) ) { |
|
668 | - if ( isset( $wpi_items_in_use[$item_id] ) ) { |
|
667 | + if (!empty($wpi_items_in_use)) { |
|
668 | + if (isset($wpi_items_in_use[$item_id])) { |
|
669 | 669 | return $wpi_items_in_use[$item_id]; |
670 | 670 | } |
671 | 671 | } else { |
672 | 672 | $wpi_items_in_use = array(); |
673 | 673 | } |
674 | 674 | |
675 | - $statuses = array_keys( wpinv_get_invoice_statuses( true ) ); |
|
675 | + $statuses = array_keys(wpinv_get_invoice_statuses(true)); |
|
676 | 676 | |
677 | - $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
678 | - $in_use = $wpdb->get_var( $query ) > 0 ? true : false; |
|
677 | + $query = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )"; |
|
678 | + $in_use = $wpdb->get_var($query) > 0 ? true : false; |
|
679 | 679 | |
680 | 680 | $wpi_items_in_use[$item_id] = $in_use; |
681 | 681 | |
682 | 682 | return $in_use; |
683 | 683 | } |
684 | 684 | |
685 | -function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) { |
|
685 | +function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) { |
|
686 | 686 | // Set some defaults |
687 | 687 | $defaults = array( |
688 | - 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
689 | - 'item_id' => 0, // Required. Any integer number. Must be unique within item type. |
|
690 | - 'title' => '', // Required. Item title. |
|
691 | - 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
692 | - 'status' => 'pending', // Optional. pending, publish |
|
693 | - 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
694 | - 'cpt_singular_name' => '', // Optional. Sub title for item. Should be singular. |
|
695 | - 'cpt_name' => '', // Optional. Sub title for item. Should be plural. |
|
696 | - 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
697 | - 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
698 | - 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
699 | - 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
700 | - 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
701 | - 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
702 | - 'trial_interval' => 0, // Optional. Any integer number. |
|
703 | - 'excerpt' => '', // Optional. Item short description |
|
688 | + 'type' => 'custom', // Optional. Item type. Default 'custom'. |
|
689 | + 'item_id' => 0, // Required. Any integer number. Must be unique within item type. |
|
690 | + 'title' => '', // Required. Item title. |
|
691 | + 'price' => '0.00', // Optional. Item price. Default '0.00'. |
|
692 | + 'status' => 'pending', // Optional. pending, publish |
|
693 | + 'vat_rule' => 'digital', // Optional. digital => Digital item, physical => Physical item |
|
694 | + 'cpt_singular_name' => '', // Optional. Sub title for item. Should be singular. |
|
695 | + 'cpt_name' => '', // Optional. Sub title for item. Should be plural. |
|
696 | + 'is_recurring' => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring |
|
697 | + 'recurring_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
698 | + 'recurring_interval' => 0, // Optional. Integer value between 1 - 90. |
|
699 | + 'recurring_limit' => 0, // Optional. Any integer number. 0 for recurring forever until cancelled. |
|
700 | + 'free_trial' => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial |
|
701 | + 'trial_period' => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly |
|
702 | + 'trial_interval' => 0, // Optional. Any integer number. |
|
703 | + 'excerpt' => '', // Optional. Item short description |
|
704 | 704 | ); |
705 | 705 | |
706 | - $data = wp_parse_args( $args, $defaults ); |
|
706 | + $data = wp_parse_args($args, $defaults); |
|
707 | 707 | |
708 | - if ( empty( $data['item_id'] ) ) { |
|
709 | - if ( $wp_error ) { |
|
710 | - return new WP_Error( 'invalid_item_id', __( 'Invalid item ID.' ) ); |
|
708 | + if (empty($data['item_id'])) { |
|
709 | + if ($wp_error) { |
|
710 | + return new WP_Error('invalid_item_id', __('Invalid item ID.')); |
|
711 | 711 | } else { |
712 | 712 | return false; |
713 | 713 | } |
714 | 714 | } |
715 | 715 | |
716 | - if ( empty( $data['type'] ) ) { |
|
716 | + if (empty($data['type'])) { |
|
717 | 717 | $data['type'] = 'custom'; |
718 | 718 | } |
719 | 719 | |
720 | - $item = wpinv_get_item_by( 'item_id', $data['item_id'], $data['type'] ); |
|
720 | + $item = wpinv_get_item_by('item_id', $data['item_id'], $data['type']); |
|
721 | 721 | |
722 | - if ( !$force_update && !empty( $item ) ) { |
|
722 | + if (!$force_update && !empty($item)) { |
|
723 | 723 | return $item; |
724 | 724 | } |
725 | 725 | |
@@ -728,18 +728,18 @@ discard block |
||
728 | 728 | $meta['post_id'] = $data['item_id']; |
729 | 729 | $meta['cpt_singular_name'] = $data['cpt_singular_name']; |
730 | 730 | $meta['cpt_name'] = $data['cpt_name']; |
731 | - $meta['price'] = wpinv_round_amount( $data['price'] ); |
|
731 | + $meta['price'] = wpinv_round_amount($data['price']); |
|
732 | 732 | $meta['vat_rule'] = $data['vat_rule']; |
733 | 733 | $meta['vat_class'] = '_standard'; |
734 | 734 | |
735 | - if ( !empty( $data['is_recurring'] ) ) { |
|
735 | + if (!empty($data['is_recurring'])) { |
|
736 | 736 | $meta['is_recurring'] = $data['is_recurring']; |
737 | 737 | $meta['recurring_period'] = $data['recurring_period']; |
738 | - $meta['recurring_interval'] = absint( $data['recurring_interval'] ); |
|
739 | - $meta['recurring_limit'] = absint( $data['recurring_limit'] ); |
|
738 | + $meta['recurring_interval'] = absint($data['recurring_interval']); |
|
739 | + $meta['recurring_limit'] = absint($data['recurring_limit']); |
|
740 | 740 | $meta['free_trial'] = $data['free_trial']; |
741 | 741 | $meta['trial_period'] = $data['trial_period']; |
742 | - $meta['trial_interval'] = absint( $data['trial_interval'] ); |
|
742 | + $meta['trial_interval'] = absint($data['trial_interval']); |
|
743 | 743 | } else { |
744 | 744 | $meta['is_recurring'] = 0; |
745 | 745 | $meta['recurring_period'] = ''; |
@@ -750,18 +750,18 @@ discard block |
||
750 | 750 | $meta['trial_interval'] = ''; |
751 | 751 | } |
752 | 752 | |
753 | - $post_data = array( |
|
753 | + $post_data = array( |
|
754 | 754 | 'post_title' => $data['title'], |
755 | 755 | 'post_excerpt' => $data['excerpt'], |
756 | 756 | 'post_status' => $data['status'], |
757 | 757 | 'meta' => $meta |
758 | 758 | ); |
759 | 759 | |
760 | - if ( !empty( $item ) ) { |
|
761 | - $item->update( $post_data, $wp_error ); |
|
760 | + if (!empty($item)) { |
|
761 | + $item->update($post_data, $wp_error); |
|
762 | 762 | } else { |
763 | 763 | $item = new WPInv_Item(); |
764 | - $item->create( $post_data, $wp_error ); |
|
764 | + $item->create($post_data, $wp_error); |
|
765 | 765 | } |
766 | 766 | |
767 | 767 | return $item; |
@@ -7,22 +7,22 @@ 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_API { |
15 | 15 | protected $post_type = 'wpi_invoice'; |
16 | 16 | |
17 | - public function __construct( $params = array() ) { |
|
17 | + public function __construct($params = array()) { |
|
18 | 18 | } |
19 | - public function insert_invoice( $data ) { |
|
19 | + public function insert_invoice($data) { |
|
20 | 20 | global $wpdb; |
21 | 21 | //wpinv_transaction_query( 'start' ); |
22 | 22 | |
23 | 23 | try { |
24 | - if ( ! isset( $data['invoice'] ) ) { |
|
25 | - throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 ); |
|
24 | + if (!isset($data['invoice'])) { |
|
25 | + throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | $data = $data['invoice']; |
@@ -32,37 +32,37 @@ discard block |
||
32 | 32 | //throw new WPInv_API_Exception( 'wpinv_api_user_cannot_create_invoice', __( 'You do not have permission to create invoices', 'invoicing' ), 401 ); |
33 | 33 | //} |
34 | 34 | |
35 | - $data = apply_filters( 'wpinv_api_create_invoice_data', $data, $this ); |
|
35 | + $data = apply_filters('wpinv_api_create_invoice_data', $data, $this); |
|
36 | 36 | |
37 | - $invoice = wpinv_insert_invoice( $data ); |
|
38 | - if ( is_wp_error( $invoice ) ) { |
|
39 | - throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 ); |
|
37 | + $invoice = wpinv_insert_invoice($data); |
|
38 | + if (is_wp_error($invoice)) { |
|
39 | + throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | // HTTP 201 Created |
43 | - $this->send_status( 201 ); |
|
43 | + $this->send_status(201); |
|
44 | 44 | |
45 | - do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this ); |
|
45 | + do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this); |
|
46 | 46 | |
47 | 47 | //wpinv_transaction_query( 'commit' ); |
48 | 48 | |
49 | - return wpinv_get_invoice( $invoice->ID ); |
|
49 | + return wpinv_get_invoice($invoice->ID); |
|
50 | 50 | |
51 | - } catch ( WPInv_API_Exception $e ) { |
|
51 | + } catch (WPInv_API_Exception $e) { |
|
52 | 52 | |
53 | 53 | //wpinv_transaction_query( 'rollback' ); |
54 | 54 | |
55 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
55 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | - public function create_invoice( $data ) { |
|
59 | + public function create_invoice($data) { |
|
60 | 60 | global $wpdb; |
61 | 61 | //wpinv_transaction_query( 'start' ); |
62 | 62 | |
63 | 63 | try { |
64 | - if ( ! isset( $data['invoice'] ) ) { |
|
65 | - throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 ); |
|
64 | + if (!isset($data['invoice'])) { |
|
65 | + throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | $data = $data['invoice']; |
@@ -72,111 +72,111 @@ discard block |
||
72 | 72 | //throw new WPInv_API_Exception( 'wpinv_api_user_cannot_create_invoice', __( 'You do not have permission to create invoices', 'invoicing' ), 401 ); |
73 | 73 | //} |
74 | 74 | |
75 | - $data = apply_filters( 'wpinv_api_create_invoice_data', $data, $this ); |
|
75 | + $data = apply_filters('wpinv_api_create_invoice_data', $data, $this); |
|
76 | 76 | |
77 | 77 | // default invoice args, note that status is checked for validity in wpinv_create_invoice() |
78 | 78 | $default_invoice_args = array( |
79 | - 'status' => isset( $data['status'] ) ? $data['status'] : '', |
|
80 | - 'user_note' => isset( $data['note'] ) ? $data['note'] : null, |
|
81 | - 'invoice_id' => isset( $data['invoice_id'] ) ? (int)$data['invoice_id'] : 0, |
|
79 | + 'status' => isset($data['status']) ? $data['status'] : '', |
|
80 | + 'user_note' => isset($data['note']) ? $data['note'] : null, |
|
81 | + 'invoice_id' => isset($data['invoice_id']) ? (int)$data['invoice_id'] : 0, |
|
82 | 82 | ); |
83 | 83 | |
84 | 84 | // if creating invoice for existing user |
85 | - if ( ! empty( $data['user_id'] ) ) { |
|
85 | + if (!empty($data['user_id'])) { |
|
86 | 86 | // make sure user exists |
87 | - if ( false === get_user_by( 'id', $data['user_id'] ) ) { |
|
88 | - throw new WPInv_API_Exception( 'wpinv_api_invalid_user_id', __( 'User ID is invalid', 'invoicing' ), 400 ); |
|
87 | + if (false === get_user_by('id', $data['user_id'])) { |
|
88 | + throw new WPInv_API_Exception('wpinv_api_invalid_user_id', __('User ID is invalid', 'invoicing'), 400); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | $default_invoice_args['user_id'] = $data['user_id']; |
92 | 92 | } |
93 | 93 | |
94 | 94 | // create the pending invoice |
95 | - $invoice = $this->create_base_invoice( $default_invoice_args, $data ); |
|
95 | + $invoice = $this->create_base_invoice($default_invoice_args, $data); |
|
96 | 96 | |
97 | - if ( is_wp_error( $invoice ) ) { |
|
98 | - throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 ); |
|
97 | + if (is_wp_error($invoice)) { |
|
98 | + throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | // Add note |
102 | - if ( !empty( $data['user_note'] ) ) { |
|
103 | - $invoice->add_note( $data['user_note'], true ); |
|
102 | + if (!empty($data['user_note'])) { |
|
103 | + $invoice->add_note($data['user_note'], true); |
|
104 | 104 | } |
105 | 105 | |
106 | - if ( !empty( $data['private_note'] ) ) { |
|
107 | - $invoice->add_note( $data['private_note'] ); |
|
106 | + if (!empty($data['private_note'])) { |
|
107 | + $invoice->add_note($data['private_note']); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | // billing address |
111 | - $invoice = $this->set_billing_details( $invoice, $data ); |
|
111 | + $invoice = $this->set_billing_details($invoice, $data); |
|
112 | 112 | |
113 | 113 | // items |
114 | - $invoice = $this->set_discount( $invoice, $data ); |
|
114 | + $invoice = $this->set_discount($invoice, $data); |
|
115 | 115 | |
116 | 116 | // items |
117 | - $invoice = $this->set_items( $invoice, $data ); |
|
117 | + $invoice = $this->set_items($invoice, $data); |
|
118 | 118 | |
119 | 119 | // payment method (and payment_complete() if `paid` == true) |
120 | - if ( isset( $data['payment_details'] ) && is_array( $data['payment_details'] ) ) { |
|
120 | + if (isset($data['payment_details']) && is_array($data['payment_details'])) { |
|
121 | 121 | // method ID & title are required |
122 | - if ( empty( $data['payment_details']['method_id'] ) || empty( $data['payment_details']['method_title'] ) ) { |
|
123 | - throw new WPInv_API_Exception( 'wpinv_invalid_payment_details', __( 'Payment method ID and title are required', 'invoicing' ), 400 ); |
|
122 | + if (empty($data['payment_details']['method_id']) || empty($data['payment_details']['method_title'])) { |
|
123 | + throw new WPInv_API_Exception('wpinv_invalid_payment_details', __('Payment method ID and title are required', 'invoicing'), 400); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | // set invoice currency |
127 | - if ( isset( $data['payment_details']['currency'] ) ) { |
|
128 | - if ( ! array_key_exists( $data['payment_details']['currency'], wpinv_get_currencies() ) ) { |
|
129 | - throw new WPInv_API_Exception( 'wpinv_invalid_invoice_currency', __( 'Provided invoice currency is invalid', 'invoicing' ), 400 ); |
|
127 | + if (isset($data['payment_details']['currency'])) { |
|
128 | + if (!array_key_exists($data['payment_details']['currency'], wpinv_get_currencies())) { |
|
129 | + throw new WPInv_API_Exception('wpinv_invalid_invoice_currency', __('Provided invoice currency is invalid', 'invoicing'), 400); |
|
130 | 130 | } |
131 | 131 | |
132 | - update_post_meta( $invoice->ID, '_wpinv_currency', $data['payment_details']['currency'] ); |
|
132 | + update_post_meta($invoice->ID, '_wpinv_currency', $data['payment_details']['currency']); |
|
133 | 133 | |
134 | 134 | $invoice->currency = $data['payment_details']['currency']; |
135 | 135 | } |
136 | 136 | |
137 | - update_post_meta( $invoice->ID, '_wpinv_gateway', $data['payment_details']['method_id'] ); |
|
138 | - update_post_meta( $invoice->ID, '_wpinv_gateway_title', $data['payment_details']['method_title'] ); |
|
137 | + update_post_meta($invoice->ID, '_wpinv_gateway', $data['payment_details']['method_id']); |
|
138 | + update_post_meta($invoice->ID, '_wpinv_gateway_title', $data['payment_details']['method_title']); |
|
139 | 139 | |
140 | 140 | $invoice->gateway = $data['payment_details']['method_id']; |
141 | 141 | $invoice->gateway_title = $data['payment_details']['method_title']; |
142 | 142 | |
143 | 143 | // mark as paid if set |
144 | - if ( isset( $data['payment_details']['paid'] ) && true === $data['payment_details']['paid'] ) { |
|
144 | + if (isset($data['payment_details']['paid']) && true === $data['payment_details']['paid']) { |
|
145 | 145 | //$invoice->payment_complete( isset( $data['payment_details']['transaction_id'] ) ? $data['payment_details']['transaction_id'] : $invoice->ID ); |
146 | 146 | } |
147 | 147 | } |
148 | 148 | |
149 | 149 | // set invoice meta |
150 | - if ( isset( $data['invoice_meta'] ) && is_array( $data['invoice_meta'] ) ) { |
|
151 | - $this->set_invoice_meta( $invoice->ID, $data['invoice_meta'] ); |
|
150 | + if (isset($data['invoice_meta']) && is_array($data['invoice_meta'])) { |
|
151 | + $this->set_invoice_meta($invoice->ID, $data['invoice_meta']); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // HTTP 201 Created |
155 | - $this->send_status( 201 ); |
|
155 | + $this->send_status(201); |
|
156 | 156 | |
157 | - do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this ); |
|
157 | + do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this); |
|
158 | 158 | |
159 | 159 | //wpinv_transaction_query( 'commit' ); |
160 | 160 | |
161 | - return wpinv_get_invoice( $invoice->ID ); |
|
161 | + return wpinv_get_invoice($invoice->ID); |
|
162 | 162 | |
163 | - } catch ( WPInv_API_Exception $e ) { |
|
163 | + } catch (WPInv_API_Exception $e) { |
|
164 | 164 | |
165 | 165 | //wpinv_transaction_query( 'rollback' ); |
166 | 166 | |
167 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
167 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
168 | 168 | } |
169 | 169 | } |
170 | 170 | |
171 | - public function send_status( $code ) { |
|
172 | - status_header( $code ); |
|
171 | + public function send_status($code) { |
|
172 | + status_header($code); |
|
173 | 173 | } |
174 | 174 | |
175 | - protected function create_base_invoice( $args, $data ) { |
|
176 | - return wpinv_create_invoice( $args, $data ); |
|
175 | + protected function create_base_invoice($args, $data) { |
|
176 | + return wpinv_create_invoice($args, $data); |
|
177 | 177 | } |
178 | 178 | |
179 | - protected function set_billing_details( $invoice, $data ) { |
|
179 | + protected function set_billing_details($invoice, $data) { |
|
180 | 180 | $address_fields = array( |
181 | 181 | 'user_id', |
182 | 182 | 'first_name', |
@@ -195,66 +195,66 @@ discard block |
||
195 | 195 | $billing_details = array(); |
196 | 196 | $user_id = $invoice->get_user_id(); |
197 | 197 | |
198 | - foreach ( $address_fields as $field ) { |
|
199 | - if ( isset( $data['billing_details'][ $field ] ) ) { |
|
200 | - $value = sanitize_text_field( $data['billing_details'][ $field ] ); |
|
198 | + foreach ($address_fields as $field) { |
|
199 | + if (isset($data['billing_details'][$field])) { |
|
200 | + $value = sanitize_text_field($data['billing_details'][$field]); |
|
201 | 201 | |
202 | - if ( $field == 'country' && empty( $value ) ) { |
|
203 | - if ( !empty( $invoice->country ) ) { |
|
202 | + if ($field == 'country' && empty($value)) { |
|
203 | + if (!empty($invoice->country)) { |
|
204 | 204 | $value = $invoice->country; |
205 | 205 | } else { |
206 | - $value = wpinv_default_billing_country( '', $user_id ); |
|
206 | + $value = wpinv_default_billing_country('', $user_id); |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | |
210 | - if ( $field == 'state' && empty( $value ) ) { |
|
211 | - if ( !empty( $invoice->state ) ) { |
|
210 | + if ($field == 'state' && empty($value)) { |
|
211 | + if (!empty($invoice->state)) { |
|
212 | 212 | $value = $invoice->state; |
213 | 213 | } else { |
214 | 214 | $value = wpinv_get_default_state(); |
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | - $invoice->set( $field, $value ); |
|
218 | + $invoice->set($field, $value); |
|
219 | 219 | |
220 | - update_post_meta( $invoice->ID, '_wpinv_' . $field, $value ); |
|
220 | + update_post_meta($invoice->ID, '_wpinv_' . $field, $value); |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
224 | 224 | return $invoice; |
225 | 225 | } |
226 | 226 | |
227 | - protected function set_discount( $invoice, $data ) { |
|
228 | - if ( isset( $data['discount'] ) ) { |
|
229 | - $invoice->set( 'discount', wpinv_round_amount( $data['discount'] ) ); |
|
227 | + protected function set_discount($invoice, $data) { |
|
228 | + if (isset($data['discount'])) { |
|
229 | + $invoice->set('discount', wpinv_round_amount($data['discount'])); |
|
230 | 230 | |
231 | - update_post_meta( $invoice->ID, '_wpinv_discount', wpinv_round_amount( $data['discount'] ) ); |
|
231 | + update_post_meta($invoice->ID, '_wpinv_discount', wpinv_round_amount($data['discount'])); |
|
232 | 232 | |
233 | - if ( isset( $data['discount_code'] ) ) { |
|
234 | - $invoice->set( 'discount_code', $data['discount_code'] ); |
|
233 | + if (isset($data['discount_code'])) { |
|
234 | + $invoice->set('discount_code', $data['discount_code']); |
|
235 | 235 | |
236 | - update_post_meta( $invoice->ID, '_wpinv_discount_code', $data['discount_code'] ); |
|
236 | + update_post_meta($invoice->ID, '_wpinv_discount_code', $data['discount_code']); |
|
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | 240 | return $invoice; |
241 | 241 | } |
242 | 242 | |
243 | - protected function set_items( $invoice, $data ) { |
|
244 | - if ( !empty( $data['items'] ) && is_array( $data['items'] ) ) { |
|
243 | + protected function set_items($invoice, $data) { |
|
244 | + if (!empty($data['items']) && is_array($data['items'])) { |
|
245 | 245 | $items_array = array(); |
246 | 246 | |
247 | - if ( !empty( $invoice->country ) ) { |
|
247 | + if (!empty($invoice->country)) { |
|
248 | 248 | $country = $invoice->country; |
249 | - } else if ( !empty( $data['billing_details']['country'] ) ) { |
|
249 | + } else if (!empty($data['billing_details']['country'])) { |
|
250 | 250 | $country = $data['billing_details']['country']; |
251 | 251 | } else { |
252 | - $country = wpinv_default_billing_country( '', $invoice->get_user_id() ); |
|
252 | + $country = wpinv_default_billing_country('', $invoice->get_user_id()); |
|
253 | 253 | } |
254 | 254 | |
255 | - if ( !empty( $invoice->state ) ) { |
|
255 | + if (!empty($invoice->state)) { |
|
256 | 256 | $state = $invoice->state; |
257 | - } else if ( !empty( $data['billing_details']['state'] ) ) { |
|
257 | + } else if (!empty($data['billing_details']['state'])) { |
|
258 | 258 | $state = $data['billing_details']['state']; |
259 | 259 | } else { |
260 | 260 | $state = wpinv_get_default_state(); |
@@ -263,54 +263,54 @@ discard block |
||
263 | 263 | $_POST['country'] = $country; |
264 | 264 | $_POST['state'] = $state; |
265 | 265 | |
266 | - $rate = wpinv_get_tax_rate( $country, $state, 'global' ); |
|
266 | + $rate = wpinv_get_tax_rate($country, $state, 'global'); |
|
267 | 267 | |
268 | 268 | $total_tax = 0; |
269 | - foreach ( $data['items'] as $item ) { |
|
270 | - $id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
271 | - $title = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : ''; |
|
272 | - $desc = isset( $item['description'] ) ? sanitize_text_field( $item['description'] ) : ''; |
|
273 | - $amount = isset( $item['amount'] ) ? wpinv_round_amount( $item['amount'] ) : 0; |
|
269 | + foreach ($data['items'] as $item) { |
|
270 | + $id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
271 | + $title = isset($item['title']) ? sanitize_text_field($item['title']) : ''; |
|
272 | + $desc = isset($item['description']) ? sanitize_text_field($item['description']) : ''; |
|
273 | + $amount = isset($item['amount']) ? wpinv_round_amount($item['amount']) : 0; |
|
274 | 274 | |
275 | - if ( !empty( $item['vat_rates_class'] ) ) { |
|
275 | + if (!empty($item['vat_rates_class'])) { |
|
276 | 276 | $vat_rates_class = $item['vat_rates_class']; |
277 | 277 | } else { |
278 | 278 | $vat_rates_class = '_standard'; |
279 | 279 | } |
280 | - $vat_rate = wpinv_get_tax_rate( $country, $state, $id ); |
|
280 | + $vat_rate = wpinv_get_tax_rate($country, $state, $id); |
|
281 | 281 | |
282 | - $tax = $amount > 0 ? ( $amount * 0.01 * (float)$vat_rate ) : 0; |
|
282 | + $tax = $amount > 0 ? ($amount * 0.01 * (float)$vat_rate) : 0; |
|
283 | 283 | $total_tax += $tax; |
284 | 284 | |
285 | 285 | $items_array[] = array( |
286 | 286 | 'id' => $id, |
287 | - 'title' => esc_html( $title ), |
|
288 | - 'description' => esc_html( $desc ), |
|
289 | - 'amount' => $amount > 0 ? wpinv_round_amount( $amount ) : 0, |
|
290 | - 'subtotal' => $amount > 0 ? wpinv_round_amount( $amount ) : 0, |
|
287 | + 'title' => esc_html($title), |
|
288 | + 'description' => esc_html($desc), |
|
289 | + 'amount' => $amount > 0 ? wpinv_round_amount($amount) : 0, |
|
290 | + 'subtotal' => $amount > 0 ? wpinv_round_amount($amount) : 0, |
|
291 | 291 | 'vat_rates_class' => $vat_rates_class, |
292 | - 'vat_rate' => $vat_rate > 0 ? wpinv_round_amount( $vat_rate ) : 0, |
|
293 | - 'tax' => $tax > 0 ? wpinv_round_amount( $tax ) : 0, |
|
292 | + 'vat_rate' => $vat_rate > 0 ? wpinv_round_amount($vat_rate) : 0, |
|
293 | + 'tax' => $tax > 0 ? wpinv_round_amount($tax) : 0, |
|
294 | 294 | ); |
295 | 295 | } |
296 | 296 | |
297 | - update_post_meta( $invoice->ID, '_wpinv_tax', wpinv_round_amount( $total_tax ) ); |
|
298 | - $invoice->set( 'tax', wpinv_round_amount( $total_tax ) ); |
|
297 | + update_post_meta($invoice->ID, '_wpinv_tax', wpinv_round_amount($total_tax)); |
|
298 | + $invoice->set('tax', wpinv_round_amount($total_tax)); |
|
299 | 299 | |
300 | - $items_array = apply_filters( 'wpinv_save_invoice_items', $items_array, $data['items'], $invoice ); |
|
300 | + $items_array = apply_filters('wpinv_save_invoice_items', $items_array, $data['items'], $invoice); |
|
301 | 301 | |
302 | - $invoice->set( 'items', $items_array ); |
|
303 | - update_post_meta( $invoice->ID, '_wpinv_items', $items_array ); |
|
302 | + $invoice->set('items', $items_array); |
|
303 | + update_post_meta($invoice->ID, '_wpinv_items', $items_array); |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | return $invoice; |
307 | 307 | } |
308 | 308 | |
309 | - protected function set_invoice_meta( $invoice_id, $invoice_meta ) { |
|
310 | - foreach ( $invoice_meta as $meta_key => $meta_value ) { |
|
309 | + protected function set_invoice_meta($invoice_id, $invoice_meta) { |
|
310 | + foreach ($invoice_meta as $meta_key => $meta_value) { |
|
311 | 311 | |
312 | - if ( is_string( $meta_key) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) { |
|
313 | - update_post_meta( $invoice_id, $meta_key, $meta_value ); |
|
312 | + if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) { |
|
313 | + update_post_meta($invoice_id, $meta_key, $meta_value); |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | } |
@@ -320,9 +320,9 @@ discard block |
||
320 | 320 | class WPInv_API_Exception extends Exception { |
321 | 321 | protected $error_code; |
322 | 322 | |
323 | - public function __construct( $error_code, $error_message, $http_status_code ) { |
|
323 | + public function __construct($error_code, $error_message, $http_status_code) { |
|
324 | 324 | $this->error_code = $error_code; |
325 | - parent::__construct( $error_message, $http_status_code ); |
|
325 | + parent::__construct($error_message, $http_status_code); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | public function getErrorCode() { |