@@ -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 |
@@ -25,30 +25,30 @@ discard block |
||
| 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,16 +57,16 @@ 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 | - 'landing_page' => apply_filters( 'wpinv_paypal_standard_landing_page', 'billing', $invoice ), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account. |
|
| 69 | + 'landing_page' => apply_filters('wpinv_paypal_standard_landing_page', 'billing', $invoice), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account. |
|
| 70 | 70 | ); |
| 71 | 71 | |
| 72 | 72 | $paypal_args['address1'] = $invoice->get_address(); |
@@ -80,57 +80,57 @@ discard block |
||
| 80 | 80 | 'upload' => '1' |
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | - $paypal_args = array_merge( $paypal_extra_args, $paypal_args ); |
|
| 83 | + $paypal_args = array_merge($paypal_extra_args, $paypal_args); |
|
| 84 | 84 | |
| 85 | 85 | // Add cart items |
| 86 | 86 | $i = 1; |
| 87 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
| 88 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
| 87 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
| 88 | + foreach ($purchase_data['cart_details'] as $item) { |
|
| 89 | 89 | $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1; |
| 90 | - $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 ); |
|
| 90 | + $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2); |
|
| 91 | 91 | |
| 92 | - if ( $item_amount <= 0 ) { |
|
| 92 | + if ($item_amount <= 0) { |
|
| 93 | 93 | $item_amount = 0; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - $paypal_args['item_number_' . $i ] = $item['id']; |
|
| 97 | - $paypal_args['item_name_' . $i ] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) ); |
|
| 98 | - $paypal_args['quantity_' . $i ] = $item['quantity']; |
|
| 99 | - $paypal_args['amount_' . $i ] = $item_amount; |
|
| 100 | - $paypal_args['discount_amount_' . $i ] = wpinv_sanitize_amount( $item['discount'], 2 ); |
|
| 96 | + $paypal_args['item_number_' . $i] = $item['id']; |
|
| 97 | + $paypal_args['item_name_' . $i] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8')); |
|
| 98 | + $paypal_args['quantity_' . $i] = $item['quantity']; |
|
| 99 | + $paypal_args['amount_' . $i] = $item_amount; |
|
| 100 | + $paypal_args['discount_amount_' . $i] = wpinv_sanitize_amount($item['discount'], 2); |
|
| 101 | 101 | |
| 102 | 102 | $i++; |
| 103 | 103 | } |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Add taxes to the cart |
| 107 | - if ( wpinv_use_taxes() ) { |
|
| 108 | - $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax(), 2 ); |
|
| 107 | + if (wpinv_use_taxes()) { |
|
| 108 | + $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax(), 2); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice ); |
|
| 111 | + $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice); |
|
| 112 | 112 | |
| 113 | 113 | // Build query |
| 114 | - $paypal_redirect .= http_build_query( $paypal_args ); |
|
| 114 | + $paypal_redirect .= http_build_query($paypal_args); |
|
| 115 | 115 | |
| 116 | 116 | // Fix for some sites that encode the entities |
| 117 | - $paypal_redirect = str_replace( '&', '&', $paypal_redirect ); |
|
| 117 | + $paypal_redirect = str_replace('&', '&', $paypal_redirect); |
|
| 118 | 118 | |
| 119 | 119 | // Get rid of cart contents |
| 120 | 120 | wpinv_empty_cart(); |
| 121 | 121 | |
| 122 | 122 | // Redirect to PayPal |
| 123 | - wp_redirect( $paypal_redirect ); |
|
| 123 | + wp_redirect($paypal_redirect); |
|
| 124 | 124 | exit; |
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | -add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' ); |
|
| 127 | +add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment'); |
|
| 128 | 128 | |
| 129 | -function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) { |
|
| 130 | - if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) { |
|
| 131 | - $item = new WPInv_Item( $item_id ); |
|
| 129 | +function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) { |
|
| 130 | + if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) { |
|
| 131 | + $item = new WPInv_Item($item_id); |
|
| 132 | 132 | |
| 133 | - if ( empty( $item ) ) { |
|
| 133 | + if (empty($item)) { |
|
| 134 | 134 | return $paypal_args; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -138,24 +138,24 @@ discard block |
||
| 138 | 138 | $interval = $item->get_recurring_interval(); |
| 139 | 139 | $bill_times = (int)$item->get_recurring_limit(); |
| 140 | 140 | |
| 141 | - $initial_amount = wpinv_sanitize_amount( $invoice->get_total(), 2 ); |
|
| 142 | - $recurring_amount = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 ); |
|
| 141 | + $initial_amount = wpinv_sanitize_amount($invoice->get_total(), 2); |
|
| 142 | + $recurring_amount = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2); |
|
| 143 | 143 | |
| 144 | 144 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
| 145 | 145 | $paypal_args['sra'] = '1'; |
| 146 | 146 | $paypal_args['src'] = '1'; |
| 147 | 147 | |
| 148 | 148 | // Set item description |
| 149 | - $paypal_args['item_name'] = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( array( 'id' => $item->ID ) ), ENT_COMPAT, 'UTF-8' ) ); |
|
| 149 | + $paypal_args['item_name'] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name(array('id' => $item->ID)), ENT_COMPAT, 'UTF-8')); |
|
| 150 | 150 | |
| 151 | - if ( $invoice->is_free_trial() && $item->has_free_trial() ) { |
|
| 151 | + if ($invoice->is_free_trial() && $item->has_free_trial()) { |
|
| 152 | 152 | $paypal_args['a1'] = $initial_amount; |
| 153 | 153 | $paypal_args['p1'] = $item->get_trial_interval(); |
| 154 | 154 | $paypal_args['t1'] = $item->get_trial_period(); |
| 155 | 155 | |
| 156 | 156 | // Set the recurring amount |
| 157 | 157 | $paypal_args['a3'] = $recurring_amount; |
| 158 | - } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) { |
|
| 158 | + } else if ($initial_amount != $recurring_amount && $bill_times != 1) { |
|
| 159 | 159 | $paypal_args['a1'] = $initial_amount; |
| 160 | 160 | $paypal_args['p1'] = $interval; |
| 161 | 161 | $paypal_args['t1'] = $period; |
@@ -163,63 +163,63 @@ discard block |
||
| 163 | 163 | // Set the recurring amount |
| 164 | 164 | $paypal_args['a3'] = $recurring_amount; |
| 165 | 165 | |
| 166 | - if ( $bill_times > 1 ) { |
|
| 166 | + if ($bill_times > 1) { |
|
| 167 | 167 | $bill_times--; |
| 168 | 168 | } |
| 169 | 169 | } else { |
| 170 | - $paypal_args['a3'] = $initial_amount; |
|
| 170 | + $paypal_args['a3'] = $initial_amount; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | $paypal_args['p3'] = $interval; |
| 174 | 174 | $paypal_args['t3'] = $period; |
| 175 | 175 | |
| 176 | - if ( $bill_times > 1 ) { |
|
| 176 | + if ($bill_times > 1) { |
|
| 177 | 177 | // Make sure it's not over the max of 52 |
| 178 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
| 178 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | // Remove cart items |
| 182 | 182 | $i = 1; |
| 183 | - if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) { |
|
| 184 | - foreach ( $purchase_data['cart_details'] as $item ) { |
|
| 185 | - if ( isset( $paypal_args['item_number_' . $i] ) ) { |
|
| 186 | - unset( $paypal_args['item_number_' . $i] ); |
|
| 183 | + if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) { |
|
| 184 | + foreach ($purchase_data['cart_details'] as $item) { |
|
| 185 | + if (isset($paypal_args['item_number_' . $i])) { |
|
| 186 | + unset($paypal_args['item_number_' . $i]); |
|
| 187 | 187 | } |
| 188 | - if ( isset( $paypal_args['item_name_' . $i] ) ) { |
|
| 189 | - unset( $paypal_args['item_name_' . $i] ); |
|
| 188 | + if (isset($paypal_args['item_name_' . $i])) { |
|
| 189 | + unset($paypal_args['item_name_' . $i]); |
|
| 190 | 190 | } |
| 191 | - if ( isset( $paypal_args['quantity_' . $i] ) ) { |
|
| 192 | - unset( $paypal_args['quantity_' . $i] ); |
|
| 191 | + if (isset($paypal_args['quantity_' . $i])) { |
|
| 192 | + unset($paypal_args['quantity_' . $i]); |
|
| 193 | 193 | } |
| 194 | - if ( isset( $paypal_args['amount_' . $i] ) ) { |
|
| 195 | - unset( $paypal_args['amount_' . $i] ); |
|
| 194 | + if (isset($paypal_args['amount_' . $i])) { |
|
| 195 | + unset($paypal_args['amount_' . $i]); |
|
| 196 | 196 | } |
| 197 | - if ( isset( $paypal_args['discount_amount_' . $i] ) ) { |
|
| 198 | - unset( $paypal_args['discount_amount_' . $i] ); |
|
| 197 | + if (isset($paypal_args['discount_amount_' . $i])) { |
|
| 198 | + unset($paypal_args['discount_amount_' . $i]); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | $i++; |
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - if ( isset( $paypal_args['tax_cart'] ) ) { |
|
| 206 | - unset( $paypal_args['tax_cart'] ); |
|
| 205 | + if (isset($paypal_args['tax_cart'])) { |
|
| 206 | + unset($paypal_args['tax_cart']); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - if ( isset( $paypal_args['upload'] ) ) { |
|
| 210 | - unset( $paypal_args['upload'] ); |
|
| 209 | + if (isset($paypal_args['upload'])) { |
|
| 210 | + unset($paypal_args['upload']); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice ); |
|
| 213 | + $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | return $paypal_args; |
| 217 | 217 | } |
| 218 | -add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 ); |
|
| 218 | +add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3); |
|
| 219 | 219 | |
| 220 | 220 | function wpinv_process_paypal_ipn() { |
| 221 | 221 | // Check the request method is POST |
| 222 | - if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) { |
|
| 222 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') { |
|
| 223 | 223 | return; |
| 224 | 224 | } |
| 225 | 225 | |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | $post_data = ''; |
| 228 | 228 | |
| 229 | 229 | // Fallback just in case post_max_size is lower than needed |
| 230 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 231 | - $post_data = file_get_contents( 'php://input' ); |
|
| 230 | + if (ini_get('allow_url_fopen')) { |
|
| 231 | + $post_data = file_get_contents('php://input'); |
|
| 232 | 232 | } else { |
| 233 | 233 | // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough |
| 234 | - ini_set( 'post_max_size', '12M' ); |
|
| 234 | + ini_set('post_max_size', '12M'); |
|
| 235 | 235 | } |
| 236 | 236 | // Start the encoded data collection with notification command |
| 237 | 237 | $encoded_data = 'cmd=_notify-validate'; |
@@ -240,43 +240,43 @@ discard block |
||
| 240 | 240 | $arg_separator = wpinv_get_php_arg_separator_output(); |
| 241 | 241 | |
| 242 | 242 | // Verify there is a post_data |
| 243 | - if ( $post_data || strlen( $post_data ) > 0 ) { |
|
| 243 | + if ($post_data || strlen($post_data) > 0) { |
|
| 244 | 244 | // Append the data |
| 245 | - $encoded_data .= $arg_separator.$post_data; |
|
| 245 | + $encoded_data .= $arg_separator . $post_data; |
|
| 246 | 246 | } else { |
| 247 | 247 | // Check if POST is empty |
| 248 | - if ( empty( $_POST ) ) { |
|
| 248 | + if (empty($_POST)) { |
|
| 249 | 249 | // Nothing to do |
| 250 | 250 | return; |
| 251 | 251 | } else { |
| 252 | 252 | // Loop through each POST |
| 253 | - foreach ( $_POST as $key => $value ) { |
|
| 253 | + foreach ($_POST as $key => $value) { |
|
| 254 | 254 | // Encode the value and append the data |
| 255 | - $encoded_data .= $arg_separator."$key=" . urlencode( $value ); |
|
| 255 | + $encoded_data .= $arg_separator . "$key=" . urlencode($value); |
|
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | // Convert collected post data to an array |
| 261 | - parse_str( $encoded_data, $encoded_data_array ); |
|
| 261 | + parse_str($encoded_data, $encoded_data_array); |
|
| 262 | 262 | |
| 263 | - foreach ( $encoded_data_array as $key => $value ) { |
|
| 264 | - if ( false !== strpos( $key, 'amp;' ) ) { |
|
| 265 | - $new_key = str_replace( '&', '&', $key ); |
|
| 266 | - $new_key = str_replace( 'amp;', '&' , $new_key ); |
|
| 263 | + foreach ($encoded_data_array as $key => $value) { |
|
| 264 | + if (false !== strpos($key, 'amp;')) { |
|
| 265 | + $new_key = str_replace('&', '&', $key); |
|
| 266 | + $new_key = str_replace('amp;', '&', $new_key); |
|
| 267 | 267 | |
| 268 | - unset( $encoded_data_array[ $key ] ); |
|
| 269 | - $encoded_data_array[ $new_key ] = $value; |
|
| 268 | + unset($encoded_data_array[$key]); |
|
| 269 | + $encoded_data_array[$new_key] = $value; |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // Get the PayPal redirect uri |
| 274 | - $paypal_redirect = wpinv_get_paypal_redirect( true ); |
|
| 274 | + $paypal_redirect = wpinv_get_paypal_redirect(true); |
|
| 275 | 275 | |
| 276 | - if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 276 | + if (!wpinv_get_option('disable_paypal_verification', false)) { |
|
| 277 | 277 | // Validate the IPN |
| 278 | 278 | |
| 279 | - $remote_post_vars = array( |
|
| 279 | + $remote_post_vars = array( |
|
| 280 | 280 | 'method' => 'POST', |
| 281 | 281 | 'timeout' => 45, |
| 282 | 282 | 'redirection' => 5, |
@@ -294,21 +294,21 @@ discard block |
||
| 294 | 294 | ); |
| 295 | 295 | |
| 296 | 296 | // Get response |
| 297 | - $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars ); |
|
| 297 | + $api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars); |
|
| 298 | 298 | |
| 299 | - if ( is_wp_error( $api_response ) ) { |
|
| 300 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 299 | + if (is_wp_error($api_response)) { |
|
| 300 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
| 301 | 301 | return; // Something went wrong |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) { |
|
| 305 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) ); |
|
| 304 | + if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) { |
|
| 305 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response))); |
|
| 306 | 306 | return; // Response not okay |
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | // Check if $post_data_array has been populated |
| 311 | - if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) |
|
| 311 | + if (!is_array($encoded_data_array) && !empty($encoded_data_array)) |
|
| 312 | 312 | return; |
| 313 | 313 | |
| 314 | 314 | $defaults = array( |
@@ -316,215 +316,215 @@ discard block |
||
| 316 | 316 | 'payment_status' => '' |
| 317 | 317 | ); |
| 318 | 318 | |
| 319 | - $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults ); |
|
| 319 | + $encoded_data_array = wp_parse_args($encoded_data_array, $defaults); |
|
| 320 | 320 | |
| 321 | - $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0; |
|
| 321 | + $invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0; |
|
| 322 | 322 | |
| 323 | - wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ ); |
|
| 323 | + wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__); |
|
| 324 | 324 | |
| 325 | - if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) { |
|
| 325 | + if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) { |
|
| 326 | 326 | // Allow PayPal IPN types to be processed separately |
| 327 | - do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id ); |
|
| 327 | + do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id); |
|
| 328 | 328 | } else { |
| 329 | 329 | // Fallback to web accept just in case the txn_type isn't present |
| 330 | - do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id ); |
|
| 330 | + do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id); |
|
| 331 | 331 | } |
| 332 | 332 | exit; |
| 333 | 333 | } |
| 334 | -add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' ); |
|
| 334 | +add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn'); |
|
| 335 | 335 | |
| 336 | -function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) { |
|
| 337 | - if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) { |
|
| 336 | +function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) { |
|
| 337 | + if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') { |
|
| 338 | 338 | return; |
| 339 | 339 | } |
| 340 | 340 | |
| 341 | - if( empty( $invoice_id ) ) { |
|
| 341 | + if (empty($invoice_id)) { |
|
| 342 | 342 | return; |
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | // Collect payment details |
| 346 | - $purchase_key = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number']; |
|
| 346 | + $purchase_key = isset($data['invoice']) ? $data['invoice'] : $data['item_number']; |
|
| 347 | 347 | $paypal_amount = $data['mc_gross']; |
| 348 | - $payment_status = strtolower( $data['payment_status'] ); |
|
| 349 | - $currency_code = strtolower( $data['mc_currency'] ); |
|
| 350 | - $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] ); |
|
| 351 | - $payment_meta = wpinv_get_invoice_meta( $invoice_id ); |
|
| 348 | + $payment_status = strtolower($data['payment_status']); |
|
| 349 | + $currency_code = strtolower($data['mc_currency']); |
|
| 350 | + $business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']); |
|
| 351 | + $payment_meta = wpinv_get_invoice_meta($invoice_id); |
|
| 352 | 352 | |
| 353 | - if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) { |
|
| 353 | + if (wpinv_get_payment_gateway($invoice_id) != 'paypal') { |
|
| 354 | 354 | return; // this isn't a PayPal standard IPN |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | // Verify payment recipient |
| 358 | - if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) { |
|
| 359 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 360 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 361 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) ); |
|
| 358 | + if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) { |
|
| 359 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 360 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 361 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing')); |
|
| 362 | 362 | return; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | // Verify payment currency |
| 366 | - if ( $currency_code != strtolower( $payment_meta['currency'] ) ) { |
|
| 367 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 368 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 369 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) ); |
|
| 366 | + if ($currency_code != strtolower($payment_meta['currency'])) { |
|
| 367 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 368 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 369 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing')); |
|
| 370 | 370 | return; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - if ( !wpinv_get_payment_user_email( $invoice_id ) ) { |
|
| 373 | + if (!wpinv_get_payment_user_email($invoice_id)) { |
|
| 374 | 374 | // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal |
| 375 | 375 | // No email associated with purchase, so store from PayPal |
| 376 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] ); |
|
| 376 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']); |
|
| 377 | 377 | |
| 378 | 378 | // Setup and store the customer's details |
| 379 | 379 | $user_info = array( |
| 380 | 380 | 'user_id' => '-1', |
| 381 | - 'email' => sanitize_text_field( $data['payer_email'] ), |
|
| 382 | - 'first_name' => sanitize_text_field( $data['first_name'] ), |
|
| 383 | - 'last_name' => sanitize_text_field( $data['last_name'] ), |
|
| 381 | + 'email' => sanitize_text_field($data['payer_email']), |
|
| 382 | + 'first_name' => sanitize_text_field($data['first_name']), |
|
| 383 | + 'last_name' => sanitize_text_field($data['last_name']), |
|
| 384 | 384 | 'discount' => '', |
| 385 | 385 | ); |
| 386 | - $user_info['address'] = ! empty( $data['address_street'] ) ? sanitize_text_field( $data['address_street'] ) : false; |
|
| 387 | - $user_info['city'] = ! empty( $data['address_city'] ) ? sanitize_text_field( $data['address_city'] ) : false; |
|
| 388 | - $user_info['state'] = ! empty( $data['address_state'] ) ? sanitize_text_field( $data['address_state'] ) : false; |
|
| 389 | - $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false; |
|
| 390 | - $user_info['zip'] = ! empty( $data['address_zip'] ) ? sanitize_text_field( $data['address_zip'] ) : false; |
|
| 386 | + $user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false; |
|
| 387 | + $user_info['city'] = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false; |
|
| 388 | + $user_info['state'] = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false; |
|
| 389 | + $user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false; |
|
| 390 | + $user_info['zip'] = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false; |
|
| 391 | 391 | |
| 392 | 392 | $payment_meta['user_info'] = $user_info; |
| 393 | - wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta ); |
|
| 393 | + wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
| 396 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
| 397 | 397 | // Process a refund |
| 398 | - wpinv_process_paypal_refund( $data, $invoice_id ); |
|
| 398 | + wpinv_process_paypal_refund($data, $invoice_id); |
|
| 399 | 399 | } else { |
| 400 | - if ( get_post_status( $invoice_id ) == 'publish' ) { |
|
| 400 | + if (get_post_status($invoice_id) == 'publish') { |
|
| 401 | 401 | return; // Only paid payments once |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | // Retrieve the total purchase amount (before PayPal) |
| 405 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 405 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
| 406 | 406 | |
| 407 | - if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 407 | + if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
| 408 | 408 | // The prices don't match |
| 409 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 410 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 411 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) ); |
|
| 409 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 410 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 411 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing')); |
|
| 412 | 412 | return; |
| 413 | 413 | } |
| 414 | - if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) { |
|
| 414 | + if ($purchase_key != wpinv_get_payment_key($invoice_id)) { |
|
| 415 | 415 | // Purchase keys don't match |
| 416 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id ); |
|
| 417 | - wpinv_update_payment_status( $invoice_id, 'wpi-failed' ); |
|
| 418 | - wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) ); |
|
| 416 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id); |
|
| 417 | + wpinv_update_payment_status($invoice_id, 'wpi-failed'); |
|
| 418 | + wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing')); |
|
| 419 | 419 | return; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) { |
|
| 423 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) ); |
|
| 424 | - wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] ); |
|
| 425 | - wpinv_update_payment_status( $invoice_id, 'publish' ); |
|
| 426 | - } else if ( 'wpi-pending' == $payment_status && isset( $data['pending_reason'] ) ) { |
|
| 422 | + if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) { |
|
| 423 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id'])); |
|
| 424 | + wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']); |
|
| 425 | + wpinv_update_payment_status($invoice_id, 'publish'); |
|
| 426 | + } else if ('wpi-pending' == $payment_status && isset($data['pending_reason'])) { |
|
| 427 | 427 | // Look for possible pending reasons, such as an echeck |
| 428 | 428 | $note = ''; |
| 429 | 429 | |
| 430 | - switch( strtolower( $data['pending_reason'] ) ) { |
|
| 430 | + switch (strtolower($data['pending_reason'])) { |
|
| 431 | 431 | case 'echeck' : |
| 432 | - $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' ); |
|
| 432 | + $note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing'); |
|
| 433 | 433 | break; |
| 434 | 434 | |
| 435 | 435 | case 'address' : |
| 436 | - $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' ); |
|
| 436 | + $note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing'); |
|
| 437 | 437 | break; |
| 438 | 438 | |
| 439 | 439 | case 'intl' : |
| 440 | - $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' ); |
|
| 440 | + $note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing'); |
|
| 441 | 441 | break; |
| 442 | 442 | |
| 443 | 443 | case 'multi-currency' : |
| 444 | - $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' ); |
|
| 444 | + $note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing'); |
|
| 445 | 445 | break; |
| 446 | 446 | |
| 447 | 447 | case 'paymentreview' : |
| 448 | 448 | case 'regulatory_review' : |
| 449 | - $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' ); |
|
| 449 | + $note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing'); |
|
| 450 | 450 | break; |
| 451 | 451 | |
| 452 | 452 | case 'unilateral' : |
| 453 | - $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' ); |
|
| 453 | + $note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing'); |
|
| 454 | 454 | break; |
| 455 | 455 | |
| 456 | 456 | case 'upgrade' : |
| 457 | - $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' ); |
|
| 457 | + $note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing'); |
|
| 458 | 458 | break; |
| 459 | 459 | |
| 460 | 460 | case 'verify' : |
| 461 | - $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' ); |
|
| 461 | + $note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing'); |
|
| 462 | 462 | break; |
| 463 | 463 | |
| 464 | 464 | case 'other' : |
| 465 | - $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' ); |
|
| 465 | + $note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing'); |
|
| 466 | 466 | break; |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | - if ( ! empty( $note ) ) { |
|
| 470 | - wpinv_insert_payment_note( $invoice_id, $note ); |
|
| 469 | + if (!empty($note)) { |
|
| 470 | + wpinv_insert_payment_note($invoice_id, $note); |
|
| 471 | 471 | } |
| 472 | 472 | } else { |
| 473 | - wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) ); |
|
| 473 | + wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status)); |
|
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | 476 | } |
| 477 | -add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 ); |
|
| 477 | +add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2); |
|
| 478 | 478 | |
| 479 | 479 | // Process PayPal subscription sign ups |
| 480 | -add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' ); |
|
| 480 | +add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup'); |
|
| 481 | 481 | |
| 482 | 482 | // Process PayPal subscription payments |
| 483 | -add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' ); |
|
| 483 | +add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment'); |
|
| 484 | 484 | |
| 485 | 485 | // Process PayPal subscription cancellations |
| 486 | -add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' ); |
|
| 486 | +add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel'); |
|
| 487 | 487 | |
| 488 | 488 | // Process PayPal subscription end of term notices |
| 489 | -add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' ); |
|
| 489 | +add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot'); |
|
| 490 | 490 | |
| 491 | 491 | // Process PayPal payment failed |
| 492 | -add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' ); |
|
| 492 | +add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed'); |
|
| 493 | 493 | |
| 494 | 494 | |
| 495 | 495 | /** |
| 496 | 496 | * Process the subscription started IPN. |
| 497 | 497 | */ |
| 498 | -function wpinv_process_paypal_subscr_signup( $ipn_data ) { |
|
| 499 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
| 500 | - if( empty( $parent_invoice_id ) ) { |
|
| 498 | +function wpinv_process_paypal_subscr_signup($ipn_data) { |
|
| 499 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
| 500 | + if (empty($parent_invoice_id)) { |
|
| 501 | 501 | return; |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
| 505 | - if ( empty( $invoice ) ) { |
|
| 504 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
| 505 | + if (empty($invoice)) { |
|
| 506 | 506 | return; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) { |
|
| 510 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ) ); |
|
| 511 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['invoice'] ); |
|
| 509 | + if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) { |
|
| 510 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice'])); |
|
| 511 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['invoice']); |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
| 514 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
| 515 | 515 | sleep(1); |
| 516 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ) ); |
|
| 516 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id'])); |
|
| 517 | 517 | |
| 518 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 519 | - if ( false === $subscription ) { |
|
| 518 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 519 | + if (false === $subscription) { |
|
| 520 | 520 | return; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - $cart_details = $invoice->cart_details; |
|
| 523 | + $cart_details = $invoice->cart_details; |
|
| 524 | 524 | |
| 525 | - if ( !empty( $cart_details ) ) { |
|
| 526 | - foreach ( $cart_details as $cart_item ) { |
|
| 527 | - $item = new WPInv_Item( $cart_item['id'] ); |
|
| 525 | + if (!empty($cart_details)) { |
|
| 526 | + foreach ($cart_details as $cart_item) { |
|
| 527 | + $item = new WPInv_Item($cart_item['id']); |
|
| 528 | 528 | |
| 529 | 529 | $status = $invoice->is_free_trial() && $item->has_free_trial() ? 'trialing' : 'active'; |
| 530 | 530 | |
@@ -533,15 +533,15 @@ discard block |
||
| 533 | 533 | 'status' => $status, |
| 534 | 534 | 'period' => $item->get_recurring_period(), |
| 535 | 535 | 'initial_amount' => $invoice->get_total(), |
| 536 | - 'recurring_amount' => $invoice->get_recurring_details( 'total' ), |
|
| 536 | + 'recurring_amount' => $invoice->get_recurring_details('total'), |
|
| 537 | 537 | 'interval' => $item->get_recurring_interval(), |
| 538 | 538 | 'bill_times' => $item->get_recurring_limit(), |
| 539 | - 'expiration' => $invoice->get_new_expiration( $cart_item['id'] ), |
|
| 539 | + 'expiration' => $invoice->get_new_expiration($cart_item['id']), |
|
| 540 | 540 | 'profile_id' => $ipn_data['subscr_id'], |
| 541 | - 'created' => date_i18n( 'Y-m-d H:i:s', strtotime( $ipn_data['subscr_date'] ) ) |
|
| 541 | + 'created' => date_i18n('Y-m-d H:i:s', strtotime($ipn_data['subscr_date'])) |
|
| 542 | 542 | ); |
| 543 | 543 | |
| 544 | - if ( $item->has_free_trial() ) { |
|
| 544 | + if ($item->has_free_trial()) { |
|
| 545 | 545 | $args['trial_period'] = $item->get_trial_period(); |
| 546 | 546 | $args['trial_interval'] = $item->get_trial_interval(); |
| 547 | 547 | } else { |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | |
| 553 | - $subscription->update_subscription( $args ); |
|
| 553 | + $subscription->update_subscription($args); |
|
| 554 | 554 | } |
| 555 | 555 | } |
| 556 | 556 | } |
@@ -558,45 +558,45 @@ discard block |
||
| 558 | 558 | /** |
| 559 | 559 | * Process the subscription payment received IPN. |
| 560 | 560 | */ |
| 561 | -function wpinv_process_paypal_subscr_payment( $ipn_data ) { |
|
| 562 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
| 561 | +function wpinv_process_paypal_subscr_payment($ipn_data) { |
|
| 562 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
| 563 | 563 | |
| 564 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 565 | - if ( false === $subscription ) { |
|
| 564 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 565 | + if (false === $subscription) { |
|
| 566 | 566 | return; |
| 567 | 567 | } |
| 568 | 568 | |
| 569 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
| 570 | - if ( empty( $parent_invoice ) ) { |
|
| 569 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
| 570 | + if (empty($parent_invoice)) { |
|
| 571 | 571 | return; |
| 572 | 572 | } |
| 573 | 573 | |
| 574 | - $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id ); |
|
| 574 | + $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id); |
|
| 575 | 575 | $signup_date = $subscription->get_subscription_created(); |
| 576 | 576 | $payment_date = $ipn_data['payment_date']; |
| 577 | - $times_billed = $parent_invoice->get_total_payments( false ); |
|
| 577 | + $times_billed = $parent_invoice->get_total_payments(false); |
|
| 578 | 578 | |
| 579 | 579 | // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet. |
| 580 | - if ( empty( $times_billed ) && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) { |
|
| 581 | - wpinv_update_payment_status( $parent_invoice_id, 'publish' ); |
|
| 580 | + if (empty($times_billed) && (!$transaction_id || $transaction_id == $parent_invoice_id)) { |
|
| 581 | + wpinv_update_payment_status($parent_invoice_id, 'publish'); |
|
| 582 | 582 | sleep(1); |
| 583 | 583 | |
| 584 | 584 | // This is the very first payment |
| 585 | - wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] ); |
|
| 586 | - wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) ); |
|
| 585 | + wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']); |
|
| 586 | + wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id'])); |
|
| 587 | 587 | return; |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | - if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) { |
|
| 590 | + if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) { |
|
| 591 | 591 | return; // Payment already recorded |
| 592 | 592 | } |
| 593 | 593 | |
| 594 | - $currency_code = strtolower( $ipn_data['mc_currency'] ); |
|
| 594 | + $currency_code = strtolower($ipn_data['mc_currency']); |
|
| 595 | 595 | |
| 596 | 596 | // verify details |
| 597 | - if ( $currency_code != strtolower( wpinv_get_currency() ) ) { |
|
| 597 | + if ($currency_code != strtolower(wpinv_get_currency())) { |
|
| 598 | 598 | // the currency code is invalid |
| 599 | - wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) ); |
|
| 599 | + wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data))); |
|
| 600 | 600 | return; |
| 601 | 601 | } |
| 602 | 602 | |
@@ -605,11 +605,11 @@ discard block |
||
| 605 | 605 | 'transaction_id' => $ipn_data['txn_id'] |
| 606 | 606 | ); |
| 607 | 607 | |
| 608 | - $invoice = wpinv_recurring_add_subscription_payment( $parent_invoice_id, $args ); |
|
| 608 | + $invoice = wpinv_recurring_add_subscription_payment($parent_invoice_id, $args); |
|
| 609 | 609 | |
| 610 | - if ( !empty( $invoice ) ) { |
|
| 610 | + if (!empty($invoice)) { |
|
| 611 | 611 | sleep(1); |
| 612 | - wpinv_insert_payment_note( $invoice->ID, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) ); |
|
| 612 | + wpinv_insert_payment_note($invoice->ID, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id'])); |
|
| 613 | 613 | |
| 614 | 614 | $invoice->renew_subscription(); |
| 615 | 615 | } |
@@ -618,10 +618,10 @@ discard block |
||
| 618 | 618 | /** |
| 619 | 619 | * Process the subscription canceled IPN. |
| 620 | 620 | */ |
| 621 | -function wpinv_process_paypal_subscr_cancel( $ipn_data ) { |
|
| 622 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 621 | +function wpinv_process_paypal_subscr_cancel($ipn_data) { |
|
| 622 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 623 | 623 | |
| 624 | - if( false === $subscription ) { |
|
| 624 | + if (false === $subscription) { |
|
| 625 | 625 | return; |
| 626 | 626 | } |
| 627 | 627 | |
@@ -631,10 +631,10 @@ discard block |
||
| 631 | 631 | /** |
| 632 | 632 | * Process the subscription expired IPN. |
| 633 | 633 | */ |
| 634 | -function wpinv_process_paypal_subscr_eot( $ipn_data ) { |
|
| 635 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 634 | +function wpinv_process_paypal_subscr_eot($ipn_data) { |
|
| 635 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 636 | 636 | |
| 637 | - if( false === $subscription ) { |
|
| 637 | + if (false === $subscription) { |
|
| 638 | 638 | return; |
| 639 | 639 | } |
| 640 | 640 | |
@@ -644,45 +644,45 @@ discard block |
||
| 644 | 644 | /** |
| 645 | 645 | * Process the subscription payment failed IPN. |
| 646 | 646 | */ |
| 647 | -function wpinv_process_paypal_subscr_failed( $ipn_data ) { |
|
| 648 | - $subscription = wpinv_get_paypal_subscription( $ipn_data ); |
|
| 647 | +function wpinv_process_paypal_subscr_failed($ipn_data) { |
|
| 648 | + $subscription = wpinv_get_paypal_subscription($ipn_data); |
|
| 649 | 649 | |
| 650 | - if( false === $subscription ) { |
|
| 650 | + if (false === $subscription) { |
|
| 651 | 651 | return; |
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | $subscription->failing_subscription(); |
| 655 | 655 | |
| 656 | - do_action( 'wpinv_recurring_payment_failed', $subscription ); |
|
| 656 | + do_action('wpinv_recurring_payment_failed', $subscription); |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | /** |
| 660 | 660 | * Retrieve the subscription this IPN notice is for. |
| 661 | 661 | */ |
| 662 | -function wpinv_get_paypal_subscription( $ipn_data = array() ) { |
|
| 663 | - $parent_invoice_id = absint( $ipn_data['custom'] ); |
|
| 662 | +function wpinv_get_paypal_subscription($ipn_data = array()) { |
|
| 663 | + $parent_invoice_id = absint($ipn_data['custom']); |
|
| 664 | 664 | |
| 665 | - if( empty( $parent_invoice_id ) ) { |
|
| 665 | + if (empty($parent_invoice_id)) { |
|
| 666 | 666 | return false; |
| 667 | 667 | } |
| 668 | 668 | |
| 669 | - $invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
| 670 | - if ( empty( $invoice ) ) { |
|
| 669 | + $invoice = wpinv_get_invoice($parent_invoice_id); |
|
| 670 | + if (empty($invoice)) { |
|
| 671 | 671 | return false; |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | - $subscription = wpinv_get_subscription( $ipn_data['subscr_id'], true ); |
|
| 674 | + $subscription = wpinv_get_subscription($ipn_data['subscr_id'], true); |
|
| 675 | 675 | |
| 676 | - if ( empty( $subscription ) ) { |
|
| 677 | - $subs = wpinv_get_subscriptions( array( 'parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1 ) ); |
|
| 678 | - $subscription = reset( $subs ); |
|
| 676 | + if (empty($subscription)) { |
|
| 677 | + $subs = wpinv_get_subscriptions(array('parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1)); |
|
| 678 | + $subscription = reset($subs); |
|
| 679 | 679 | |
| 680 | - if ( $subscription && $subscription->ID > 0 ) { |
|
| 680 | + if ($subscription && $subscription->ID > 0) { |
|
| 681 | 681 | // Update the profile ID so it is set for future renewals |
| 682 | - $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
| 682 | + $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
| 683 | 683 | } else { |
| 684 | 684 | $subscription = $invoice; |
| 685 | - $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) ); |
|
| 685 | + $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id']))); |
|
| 686 | 686 | // No subscription found with a matching payment ID, bail |
| 687 | 687 | //return false; |
| 688 | 688 | } |
@@ -692,39 +692,39 @@ discard block |
||
| 692 | 692 | |
| 693 | 693 | } |
| 694 | 694 | |
| 695 | -function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) { |
|
| 695 | +function wpinv_process_paypal_refund($data, $invoice_id = 0) { |
|
| 696 | 696 | // Collect payment details |
| 697 | 697 | |
| 698 | - if( empty( $invoice_id ) ) { |
|
| 698 | + if (empty($invoice_id)) { |
|
| 699 | 699 | return; |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) { |
|
| 702 | + if (get_post_status($invoice_id) == 'wpi-refunded') { |
|
| 703 | 703 | return; // Only refund payments once |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | - $payment_amount = wpinv_payment_total( $invoice_id ); |
|
| 706 | + $payment_amount = wpinv_payment_total($invoice_id); |
|
| 707 | 707 | $refund_amount = $data['mc_gross'] * -1; |
| 708 | 708 | |
| 709 | - if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) { |
|
| 710 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) ); |
|
| 709 | + if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) { |
|
| 710 | + wpinv_insert_payment_note($invoice_id, sprintf(__('Partial PayPal refund processed: %s', 'invoicing'), $data['parent_txn_id'])); |
|
| 711 | 711 | return; // This is a partial refund |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) ); |
|
| 715 | - wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) ); |
|
| 716 | - wpinv_update_payment_status( $invoice_id, 'wpi-refunded' ); |
|
| 714 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code'])); |
|
| 715 | + wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id'])); |
|
| 716 | + wpinv_update_payment_status($invoice_id, 'wpi-refunded'); |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | -function wpinv_get_paypal_redirect( $ssl_check = false ) { |
|
| 720 | - if ( is_ssl() || ! $ssl_check ) { |
|
| 719 | +function wpinv_get_paypal_redirect($ssl_check = false) { |
|
| 720 | + if (is_ssl() || !$ssl_check) { |
|
| 721 | 721 | $protocol = 'https://'; |
| 722 | 722 | } else { |
| 723 | 723 | $protocol = 'http://'; |
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | // Check the current payment mode |
| 727 | - if ( wpinv_is_test_mode( 'paypal' ) ) { |
|
| 727 | + if (wpinv_is_test_mode('paypal')) { |
|
| 728 | 728 | // Test mode |
| 729 | 729 | $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr'; |
| 730 | 730 | } else { |
@@ -732,67 +732,67 @@ discard block |
||
| 732 | 732 | $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr'; |
| 733 | 733 | } |
| 734 | 734 | |
| 735 | - return apply_filters( 'wpinv_paypal_uri', $paypal_uri ); |
|
| 735 | + return apply_filters('wpinv_paypal_uri', $paypal_uri); |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | -function wpinv_paypal_success_page_content( $content ) { |
|
| 738 | +function wpinv_paypal_success_page_content($content) { |
|
| 739 | 739 | global $wpi_invoice; |
| 740 | 740 | |
| 741 | 741 | $session = wpinv_get_checkout_session(); |
| 742 | 742 | |
| 743 | - if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] ) ) { |
|
| 743 | + if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) { |
|
| 744 | 744 | return $content; |
| 745 | 745 | } |
| 746 | 746 | |
| 747 | - $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] ); |
|
| 747 | + $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']); |
|
| 748 | 748 | |
| 749 | - if ( empty( $invoice_id ) ) { |
|
| 749 | + if (empty($invoice_id)) { |
|
| 750 | 750 | return $content; |
| 751 | 751 | } |
| 752 | 752 | |
| 753 | - $wpi_invoice = wpinv_get_invoice( $invoice_id ); |
|
| 753 | + $wpi_invoice = wpinv_get_invoice($invoice_id); |
|
| 754 | 754 | |
| 755 | - if ( !empty( $wpi_invoice ) && 'wpi-pending' == $wpi_invoice->status ) { |
|
| 755 | + if (!empty($wpi_invoice) && 'wpi-pending' == $wpi_invoice->status) { |
|
| 756 | 756 | // Payment is still pending so show processing indicator to fix the Race Condition, issue # |
| 757 | 757 | ob_start(); |
| 758 | - wpinv_get_template_part( 'wpinv-payment-processing' ); |
|
| 758 | + wpinv_get_template_part('wpinv-payment-processing'); |
|
| 759 | 759 | $content = ob_get_clean(); |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | 762 | return $content; |
| 763 | 763 | } |
| 764 | -add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' ); |
|
| 764 | +add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content'); |
|
| 765 | 765 | |
| 766 | -function wpinv_paypal_get_transaction_id( $invoice_id ) { |
|
| 766 | +function wpinv_paypal_get_transaction_id($invoice_id) { |
|
| 767 | 767 | $transaction_id = ''; |
| 768 | - $notes = wpinv_get_invoice_notes( $invoice_id ); |
|
| 768 | + $notes = wpinv_get_invoice_notes($invoice_id); |
|
| 769 | 769 | |
| 770 | - foreach ( $notes as $note ) { |
|
| 771 | - if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) { |
|
| 770 | + foreach ($notes as $note) { |
|
| 771 | + if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) { |
|
| 772 | 772 | $transaction_id = $match[1]; |
| 773 | 773 | continue; |
| 774 | 774 | } |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | - return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id ); |
|
| 777 | + return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id); |
|
| 778 | 778 | } |
| 779 | -add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 ); |
|
| 779 | +add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1); |
|
| 780 | 780 | |
| 781 | -function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) { |
|
| 782 | - if ( $invoice->is_free_trial() || $transaction_id == $invoice_id ) { // Free trial does not have transaction at PayPal. |
|
| 781 | +function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) { |
|
| 782 | + if ($invoice->is_free_trial() || $transaction_id == $invoice_id) { // Free trial does not have transaction at PayPal. |
|
| 783 | 783 | $transaction_url = $invoice->get_view_url(); |
| 784 | 784 | } else { |
| 785 | - $sandbox = wpinv_is_test_mode( 'paypal' ) ? '.sandbox' : ''; |
|
| 785 | + $sandbox = wpinv_is_test_mode('paypal') ? '.sandbox' : ''; |
|
| 786 | 786 | $transaction_url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . $transaction_id; |
| 787 | 787 | } |
| 788 | 788 | |
| 789 | - $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>'; |
|
| 789 | + $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>'; |
|
| 790 | 790 | |
| 791 | - return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice ); |
|
| 791 | + return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice); |
|
| 792 | 792 | } |
| 793 | -add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 ); |
|
| 793 | +add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3); |
|
| 794 | 794 | |
| 795 | 795 | function wpinv_gateway_paypal_button_label($label) { |
| 796 | - return __( 'Proceed to PayPal', 'invoicing' ); |
|
| 796 | + return __('Proceed to PayPal', 'invoicing'); |
|
| 797 | 797 | } |
| 798 | -add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 ); |
|
| 799 | 798 | \ No newline at end of file |
| 799 | +add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1); |
|
| 800 | 800 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // Exit if accessed directly. |
| 3 | -if (!defined( 'ABSPATH' ) ) exit; |
|
| 3 | +if (!defined('ABSPATH')) exit; |
|
| 4 | 4 | |
| 5 | 5 | class WPInv_EUVat { |
| 6 | 6 | private static $is_ajax = false; |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | private static $instance = false; |
| 9 | 9 | |
| 10 | 10 | public static function get_instance() { |
| 11 | - if ( !self::$instance ) { |
|
| 11 | + if (!self::$instance) { |
|
| 12 | 12 | self::$instance = new self(); |
| 13 | 13 | self::$instance->actions(); |
| 14 | 14 | } |
@@ -17,132 +17,132 @@ discard block |
||
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | public function __construct() { |
| 20 | - self::$is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
| 20 | + self::$is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 21 | 21 | self::$default_country = wpinv_get_default_country(); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public static function actions() { |
| 25 | - if ( is_admin() ) { |
|
| 26 | - add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) ); |
|
| 27 | - add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); |
|
| 28 | - add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) ); |
|
| 29 | - add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) ); |
|
| 30 | - add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) ); |
|
| 31 | - add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
| 32 | - add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) ); |
|
| 33 | - add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
| 34 | - add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) ); |
|
| 35 | - add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
| 36 | - add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) ); |
|
| 37 | - add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
| 38 | - add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) ); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) ); |
|
| 42 | - add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 ); |
|
| 43 | - add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 ); |
|
| 44 | - add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
| 45 | - add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) ); |
|
| 46 | - add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
| 47 | - add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) ); |
|
| 48 | - add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 ); |
|
| 49 | - if ( wpinv_use_taxes() ) { |
|
| 50 | - add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) ); |
|
| 51 | - if ( self::allow_vat_rules() ) { |
|
| 52 | - add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 ); |
|
| 53 | - add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 ); |
|
| 25 | + if (is_admin()) { |
|
| 26 | + add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts')); |
|
| 27 | + add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); |
|
| 28 | + add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings')); |
|
| 29 | + add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings')); |
|
| 30 | + add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates')); |
|
| 31 | + add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
| 32 | + add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class')); |
|
| 33 | + add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
| 34 | + add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class')); |
|
| 35 | + add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
| 36 | + add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates')); |
|
| 37 | + add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
| 38 | + add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database')); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts')); |
|
| 42 | + add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10); |
|
| 43 | + add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10); |
|
| 44 | + add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
| 45 | + add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate')); |
|
| 46 | + add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
| 47 | + add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset')); |
|
| 48 | + add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1); |
|
| 49 | + if (wpinv_use_taxes()) { |
|
| 50 | + add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields')); |
|
| 51 | + if (self::allow_vat_rules()) { |
|
| 52 | + add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2); |
|
| 53 | + add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4); |
|
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - public static function get_eu_states( $sort = true ) { |
|
| 59 | - $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' ); |
|
| 60 | - if ( $sort ) { |
|
| 61 | - $sort = sort( $eu_states ); |
|
| 58 | + public static function get_eu_states($sort = true) { |
|
| 59 | + $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE'); |
|
| 60 | + if ($sort) { |
|
| 61 | + $sort = sort($eu_states); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort ); |
|
| 64 | + return apply_filters('wpinv_get_eu_states', $eu_states, $sort); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - public static function get_gst_countries( $sort = true ) { |
|
| 68 | - $gst_countries = array( 'AU', 'NZ', 'CA', 'CN' ); |
|
| 67 | + public static function get_gst_countries($sort = true) { |
|
| 68 | + $gst_countries = array('AU', 'NZ', 'CA', 'CN'); |
|
| 69 | 69 | |
| 70 | - if ( $sort ) { |
|
| 71 | - $sort = sort( $gst_countries ); |
|
| 70 | + if ($sort) { |
|
| 71 | + $sort = sort($gst_countries); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort ); |
|
| 74 | + return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public static function is_eu_state( $country_code ) { |
|
| 78 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false; |
|
| 77 | + public static function is_eu_state($country_code) { |
|
| 78 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false; |
|
| 79 | 79 | |
| 80 | - return apply_filters( 'wpinv_is_eu_state', $return, $country_code ); |
|
| 80 | + return apply_filters('wpinv_is_eu_state', $return, $country_code); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - public static function is_gst_country( $country_code ) { |
|
| 84 | - $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false; |
|
| 83 | + public static function is_gst_country($country_code) { |
|
| 84 | + $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false; |
|
| 85 | 85 | |
| 86 | - return apply_filters( 'wpinv_is_gst_country', $return, $country_code ); |
|
| 86 | + return apply_filters('wpinv_is_gst_country', $return, $country_code); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | public static function enqueue_vat_scripts() { |
| 90 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 90 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 91 | 91 | |
| 92 | - wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 93 | - wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 92 | + wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 93 | + wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 94 | 94 | |
| 95 | - $vat_name = self::get_vat_name(); |
|
| 95 | + $vat_name = self::get_vat_name(); |
|
| 96 | 96 | |
| 97 | 97 | $vars = array(); |
| 98 | 98 | $vars['UseTaxes'] = wpinv_use_taxes(); |
| 99 | 99 | $vars['EUStates'] = self::get_eu_states(); |
| 100 | - $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' ); |
|
| 101 | - $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
| 102 | - $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
| 103 | - $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name ); |
|
| 104 | - $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name ); |
|
| 105 | - $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name ); |
|
| 106 | - $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name ); |
|
| 107 | - $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' ); |
|
| 100 | + $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing'); |
|
| 101 | + $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing'); |
|
| 102 | + $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
| 103 | + $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name); |
|
| 104 | + $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name); |
|
| 105 | + $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name); |
|
| 106 | + $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name); |
|
| 107 | + $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing'); |
|
| 108 | 108 | $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false; |
| 109 | 109 | $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true; |
| 110 | - $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' ); |
|
| 111 | - $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' ); |
|
| 112 | - $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' ); |
|
| 113 | - $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' ); |
|
| 114 | - $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' ); |
|
| 115 | - $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' ); |
|
| 116 | - $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' ); |
|
| 117 | - $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' ); |
|
| 118 | - $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name ); |
|
| 119 | - $vars['VatReseting'] = __( 'Reseting...', 'invoicing' ); |
|
| 120 | - $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
| 121 | - $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
| 122 | - $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' ); |
|
| 110 | + $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing'); |
|
| 111 | + $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing'); |
|
| 112 | + $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing'); |
|
| 113 | + $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing'); |
|
| 114 | + $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing'); |
|
| 115 | + $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing'); |
|
| 116 | + $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing'); |
|
| 117 | + $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing'); |
|
| 118 | + $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name); |
|
| 119 | + $vars['VatReseting'] = __('Reseting...', 'invoicing'); |
|
| 120 | + $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
| 121 | + $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
| 122 | + $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing'); |
|
| 123 | 123 | $vars['isFront'] = is_admin() ? false : true; |
| 124 | - $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 124 | + $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
| 125 | 125 | $vars['baseCountry'] = wpinv_get_default_country(); |
| 126 | - $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false ); |
|
| 127 | - $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false; |
|
| 126 | + $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false); |
|
| 127 | + $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false; |
|
| 128 | 128 | |
| 129 | - wp_enqueue_script( 'wpinv-vat-validation-script' ); |
|
| 130 | - wp_enqueue_script( 'wpinv-vat-script' ); |
|
| 131 | - wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars ); |
|
| 129 | + wp_enqueue_script('wpinv-vat-validation-script'); |
|
| 130 | + wp_enqueue_script('wpinv-vat-script'); |
|
| 131 | + wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | public static function enqueue_admin_scripts() { |
| 135 | - if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) { |
|
| 135 | + if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) { |
|
| 136 | 136 | self::enqueue_vat_scripts(); |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - public static function section_vat_settings( $sections ) { |
|
| 141 | - if ( !empty( $sections ) ) { |
|
| 142 | - $sections['vat'] = __( 'EU VAT Settings', 'invoicing' ); |
|
| 140 | + public static function section_vat_settings($sections) { |
|
| 141 | + if (!empty($sections)) { |
|
| 142 | + $sections['vat'] = __('EU VAT Settings', 'invoicing'); |
|
| 143 | 143 | |
| 144 | - if ( self::allow_vat_classes() ) { |
|
| 145 | - $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' ); |
|
| 144 | + if (self::allow_vat_classes()) { |
|
| 145 | + $sections['vat_rates'] = __('EU VAT Rates', 'invoicing'); |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | return $sections; |
@@ -151,52 +151,52 @@ discard block |
||
| 151 | 151 | public static function vat_rates_settings() { |
| 152 | 152 | $vat_classes = self::get_rate_classes(); |
| 153 | 153 | $vat_rates = array(); |
| 154 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new'; |
|
| 155 | - $current_url = remove_query_arg( 'wpi_sub' ); |
|
| 154 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new'; |
|
| 155 | + $current_url = remove_query_arg('wpi_sub'); |
|
| 156 | 156 | |
| 157 | 157 | $vat_rates['vat_rates_header'] = array( |
| 158 | 158 | 'id' => 'vat_rates_header', |
| 159 | - 'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>', |
|
| 159 | + 'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>', |
|
| 160 | 160 | 'desc' => '', |
| 161 | 161 | 'type' => 'header', |
| 162 | 162 | 'size' => 'regular' |
| 163 | 163 | ); |
| 164 | 164 | $vat_rates['vat_rates_class'] = array( |
| 165 | 165 | 'id' => 'vat_rates_class', |
| 166 | - 'name' => __( 'Edit VAT Rates', 'invoicing' ), |
|
| 167 | - 'desc' => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ), |
|
| 166 | + 'name' => __('Edit VAT Rates', 'invoicing'), |
|
| 167 | + 'desc' => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'), |
|
| 168 | 168 | 'type' => 'select', |
| 169 | - 'options' => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ), |
|
| 169 | + 'options' => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))), |
|
| 170 | 170 | 'chosen' => true, |
| 171 | - 'placeholder' => __( 'Select a VAT Rate', 'invoicing' ), |
|
| 171 | + 'placeholder' => __('Select a VAT Rate', 'invoicing'), |
|
| 172 | 172 | 'selected' => $vat_class, |
| 173 | 173 | 'onchange' => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;', |
| 174 | 174 | ); |
| 175 | 175 | |
| 176 | - if ( $vat_class != '_standard' && $vat_class != '_new' ) { |
|
| 176 | + if ($vat_class != '_standard' && $vat_class != '_new') { |
|
| 177 | 177 | $vat_rates['vat_rate_delete'] = array( |
| 178 | 178 | 'id' => 'vat_rate_delete', |
| 179 | 179 | 'type' => 'vat_rate_delete', |
| 180 | 180 | ); |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if ( $vat_class == '_new' ) { |
|
| 183 | + if ($vat_class == '_new') { |
|
| 184 | 184 | $vat_rates['vat_rates_settings'] = array( |
| 185 | 185 | 'id' => 'vat_rates_settings', |
| 186 | - 'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>', |
|
| 186 | + 'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>', |
|
| 187 | 187 | 'type' => 'header', |
| 188 | 188 | ); |
| 189 | 189 | $vat_rates['vat_rate_name'] = array( |
| 190 | 190 | 'id' => 'vat_rate_name', |
| 191 | - 'name' => __( 'Name', 'invoicing' ), |
|
| 192 | - 'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ), |
|
| 191 | + 'name' => __('Name', 'invoicing'), |
|
| 192 | + 'desc' => __('A short name for the new VAT Rate class', 'invoicing'), |
|
| 193 | 193 | 'type' => 'text', |
| 194 | 194 | 'size' => 'regular', |
| 195 | 195 | ); |
| 196 | 196 | $vat_rates['vat_rate_desc'] = array( |
| 197 | 197 | 'id' => 'vat_rate_desc', |
| 198 | - 'name' => __( 'Description', 'invoicing' ), |
|
| 199 | - 'desc' => __( 'Manage VAT Rate class', 'invoicing' ), |
|
| 198 | + 'name' => __('Description', 'invoicing'), |
|
| 199 | + 'desc' => __('Manage VAT Rate class', 'invoicing'), |
|
| 200 | 200 | 'type' => 'text', |
| 201 | 201 | 'size' => 'regular', |
| 202 | 202 | ); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $vat_rates['vat_rates'] = array( |
| 209 | 209 | 'id' => 'vat_rates', |
| 210 | 210 | 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>', |
| 211 | - 'desc' => self::get_class_desc( $vat_class ), |
|
| 211 | + 'desc' => self::get_class_desc($vat_class), |
|
| 212 | 212 | 'type' => 'vat_rates', |
| 213 | 213 | ); |
| 214 | 214 | } |
@@ -216,12 +216,12 @@ discard block |
||
| 216 | 216 | return $vat_rates; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - public static function vat_settings( $settings ) { |
|
| 220 | - if ( !empty( $settings ) ) { |
|
| 219 | + public static function vat_settings($settings) { |
|
| 220 | + if (!empty($settings)) { |
|
| 221 | 221 | $vat_settings = array(); |
| 222 | 222 | $vat_settings['vat_company_title'] = array( |
| 223 | 223 | 'id' => 'vat_company_title', |
| 224 | - 'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>', |
|
| 224 | + 'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>', |
|
| 225 | 225 | 'desc' => '', |
| 226 | 226 | 'type' => 'header', |
| 227 | 227 | 'size' => 'regular' |
@@ -229,22 +229,22 @@ discard block |
||
| 229 | 229 | |
| 230 | 230 | $vat_settings['vat_company_name'] = array( |
| 231 | 231 | 'id' => 'vat_company_name', |
| 232 | - 'name' => __( 'Your Company Name', 'invoicing' ), |
|
| 233 | - 'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
| 232 | + 'name' => __('Your Company Name', 'invoicing'), |
|
| 233 | + 'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
| 234 | 234 | 'type' => 'text', |
| 235 | 235 | 'size' => 'regular', |
| 236 | 236 | ); |
| 237 | 237 | |
| 238 | 238 | $vat_settings['vat_number'] = array( |
| 239 | 239 | 'id' => 'vat_number', |
| 240 | - 'name' => __( 'Your VAT Number', 'invoicing' ), |
|
| 240 | + 'name' => __('Your VAT Number', 'invoicing'), |
|
| 241 | 241 | 'type' => 'vat_number', |
| 242 | 242 | 'size' => 'regular', |
| 243 | 243 | ); |
| 244 | 244 | |
| 245 | 245 | $vat_settings['vat_settings_title'] = array( |
| 246 | 246 | 'id' => 'vat_settings_title', |
| 247 | - 'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>', |
|
| 247 | + 'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>', |
|
| 248 | 248 | 'desc' => '', |
| 249 | 249 | 'type' => 'header', |
| 250 | 250 | 'size' => 'regular' |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | |
| 253 | 253 | $vat_settings['apply_vat_rules'] = array( |
| 254 | 254 | 'id' => 'apply_vat_rules', |
| 255 | - 'name' => __( 'Enable VAT Rules', 'invoicing' ), |
|
| 256 | - 'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>', |
|
| 255 | + 'name' => __('Enable VAT Rules', 'invoicing'), |
|
| 256 | + 'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>', |
|
| 257 | 257 | 'type' => 'checkbox', |
| 258 | 258 | 'std' => '1' |
| 259 | 259 | ); |
@@ -269,8 +269,8 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | $vat_settings['vat_prevent_b2c_purchase'] = array( |
| 271 | 271 | 'id' => 'vat_prevent_b2c_purchase', |
| 272 | - 'name' => __( 'Prevent EU B2C Sales', 'invoicing' ), |
|
| 273 | - 'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ), |
|
| 272 | + 'name' => __('Prevent EU B2C Sales', 'invoicing'), |
|
| 273 | + 'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'), |
|
| 274 | 274 | 'type' => 'checkbox' |
| 275 | 275 | ); |
| 276 | 276 | |
@@ -278,21 +278,21 @@ discard block |
||
| 278 | 278 | |
| 279 | 279 | $vat_settings['vat_same_country_rule'] = array( |
| 280 | 280 | 'id' => 'vat_same_country_rule', |
| 281 | - 'name' => __( 'Same Country Rule', 'invoicing' ), |
|
| 282 | - 'desc' => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ), |
|
| 281 | + 'name' => __('Same Country Rule', 'invoicing'), |
|
| 282 | + 'desc' => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'), |
|
| 283 | 283 | 'type' => 'select', |
| 284 | 284 | 'options' => array( |
| 285 | - '' => __( 'Normal', 'invoicing' ), |
|
| 286 | - 'no' => __( 'No VAT', 'invoicing' ), |
|
| 287 | - 'always' => __( 'Always apply VAT', 'invoicing' ), |
|
| 285 | + '' => __('Normal', 'invoicing'), |
|
| 286 | + 'no' => __('No VAT', 'invoicing'), |
|
| 287 | + 'always' => __('Always apply VAT', 'invoicing'), |
|
| 288 | 288 | ), |
| 289 | - 'placeholder' => __( 'Select an option', 'invoicing' ), |
|
| 289 | + 'placeholder' => __('Select an option', 'invoicing'), |
|
| 290 | 290 | 'std' => '' |
| 291 | 291 | ); |
| 292 | 292 | |
| 293 | 293 | $vat_settings['vat_checkout_title'] = array( |
| 294 | 294 | 'id' => 'vat_checkout_title', |
| 295 | - 'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>', |
|
| 295 | + 'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>', |
|
| 296 | 296 | 'desc' => '', |
| 297 | 297 | 'type' => 'header', |
| 298 | 298 | 'size' => 'regular' |
@@ -300,14 +300,14 @@ discard block |
||
| 300 | 300 | |
| 301 | 301 | $vat_settings['vat_disable_fields'] = array( |
| 302 | 302 | 'id' => 'vat_disable_fields', |
| 303 | - 'name' => __( 'Disable VAT Fields', 'invoicing' ), |
|
| 304 | - 'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>', |
|
| 303 | + 'name' => __('Disable VAT Fields', 'invoicing'), |
|
| 304 | + 'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>', |
|
| 305 | 305 | 'type' => 'checkbox' |
| 306 | 306 | ); |
| 307 | 307 | |
| 308 | 308 | $vat_settings['vat_ip_lookup'] = array( |
| 309 | 309 | 'id' => 'vat_ip_lookup', |
| 310 | - 'name' => __( 'IP Country Look-up', 'invoicing' ), |
|
| 310 | + 'name' => __('IP Country Look-up', 'invoicing'), |
|
| 311 | 311 | 'type' => 'vat_ip_lookup', |
| 312 | 312 | 'size' => 'regular', |
| 313 | 313 | 'std' => 'default' |
@@ -315,21 +315,21 @@ discard block |
||
| 315 | 315 | |
| 316 | 316 | $vat_settings['hide_ip_address'] = array( |
| 317 | 317 | 'id' => 'hide_ip_address', |
| 318 | - 'name' => __( 'Hide IP Info at Checkout', 'invoicing' ), |
|
| 319 | - 'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ), |
|
| 318 | + 'name' => __('Hide IP Info at Checkout', 'invoicing'), |
|
| 319 | + 'desc' => __('Hide the user IP info at checkout.', 'invoicing'), |
|
| 320 | 320 | 'type' => 'checkbox' |
| 321 | 321 | ); |
| 322 | 322 | |
| 323 | 323 | $vat_settings['vat_ip_country_default'] = array( |
| 324 | 324 | 'id' => 'vat_ip_country_default', |
| 325 | - 'name' => __( 'Enable IP Country as Default', 'invoicing' ), |
|
| 326 | - 'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ), |
|
| 325 | + 'name' => __('Enable IP Country as Default', 'invoicing'), |
|
| 326 | + 'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'), |
|
| 327 | 327 | 'type' => 'checkbox' |
| 328 | 328 | ); |
| 329 | 329 | |
| 330 | 330 | $vat_settings['vies_validation_title'] = array( |
| 331 | 331 | 'id' => 'vies_validation_title', |
| 332 | - 'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>', |
|
| 332 | + 'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>', |
|
| 333 | 333 | 'desc' => '', |
| 334 | 334 | 'type' => 'header', |
| 335 | 335 | 'size' => 'regular' |
@@ -337,37 +337,37 @@ discard block |
||
| 337 | 337 | |
| 338 | 338 | $vat_settings['vat_vies_check'] = array( |
| 339 | 339 | 'id' => 'vat_vies_check', |
| 340 | - 'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ), |
|
| 341 | - 'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
| 340 | + 'name' => __('Disable VIES VAT ID Check', 'invoicing'), |
|
| 341 | + 'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
| 342 | 342 | 'type' => 'checkbox' |
| 343 | 343 | ); |
| 344 | 344 | |
| 345 | 345 | $vat_settings['vat_disable_company_name_check'] = array( |
| 346 | 346 | 'id' => 'vat_disable_company_name_check', |
| 347 | - 'name' => __( 'Disable VIES Name Check', 'invoicing' ), |
|
| 348 | - 'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ), |
|
| 347 | + 'name' => __('Disable VIES Name Check', 'invoicing'), |
|
| 348 | + 'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'), |
|
| 349 | 349 | 'type' => 'checkbox' |
| 350 | 350 | ); |
| 351 | 351 | |
| 352 | 352 | $vat_settings['vat_offline_check'] = array( |
| 353 | 353 | 'id' => 'vat_offline_check', |
| 354 | - 'name' => __( 'Disable Basic Checks', 'invoicing' ), |
|
| 355 | - 'desc' => __( 'This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing' ), |
|
| 354 | + 'name' => __('Disable Basic Checks', 'invoicing'), |
|
| 355 | + 'desc' => __('This will disable basic JS correct format validation attempts, it is very rare this should need to be disabled.', 'invoicing'), |
|
| 356 | 356 | 'type' => 'checkbox' |
| 357 | 357 | ); |
| 358 | 358 | |
| 359 | 359 | |
| 360 | 360 | $settings['vat'] = $vat_settings; |
| 361 | 361 | |
| 362 | - if ( self::allow_vat_classes() ) { |
|
| 362 | + if (self::allow_vat_classes()) { |
|
| 363 | 363 | $settings['vat_rates'] = self::vat_rates_settings(); |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | $eu_fallback_rate = array( |
| 367 | 367 | 'id' => 'eu_fallback_rate', |
| 368 | - 'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>', |
|
| 368 | + 'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>', |
|
| 369 | 369 | 'type' => 'eu_fallback_rate', |
| 370 | - 'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ), |
|
| 370 | + 'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'), |
|
| 371 | 371 | 'std' => '20', |
| 372 | 372 | 'size' => 'small' |
| 373 | 373 | ); |
@@ -383,11 +383,11 @@ discard block |
||
| 383 | 383 | $database_url = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/'; |
| 384 | 384 | $destination_dir = $upload_dir['basedir'] . '/invoicing'; |
| 385 | 385 | |
| 386 | - if ( !is_dir( $destination_dir ) ) { |
|
| 387 | - mkdir( $destination_dir ); |
|
| 386 | + if (!is_dir($destination_dir)) { |
|
| 387 | + mkdir($destination_dir); |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | - $database_files = array( |
|
| 390 | + $database_files = array( |
|
| 391 | 391 | 'country' => array( |
| 392 | 392 | 'source' => $database_url . 'GeoLite2-Country.mmdb.gz', |
| 393 | 393 | 'destination' => $destination_dir . '/GeoLite2-Country.mmdb', |
@@ -398,57 +398,57 @@ discard block |
||
| 398 | 398 | ) |
| 399 | 399 | ); |
| 400 | 400 | |
| 401 | - foreach( $database_files as $database => $files ) { |
|
| 402 | - $result = self::geoip2_download_file( $files['source'], $files['destination'] ); |
|
| 401 | + foreach ($database_files as $database => $files) { |
|
| 402 | + $result = self::geoip2_download_file($files['source'], $files['destination']); |
|
| 403 | 403 | |
| 404 | - if ( empty( $result['success'] ) ) { |
|
| 404 | + if (empty($result['success'])) { |
|
| 405 | 405 | echo $result['message']; |
| 406 | 406 | exit; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) ); |
|
| 410 | - echo sprintf(__( 'GeoIp2 %s database updated successfully.', 'invoicing' ), $database ) . ' '; |
|
| 409 | + wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp')); |
|
| 410 | + echo sprintf(__('GeoIp2 %s database updated successfully.', 'invoicing'), $database) . ' '; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | exit; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | - public static function geoip2_download_file( $source_url, $destination_file ) { |
|
| 416 | + public static function geoip2_download_file($source_url, $destination_file) { |
|
| 417 | 417 | $success = false; |
| 418 | 418 | $message = ''; |
| 419 | 419 | |
| 420 | - if ( !function_exists( 'download_url' ) ) { |
|
| 421 | - require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
|
| 420 | + if (!function_exists('download_url')) { |
|
| 421 | + require_once(ABSPATH . 'wp-admin/includes/file.php'); |
|
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - $temp_file = download_url( $source_url ); |
|
| 424 | + $temp_file = download_url($source_url); |
|
| 425 | 425 | |
| 426 | - if ( is_wp_error( $temp_file ) ) { |
|
| 427 | - $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() ); |
|
| 426 | + if (is_wp_error($temp_file)) { |
|
| 427 | + $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message()); |
|
| 428 | 428 | } else { |
| 429 | - $handle = gzopen( $temp_file, 'rb' ); |
|
| 429 | + $handle = gzopen($temp_file, 'rb'); |
|
| 430 | 430 | |
| 431 | - if ( $handle ) { |
|
| 432 | - $fopen = fopen( $destination_file, 'wb' ); |
|
| 433 | - if ( $fopen ) { |
|
| 434 | - while ( ( $data = gzread( $handle, 4096 ) ) != false ) { |
|
| 435 | - fwrite( $fopen, $data ); |
|
| 431 | + if ($handle) { |
|
| 432 | + $fopen = fopen($destination_file, 'wb'); |
|
| 433 | + if ($fopen) { |
|
| 434 | + while (($data = gzread($handle, 4096)) != false) { |
|
| 435 | + fwrite($fopen, $data); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - gzclose( $handle ); |
|
| 439 | - fclose( $fopen ); |
|
| 438 | + gzclose($handle); |
|
| 439 | + fclose($fopen); |
|
| 440 | 440 | |
| 441 | 441 | $success = true; |
| 442 | 442 | } else { |
| 443 | - gzclose( $handle ); |
|
| 444 | - $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file ); |
|
| 443 | + gzclose($handle); |
|
| 444 | + $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file); |
|
| 445 | 445 | } |
| 446 | 446 | } else { |
| 447 | - $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file ); |
|
| 447 | + $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | - if ( file_exists( $temp_file ) ) { |
|
| 451 | - unlink( $temp_file ); |
|
| 450 | + if (file_exists($temp_file)) { |
|
| 451 | + unlink($temp_file); |
|
| 452 | 452 | } |
| 453 | 453 | } |
| 454 | 454 | |
@@ -460,11 +460,11 @@ discard block |
||
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | public static function load_geoip2() { |
| 463 | - if ( defined( 'WPINV_GEOIP2_LODDED' ) ) { |
|
| 463 | + if (defined('WPINV_GEOIP2_LODDED')) { |
|
| 464 | 464 | return; |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | - if ( !class_exists( '\MaxMind\Db\Reader' ) ) { |
|
| 467 | + if (!class_exists('\MaxMind\Db\Reader')) { |
|
| 468 | 468 | $maxmind_db_files = array( |
| 469 | 469 | 'Reader/Decoder.php', |
| 470 | 470 | 'Reader/InvalidDatabaseException.php', |
@@ -473,12 +473,12 @@ discard block |
||
| 473 | 473 | 'Reader.php', |
| 474 | 474 | ); |
| 475 | 475 | |
| 476 | - foreach ( $maxmind_db_files as $key => $file ) { |
|
| 477 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file ); |
|
| 476 | + foreach ($maxmind_db_files as $key => $file) { |
|
| 477 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file); |
|
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - if ( !class_exists( '\GeoIp2\Database\Reader' ) ) { |
|
| 481 | + if (!class_exists('\GeoIp2\Database\Reader')) { |
|
| 482 | 482 | $geoip2_files = array( |
| 483 | 483 | 'ProviderInterface.php', |
| 484 | 484 | 'Compat/JsonSerializable.php', |
@@ -512,23 +512,23 @@ discard block |
||
| 512 | 512 | 'WebService/Client.php', |
| 513 | 513 | ); |
| 514 | 514 | |
| 515 | - foreach ( $geoip2_files as $key => $file ) { |
|
| 516 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file ); |
|
| 515 | + foreach ($geoip2_files as $key => $file) { |
|
| 516 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file); |
|
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | - define( 'WPINV_GEOIP2_LODDED', true ); |
|
| 520 | + define('WPINV_GEOIP2_LODDED', true); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | public static function geoip2_country_dbfile() { |
| 524 | 524 | $upload_dir = wp_upload_dir(); |
| 525 | 525 | |
| 526 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
| 526 | + if (!isset($upload_dir['basedir'])) { |
|
| 527 | 527 | return false; |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb'; |
| 531 | - if ( !file_exists( $filename ) ) { |
|
| 531 | + if (!file_exists($filename)) { |
|
| 532 | 532 | return false; |
| 533 | 533 | } |
| 534 | 534 | |
@@ -538,12 +538,12 @@ discard block |
||
| 538 | 538 | public static function geoip2_city_dbfile() { |
| 539 | 539 | $upload_dir = wp_upload_dir(); |
| 540 | 540 | |
| 541 | - if ( !isset( $upload_dir['basedir'] ) ) { |
|
| 541 | + if (!isset($upload_dir['basedir'])) { |
|
| 542 | 542 | return false; |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb'; |
| 546 | - if ( !file_exists( $filename ) ) { |
|
| 546 | + if (!file_exists($filename)) { |
|
| 547 | 547 | return false; |
| 548 | 548 | } |
| 549 | 549 | |
@@ -554,10 +554,10 @@ discard block |
||
| 554 | 554 | try { |
| 555 | 555 | self::load_geoip2(); |
| 556 | 556 | |
| 557 | - if ( $filename = self::geoip2_country_dbfile() ) { |
|
| 558 | - return new \GeoIp2\Database\Reader( $filename ); |
|
| 557 | + if ($filename = self::geoip2_country_dbfile()) { |
|
| 558 | + return new \GeoIp2\Database\Reader($filename); |
|
| 559 | 559 | } |
| 560 | - } catch( Exception $e ) { |
|
| 560 | + } catch (Exception $e) { |
|
| 561 | 561 | return false; |
| 562 | 562 | } |
| 563 | 563 | |
@@ -568,173 +568,173 @@ discard block |
||
| 568 | 568 | try { |
| 569 | 569 | self::load_geoip2(); |
| 570 | 570 | |
| 571 | - if ( $filename = self::geoip2_city_dbfile() ) { |
|
| 572 | - return new \GeoIp2\Database\Reader( $filename ); |
|
| 571 | + if ($filename = self::geoip2_city_dbfile()) { |
|
| 572 | + return new \GeoIp2\Database\Reader($filename); |
|
| 573 | 573 | } |
| 574 | - } catch( Exception $e ) { |
|
| 574 | + } catch (Exception $e) { |
|
| 575 | 575 | return false; |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | return false; |
| 579 | 579 | } |
| 580 | 580 | |
| 581 | - public static function geoip2_country_record( $ip_address ) { |
|
| 581 | + public static function geoip2_country_record($ip_address) { |
|
| 582 | 582 | try { |
| 583 | 583 | $reader = self::geoip2_country_reader(); |
| 584 | 584 | |
| 585 | - if ( $reader ) { |
|
| 586 | - $record = $reader->country( $ip_address ); |
|
| 585 | + if ($reader) { |
|
| 586 | + $record = $reader->country($ip_address); |
|
| 587 | 587 | |
| 588 | - if ( !empty( $record->country->isoCode ) ) { |
|
| 588 | + if (!empty($record->country->isoCode)) { |
|
| 589 | 589 | return $record; |
| 590 | 590 | } |
| 591 | 591 | } |
| 592 | - } catch(\InvalidArgumentException $e) { |
|
| 593 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 592 | + } catch (\InvalidArgumentException $e) { |
|
| 593 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 594 | 594 | |
| 595 | 595 | return false; |
| 596 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 597 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 596 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 597 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 598 | 598 | |
| 599 | 599 | return false; |
| 600 | - } catch( Exception $e ) { |
|
| 600 | + } catch (Exception $e) { |
|
| 601 | 601 | return false; |
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | return false; |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | - public static function geoip2_city_record( $ip_address ) { |
|
| 607 | + public static function geoip2_city_record($ip_address) { |
|
| 608 | 608 | try { |
| 609 | 609 | $reader = self::geoip2_city_reader(); |
| 610 | 610 | |
| 611 | - if ( $reader ) { |
|
| 612 | - $record = $reader->city( $ip_address ); |
|
| 611 | + if ($reader) { |
|
| 612 | + $record = $reader->city($ip_address); |
|
| 613 | 613 | |
| 614 | - if ( !empty( $record->country->isoCode ) ) { |
|
| 614 | + if (!empty($record->country->isoCode)) { |
|
| 615 | 615 | return $record; |
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | - } catch(\InvalidArgumentException $e) { |
|
| 619 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 618 | + } catch (\InvalidArgumentException $e) { |
|
| 619 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 620 | 620 | |
| 621 | 621 | return false; |
| 622 | - } catch(\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 623 | - wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' ); |
|
| 622 | + } catch (\GeoIp2\Exception\AddressNotFoundException $e) { |
|
| 623 | + wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )'); |
|
| 624 | 624 | |
| 625 | 625 | return false; |
| 626 | - } catch( Exception $e ) { |
|
| 626 | + } catch (Exception $e) { |
|
| 627 | 627 | return false; |
| 628 | 628 | } |
| 629 | 629 | |
| 630 | 630 | return false; |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | - public static function geoip2_country_code( $ip_address ) { |
|
| 634 | - $record = self::geoip2_country_record( $ip_address ); |
|
| 635 | - return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country(); |
|
| 633 | + public static function geoip2_country_code($ip_address) { |
|
| 634 | + $record = self::geoip2_country_record($ip_address); |
|
| 635 | + return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country(); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | // Find country by IP address. |
| 639 | - public static function get_country_by_ip( $ip = '' ) { |
|
| 639 | + public static function get_country_by_ip($ip = '') { |
|
| 640 | 640 | global $wpinv_ip_address_country; |
| 641 | 641 | |
| 642 | - if ( !empty( $wpinv_ip_address_country ) ) { |
|
| 642 | + if (!empty($wpinv_ip_address_country)) { |
|
| 643 | 643 | return $wpinv_ip_address_country; |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | - if ( empty( $ip ) ) { |
|
| 646 | + if (empty($ip)) { |
|
| 647 | 647 | $ip = wpinv_get_ip(); |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | - $ip_country_service = wpinv_get_option( 'vat_ip_lookup' ); |
|
| 651 | - $is_default = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false; |
|
| 650 | + $ip_country_service = wpinv_get_option('vat_ip_lookup'); |
|
| 651 | + $is_default = empty($ip_country_service) || $ip_country_service === 'default' ? true : false; |
|
| 652 | 652 | |
| 653 | - if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country. |
|
| 654 | - if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) { |
|
| 653 | + if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country. |
|
| 654 | + if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) { |
|
| 655 | 655 | try { |
| 656 | - $wpinv_ip_address_country = geoip_country_code_by_name( $ip ); |
|
| 657 | - } catch( Exception $e ) { |
|
| 658 | - wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' ); |
|
| 656 | + $wpinv_ip_address_country = geoip_country_code_by_name($ip); |
|
| 657 | + } catch (Exception $e) { |
|
| 658 | + wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )'); |
|
| 659 | 659 | } |
| 660 | - } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) { |
|
| 661 | - $wpinv_ip_address_country = self::geoip2_country_code( $ip ); |
|
| 662 | - } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) { |
|
| 663 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
| 660 | + } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) { |
|
| 661 | + $wpinv_ip_address_country = self::geoip2_country_code($ip); |
|
| 662 | + } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) { |
|
| 663 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
| 664 | 664 | |
| 665 | - if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) { |
|
| 665 | + if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) { |
|
| 666 | 666 | $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode; |
| 667 | 667 | } |
| 668 | 668 | } |
| 669 | 669 | } |
| 670 | 670 | |
| 671 | - if ( empty( $wpinv_ip_address_country ) ) { |
|
| 671 | + if (empty($wpinv_ip_address_country)) { |
|
| 672 | 672 | $wpinv_ip_address_country = wpinv_get_default_country(); |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | return $wpinv_ip_address_country; |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | - public static function sanitize_vat_settings( $input ) { |
|
| 678 | + public static function sanitize_vat_settings($input) { |
|
| 679 | 679 | global $wpinv_options; |
| 680 | 680 | |
| 681 | 681 | $valid = false; |
| 682 | 682 | $message = ''; |
| 683 | 683 | |
| 684 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
| 685 | - if ( empty( $wpinv_options['vat_offline_check'] ) ) { |
|
| 686 | - $valid = self::offline_check( $input['vat_number'] ); |
|
| 684 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
| 685 | + if (empty($wpinv_options['vat_offline_check'])) { |
|
| 686 | + $valid = self::offline_check($input['vat_number']); |
|
| 687 | 687 | } else { |
| 688 | 688 | $valid = true; |
| 689 | 689 | } |
| 690 | 690 | |
| 691 | - $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' ); |
|
| 691 | + $message = $valid ? '' : __('VAT number not validated', 'invoicing'); |
|
| 692 | 692 | } else { |
| 693 | - $result = self::check_vat( $input['vat_number'] ); |
|
| 693 | + $result = self::check_vat($input['vat_number']); |
|
| 694 | 694 | |
| 695 | - if ( empty( $result['valid'] ) ) { |
|
| 695 | + if (empty($result['valid'])) { |
|
| 696 | 696 | $valid = false; |
| 697 | 697 | $message = $result['message']; |
| 698 | 698 | } else { |
| 699 | - $valid = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] ); |
|
| 700 | - $message = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' ); |
|
| 699 | + $valid = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']); |
|
| 700 | + $message = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing'); |
|
| 701 | 701 | } |
| 702 | 702 | } |
| 703 | 703 | |
| 704 | - if ( $message && self::is_vat_validated() != $valid ) { |
|
| 705 | - add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) ); |
|
| 704 | + if ($message && self::is_vat_validated() != $valid) { |
|
| 705 | + add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error')); |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | $input['vat_valid'] = $valid; |
| 709 | 709 | return $input; |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | - public static function sanitize_vat_rates( $input ) { |
|
| 713 | - if( !current_user_can( 'manage_options' ) ) { |
|
| 714 | - add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' ); |
|
| 712 | + public static function sanitize_vat_rates($input) { |
|
| 713 | + if (!current_user_can('manage_options')) { |
|
| 714 | + add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error'); |
|
| 715 | 715 | return $input; |
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | $vat_classes = self::get_rate_classes(); |
| 719 | - $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : ''; |
|
| 719 | + $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : ''; |
|
| 720 | 720 | |
| 721 | - if ( empty( $vat_class ) ) { |
|
| 722 | - add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' ); |
|
| 721 | + if (empty($vat_class)) { |
|
| 722 | + add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error'); |
|
| 723 | 723 | |
| 724 | 724 | return $input; |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | - $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array(); |
|
| 727 | + $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array(); |
|
| 728 | 728 | |
| 729 | - if ( $vat_class === '_standard' ) { |
|
| 729 | + if ($vat_class === '_standard') { |
|
| 730 | 730 | // Save the active rates in the invoice settings |
| 731 | - update_option( 'wpinv_tax_rates', $new_rates ); |
|
| 731 | + update_option('wpinv_tax_rates', $new_rates); |
|
| 732 | 732 | } else { |
| 733 | 733 | // Get the existing set of rates |
| 734 | 734 | $rates = self::get_non_standard_rates(); |
| 735 | 735 | $rates[$vat_class] = $new_rates; |
| 736 | 736 | |
| 737 | - update_option( 'wpinv_vat_rates', $rates ); |
|
| 737 | + update_option('wpinv_vat_rates', $rates); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | return $input; |
@@ -744,71 +744,71 @@ discard block |
||
| 744 | 744 | $response = array(); |
| 745 | 745 | $response['success'] = false; |
| 746 | 746 | |
| 747 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 748 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
| 749 | - wp_send_json( $response ); |
|
| 747 | + if (!current_user_can('manage_options')) { |
|
| 748 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
| 749 | + wp_send_json($response); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | - $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false; |
|
| 753 | - $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false; |
|
| 752 | + $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false; |
|
| 753 | + $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false; |
|
| 754 | 754 | |
| 755 | - if ( empty( $vat_class_name ) ) { |
|
| 756 | - $response['error'] = __( 'Select the VAT rate name', 'invoicing' ); |
|
| 757 | - wp_send_json( $response ); |
|
| 755 | + if (empty($vat_class_name)) { |
|
| 756 | + $response['error'] = __('Select the VAT rate name', 'invoicing'); |
|
| 757 | + wp_send_json($response); |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | $vat_classes = (array)self::get_rate_classes(); |
| 761 | 761 | |
| 762 | - if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) { |
|
| 763 | - $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name ); |
|
| 764 | - wp_send_json( $response ); |
|
| 762 | + if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) { |
|
| 763 | + $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name); |
|
| 764 | + wp_send_json($response); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | - $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name ); |
|
| 768 | - $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) ); |
|
| 767 | + $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name); |
|
| 768 | + $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key)); |
|
| 769 | 769 | |
| 770 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
| 771 | - $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc ); |
|
| 770 | + $vat_classes = (array)self::get_rate_classes(true); |
|
| 771 | + $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc); |
|
| 772 | 772 | |
| 773 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
| 773 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
| 774 | 774 | |
| 775 | 775 | $response['success'] = true; |
| 776 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key ); |
|
| 776 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=' . $rate_class_key); |
|
| 777 | 777 | |
| 778 | - wp_send_json( $response ); |
|
| 778 | + wp_send_json($response); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | public static function delete_class() { |
| 782 | 782 | $response = array(); |
| 783 | 783 | $response['success'] = false; |
| 784 | 784 | |
| 785 | - if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) { |
|
| 786 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
| 787 | - wp_send_json( $response ); |
|
| 785 | + if (!current_user_can('manage_options') || !isset($_POST['class'])) { |
|
| 786 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
| 787 | + wp_send_json($response); |
|
| 788 | 788 | } |
| 789 | 789 | |
| 790 | - $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false; |
|
| 790 | + $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false; |
|
| 791 | 791 | $vat_classes = (array)self::get_rate_classes(); |
| 792 | 792 | |
| 793 | - if ( !isset( $vat_classes[$vat_class] ) ) { |
|
| 794 | - $response['error'] = __( 'Requested class does not exists', 'invoicing' ); |
|
| 795 | - wp_send_json( $response ); |
|
| 793 | + if (!isset($vat_classes[$vat_class])) { |
|
| 794 | + $response['error'] = __('Requested class does not exists', 'invoicing'); |
|
| 795 | + wp_send_json($response); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | - if ( $vat_class == '_new' || $vat_class == '_standard' ) { |
|
| 799 | - $response['error'] = __( 'You can not delete standard rates class', 'invoicing' ); |
|
| 800 | - wp_send_json( $response ); |
|
| 798 | + if ($vat_class == '_new' || $vat_class == '_standard') { |
|
| 799 | + $response['error'] = __('You can not delete standard rates class', 'invoicing'); |
|
| 800 | + wp_send_json($response); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | - $vat_classes = (array)self::get_rate_classes( true ); |
|
| 804 | - unset( $vat_classes[$vat_class] ); |
|
| 803 | + $vat_classes = (array)self::get_rate_classes(true); |
|
| 804 | + unset($vat_classes[$vat_class]); |
|
| 805 | 805 | |
| 806 | - update_option( '_wpinv_vat_rate_classes', $vat_classes ); |
|
| 806 | + update_option('_wpinv_vat_rate_classes', $vat_classes); |
|
| 807 | 807 | |
| 808 | 808 | $response['success'] = true; |
| 809 | - $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new' ); |
|
| 809 | + $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes§ion=vat_rates&wpi_sub=_new'); |
|
| 810 | 810 | |
| 811 | - wp_send_json( $response ); |
|
| 811 | + wp_send_json($response); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | public static function update_eu_rates() { |
@@ -817,72 +817,72 @@ discard block |
||
| 817 | 817 | $response['error'] = null; |
| 818 | 818 | $response['data'] = null; |
| 819 | 819 | |
| 820 | - if ( !current_user_can( 'manage_options' ) ) { |
|
| 821 | - $response['error'] = __( 'Invalid access!', 'invoicing' ); |
|
| 822 | - wp_send_json( $response ); |
|
| 820 | + if (!current_user_can('manage_options')) { |
|
| 821 | + $response['error'] = __('Invalid access!', 'invoicing'); |
|
| 822 | + wp_send_json($response); |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | - $group = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : ''; |
|
| 826 | - $euvatrates = self::request_euvatrates( $group ); |
|
| 825 | + $group = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : ''; |
|
| 826 | + $euvatrates = self::request_euvatrates($group); |
|
| 827 | 827 | |
| 828 | - if ( !empty( $euvatrates ) ) { |
|
| 829 | - if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) { |
|
| 828 | + if (!empty($euvatrates)) { |
|
| 829 | + if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) { |
|
| 830 | 830 | $response['success'] = true; |
| 831 | 831 | $response['data']['rates'] = $euvatrates['rates']; |
| 832 | - } else if ( !empty( $euvatrates['error'] ) ) { |
|
| 832 | + } else if (!empty($euvatrates['error'])) { |
|
| 833 | 833 | $response['error'] = $euvatrates['error']; |
| 834 | 834 | } |
| 835 | 835 | } |
| 836 | 836 | |
| 837 | - wp_send_json( $response ); |
|
| 837 | + wp_send_json($response); |
|
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | public static function hide_vat_fields() { |
| 841 | - $hide = wpinv_get_option( 'vat_disable_fields' ); |
|
| 841 | + $hide = wpinv_get_option('vat_disable_fields'); |
|
| 842 | 842 | |
| 843 | - return apply_filters( 'wpinv_hide_vat_fields', $hide ); |
|
| 843 | + return apply_filters('wpinv_hide_vat_fields', $hide); |
|
| 844 | 844 | } |
| 845 | 845 | |
| 846 | 846 | public static function same_country_rule() { |
| 847 | - $same_country_rule = wpinv_get_option( 'vat_same_country_rule' ); |
|
| 847 | + $same_country_rule = wpinv_get_option('vat_same_country_rule'); |
|
| 848 | 848 | |
| 849 | - return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule ); |
|
| 849 | + return apply_filters('wpinv_vat_same_country_rule', $same_country_rule); |
|
| 850 | 850 | } |
| 851 | 851 | |
| 852 | 852 | public static function get_vat_name() { |
| 853 | - $vat_name = wpinv_get_option( 'vat_name' ); |
|
| 854 | - $vat_name = !empty( $vat_name ) ? $vat_name : 'VAT'; |
|
| 853 | + $vat_name = wpinv_get_option('vat_name'); |
|
| 854 | + $vat_name = !empty($vat_name) ? $vat_name : 'VAT'; |
|
| 855 | 855 | |
| 856 | - return apply_filters( 'wpinv_get_owner_vat_name', $vat_name ); |
|
| 856 | + return apply_filters('wpinv_get_owner_vat_name', $vat_name); |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | public static function get_company_name() { |
| 860 | - $company_name = wpinv_get_option( 'vat_company_name' ); |
|
| 860 | + $company_name = wpinv_get_option('vat_company_name'); |
|
| 861 | 861 | |
| 862 | - return apply_filters( 'wpinv_get_owner_company_name', $company_name ); |
|
| 862 | + return apply_filters('wpinv_get_owner_company_name', $company_name); |
|
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | public static function get_vat_number() { |
| 866 | - $vat_number = wpinv_get_option( 'vat_number' ); |
|
| 866 | + $vat_number = wpinv_get_option('vat_number'); |
|
| 867 | 867 | |
| 868 | - return apply_filters( 'wpinv_get_owner_vat_number', $vat_number ); |
|
| 868 | + return apply_filters('wpinv_get_owner_vat_number', $vat_number); |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | public static function is_vat_validated() { |
| 872 | - $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' ); |
|
| 872 | + $validated = self::get_vat_number() && wpinv_get_option('vat_valid'); |
|
| 873 | 873 | |
| 874 | - return apply_filters( 'wpinv_is_owner_vat_validated', $validated ); |
|
| 874 | + return apply_filters('wpinv_is_owner_vat_validated', $validated); |
|
| 875 | 875 | } |
| 876 | 876 | |
| 877 | - public static function sanitize_vat( $vat_number, $country_code = '' ) { |
|
| 878 | - $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) ); |
|
| 877 | + public static function sanitize_vat($vat_number, $country_code = '') { |
|
| 878 | + $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number))); |
|
| 879 | 879 | |
| 880 | - if ( empty( $country_code ) ) { |
|
| 881 | - $country_code = substr( $vat_number, 0, 2 ); |
|
| 880 | + if (empty($country_code)) { |
|
| 881 | + $country_code = substr($vat_number, 0, 2); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - if ( strpos( $vat_number , $country_code ) === 0 ) { |
|
| 885 | - $vat = str_replace( $country_code, '', $vat_number ); |
|
| 884 | + if (strpos($vat_number, $country_code) === 0) { |
|
| 885 | + $vat = str_replace($country_code, '', $vat_number); |
|
| 886 | 886 | } else { |
| 887 | 887 | $vat = $country_code . $vat_number; |
| 888 | 888 | } |
@@ -895,140 +895,140 @@ discard block |
||
| 895 | 895 | return $return; |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | - public static function offline_check( $vat_number, $country_code = '', $formatted = false ) { |
|
| 899 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
| 898 | + public static function offline_check($vat_number, $country_code = '', $formatted = false) { |
|
| 899 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
| 900 | 900 | $vat_number = $vat['vat_number']; |
| 901 | 901 | $country_code = $vat['iso']; |
| 902 | 902 | $regex = array(); |
| 903 | 903 | |
| 904 | - switch ( $country_code ) { |
|
| 904 | + switch ($country_code) { |
|
| 905 | 905 | case 'AT': |
| 906 | - $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
| 906 | + $regex[] = '/^(AT)U(\d{8})$/'; // Austria |
|
| 907 | 907 | break; |
| 908 | 908 | case 'BE': |
| 909 | - $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
| 909 | + $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium |
|
| 910 | 910 | break; |
| 911 | 911 | case 'BG': |
| 912 | - $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
| 912 | + $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria |
|
| 913 | 913 | break; |
| 914 | 914 | case 'CH': |
| 915 | 915 | case 'CHE': |
| 916 | - $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
| 916 | + $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU) |
|
| 917 | 917 | break; |
| 918 | 918 | case 'CY': |
| 919 | - $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
| 919 | + $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus |
|
| 920 | 920 | break; |
| 921 | 921 | case 'CZ': |
| 922 | - $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
| 922 | + $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic |
|
| 923 | 923 | break; |
| 924 | 924 | case 'DE': |
| 925 | - $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
| 925 | + $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany |
|
| 926 | 926 | break; |
| 927 | 927 | case 'DK': |
| 928 | - $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
| 928 | + $regex[] = '/^(DK)(\d{8})$/'; // Denmark |
|
| 929 | 929 | break; |
| 930 | 930 | case 'EE': |
| 931 | - $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
| 931 | + $regex[] = '/^(EE)(10\d{7})$/'; // Estonia |
|
| 932 | 932 | break; |
| 933 | 933 | case 'EL': |
| 934 | - $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
| 934 | + $regex[] = '/^(EL)(\d{9})$/'; // Greece |
|
| 935 | 935 | break; |
| 936 | 936 | case 'ES': |
| 937 | - $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
| 938 | - $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
| 939 | - $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
| 940 | - $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
| 937 | + $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities) |
|
| 938 | + $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities) |
|
| 939 | + $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1) |
|
| 940 | + $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2) |
|
| 941 | 941 | break; |
| 942 | 942 | case 'EU': |
| 943 | - $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
| 943 | + $regex[] = '/^(EU)(\d{9})$/'; // EU-type |
|
| 944 | 944 | break; |
| 945 | 945 | case 'FI': |
| 946 | - $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
| 946 | + $regex[] = '/^(FI)(\d{8})$/'; // Finland |
|
| 947 | 947 | break; |
| 948 | 948 | case 'FR': |
| 949 | - $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
| 950 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
| 951 | - $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
| 952 | - $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
| 949 | + $regex[] = '/^(FR)(\d{11})$/'; // France (1) |
|
| 950 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2) |
|
| 951 | + $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3) |
|
| 952 | + $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4) |
|
| 953 | 953 | break; |
| 954 | 954 | case 'GB': |
| 955 | - $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
| 956 | - $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
| 957 | - $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
| 958 | - $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
| 955 | + $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard) |
|
| 956 | + $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches) |
|
| 957 | + $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government) |
|
| 958 | + $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority) |
|
| 959 | 959 | break; |
| 960 | 960 | case 'GR': |
| 961 | - $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
| 961 | + $regex[] = '/^(GR)(\d{8,9})$/'; // Greece |
|
| 962 | 962 | break; |
| 963 | 963 | case 'HR': |
| 964 | - $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
| 964 | + $regex[] = '/^(HR)(\d{11})$/'; // Croatia |
|
| 965 | 965 | break; |
| 966 | 966 | case 'HU': |
| 967 | - $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
| 967 | + $regex[] = '/^(HU)(\d{8})$/'; // Hungary |
|
| 968 | 968 | break; |
| 969 | 969 | case 'IE': |
| 970 | - $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
| 971 | - $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
| 972 | - $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
| 970 | + $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1) |
|
| 971 | + $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2) |
|
| 972 | + $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013) |
|
| 973 | 973 | break; |
| 974 | 974 | case 'IT': |
| 975 | - $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
| 975 | + $regex[] = '/^(IT)(\d{11})$/'; // Italy |
|
| 976 | 976 | break; |
| 977 | 977 | case 'LV': |
| 978 | - $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
| 978 | + $regex[] = '/^(LV)(\d{11})$/'; // Latvia |
|
| 979 | 979 | break; |
| 980 | 980 | case 'LT': |
| 981 | - $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
| 981 | + $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania |
|
| 982 | 982 | break; |
| 983 | 983 | case 'LU': |
| 984 | - $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
| 984 | + $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg |
|
| 985 | 985 | break; |
| 986 | 986 | case 'MT': |
| 987 | - $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
| 987 | + $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta |
|
| 988 | 988 | break; |
| 989 | 989 | case 'NL': |
| 990 | - $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
| 990 | + $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands |
|
| 991 | 991 | break; |
| 992 | 992 | case 'NO': |
| 993 | - $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
| 993 | + $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU) |
|
| 994 | 994 | break; |
| 995 | 995 | case 'PL': |
| 996 | - $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
| 996 | + $regex[] = '/^(PL)(\d{10})$/'; // Poland |
|
| 997 | 997 | break; |
| 998 | 998 | case 'PT': |
| 999 | - $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
| 999 | + $regex[] = '/^(PT)(\d{9})$/'; // Portugal |
|
| 1000 | 1000 | break; |
| 1001 | 1001 | case 'RO': |
| 1002 | - $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
| 1002 | + $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania |
|
| 1003 | 1003 | break; |
| 1004 | 1004 | case 'RS': |
| 1005 | - $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
| 1005 | + $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU) |
|
| 1006 | 1006 | break; |
| 1007 | 1007 | case 'SI': |
| 1008 | - $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
| 1008 | + $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia |
|
| 1009 | 1009 | break; |
| 1010 | 1010 | case 'SK': |
| 1011 | - $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
| 1011 | + $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic |
|
| 1012 | 1012 | break; |
| 1013 | 1013 | case 'SE': |
| 1014 | - $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
| 1014 | + $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden |
|
| 1015 | 1015 | break; |
| 1016 | 1016 | default: |
| 1017 | 1017 | $regex = array(); |
| 1018 | 1018 | break; |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | - if ( empty( $regex ) ) { |
|
| 1021 | + if (empty($regex)) { |
|
| 1022 | 1022 | return false; |
| 1023 | 1023 | } |
| 1024 | 1024 | |
| 1025 | - foreach ( $regex as $pattern ) { |
|
| 1025 | + foreach ($regex as $pattern) { |
|
| 1026 | 1026 | $matches = null; |
| 1027 | - preg_match_all( $pattern, $vat_number, $matches ); |
|
| 1027 | + preg_match_all($pattern, $vat_number, $matches); |
|
| 1028 | 1028 | |
| 1029 | - if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) { |
|
| 1030 | - if ( $formatted ) { |
|
| 1031 | - return array( 'code' => $matches[1][0], 'number' => $matches[2][0] ); |
|
| 1029 | + if (!empty($matches[1][0]) && !empty($matches[2][0])) { |
|
| 1030 | + if ($formatted) { |
|
| 1031 | + return array('code' => $matches[1][0], 'number' => $matches[2][0]); |
|
| 1032 | 1032 | } else { |
| 1033 | 1033 | return true; |
| 1034 | 1034 | } |
@@ -1038,75 +1038,75 @@ discard block |
||
| 1038 | 1038 | return false; |
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | - public static function vies_check( $vat_number, $country_code = '', $result = false ) { |
|
| 1042 | - $vat = self::sanitize_vat( $vat_number, $country_code ); |
|
| 1041 | + public static function vies_check($vat_number, $country_code = '', $result = false) { |
|
| 1042 | + $vat = self::sanitize_vat($vat_number, $country_code); |
|
| 1043 | 1043 | $vat_number = $vat['vat']; |
| 1044 | 1044 | $iso = $vat['iso']; |
| 1045 | 1045 | |
| 1046 | - $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number ); |
|
| 1046 | + $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number); |
|
| 1047 | 1047 | |
| 1048 | - if ( ini_get( 'allow_url_fopen' ) ) { |
|
| 1049 | - $response = file_get_contents( $url ); |
|
| 1050 | - } else if ( function_exists( 'curl_init' ) ) { |
|
| 1048 | + if (ini_get('allow_url_fopen')) { |
|
| 1049 | + $response = file_get_contents($url); |
|
| 1050 | + } else if (function_exists('curl_init')) { |
|
| 1051 | 1051 | $ch = curl_init(); |
| 1052 | 1052 | |
| 1053 | - curl_setopt( $ch, CURLOPT_URL, $url ); |
|
| 1054 | - curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 ); |
|
| 1055 | - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); |
|
| 1056 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); |
|
| 1057 | - curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); |
|
| 1053 | + curl_setopt($ch, CURLOPT_URL, $url); |
|
| 1054 | + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); |
|
| 1055 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 1056 | + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); |
|
| 1057 | + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); |
|
| 1058 | 1058 | |
| 1059 | - $response = curl_exec( $ch ); |
|
| 1059 | + $response = curl_exec($ch); |
|
| 1060 | 1060 | |
| 1061 | - if ( curl_errno( $ch ) ) { |
|
| 1062 | - wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' ); |
|
| 1061 | + if (curl_errno($ch)) { |
|
| 1062 | + wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR'); |
|
| 1063 | 1063 | $response = ''; |
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | - curl_close( $ch ); |
|
| 1066 | + curl_close($ch); |
|
| 1067 | 1067 | } else { |
| 1068 | - wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' ); |
|
| 1068 | + wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR'); |
|
| 1069 | 1069 | } |
| 1070 | 1070 | |
| 1071 | - if ( empty( $response ) ) { |
|
| 1071 | + if (empty($response)) { |
|
| 1072 | 1072 | return $result; |
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | - if ( preg_match( '/invalid VAT number/i', $response ) ) { |
|
| 1075 | + if (preg_match('/invalid VAT number/i', $response)) { |
|
| 1076 | 1076 | return false; |
| 1077 | - } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) { |
|
| 1078 | - $content = explode( "valid VAT number", htmlentities( $response ) ); |
|
| 1077 | + } else if (preg_match('/valid VAT number/i', $response, $matches)) { |
|
| 1078 | + $content = explode("valid VAT number", htmlentities($response)); |
|
| 1079 | 1079 | |
| 1080 | - if ( !empty( $content[1] ) ) { |
|
| 1081 | - preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches ); |
|
| 1080 | + if (!empty($content[1])) { |
|
| 1081 | + preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches); |
|
| 1082 | 1082 | |
| 1083 | - if ( !empty( $matches[2] ) && $matches[3] ) { |
|
| 1083 | + if (!empty($matches[2]) && $matches[3]) { |
|
| 1084 | 1084 | $return = array(); |
| 1085 | 1085 | |
| 1086 | - foreach ( $matches[2] as $key => $label ) { |
|
| 1087 | - $label = trim( $label ); |
|
| 1086 | + foreach ($matches[2] as $key => $label) { |
|
| 1087 | + $label = trim($label); |
|
| 1088 | 1088 | |
| 1089 | - switch ( strtolower( $label ) ) { |
|
| 1089 | + switch (strtolower($label)) { |
|
| 1090 | 1090 | case 'member state': |
| 1091 | - $return['state'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1091 | + $return['state'] = trim(strip_tags($matches[3][$key])); |
|
| 1092 | 1092 | break; |
| 1093 | 1093 | case 'vat number': |
| 1094 | - $return['number'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1094 | + $return['number'] = trim(strip_tags($matches[3][$key])); |
|
| 1095 | 1095 | break; |
| 1096 | 1096 | case 'name': |
| 1097 | - $return['company'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1097 | + $return['company'] = trim(strip_tags($matches[3][$key])); |
|
| 1098 | 1098 | break; |
| 1099 | 1099 | case 'address': |
| 1100 | - $address = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) ); |
|
| 1101 | - $return['address'] = trim( strip_tags( $address, '<br>' ) ); |
|
| 1100 | + $address = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key]))); |
|
| 1101 | + $return['address'] = trim(strip_tags($address, '<br>')); |
|
| 1102 | 1102 | break; |
| 1103 | 1103 | case 'consultation number': |
| 1104 | - $return['consultation'] = trim( strip_tags( $matches[3][$key] ) ); |
|
| 1104 | + $return['consultation'] = trim(strip_tags($matches[3][$key])); |
|
| 1105 | 1105 | break; |
| 1106 | 1106 | } |
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | - if ( !empty( $return ) ) { |
|
| 1109 | + if (!empty($return)) { |
|
| 1110 | 1110 | return $return; |
| 1111 | 1111 | } |
| 1112 | 1112 | } |
@@ -1118,55 +1118,55 @@ discard block |
||
| 1118 | 1118 | } |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | - public static function check_vat( $vat_number, $country_code = '' ) { |
|
| 1121 | + public static function check_vat($vat_number, $country_code = '') { |
|
| 1122 | 1122 | $vat_name = self::get_vat_name(); |
| 1123 | 1123 | |
| 1124 | 1124 | $return = array(); |
| 1125 | 1125 | $return['valid'] = false; |
| 1126 | - $return['message'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
| 1126 | + $return['message'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
| 1127 | 1127 | |
| 1128 | - if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) { |
|
| 1128 | + if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) { |
|
| 1129 | 1129 | return $return; |
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | - $response = self::vies_check( $vat_number, $country_code ); |
|
| 1132 | + $response = self::vies_check($vat_number, $country_code); |
|
| 1133 | 1133 | |
| 1134 | - if ( $response ) { |
|
| 1135 | - $return['valid'] = true; |
|
| 1134 | + if ($response) { |
|
| 1135 | + $return['valid'] = true; |
|
| 1136 | 1136 | |
| 1137 | - if ( is_array( $response ) ) { |
|
| 1138 | - $return['company'] = isset( $response['company'] ) ? $response['company'] : ''; |
|
| 1139 | - $return['address'] = isset( $response['address'] ) ? $response['address'] : ''; |
|
| 1137 | + if (is_array($response)) { |
|
| 1138 | + $return['company'] = isset($response['company']) ? $response['company'] : ''; |
|
| 1139 | + $return['address'] = isset($response['address']) ? $response['address'] : ''; |
|
| 1140 | 1140 | $return['message'] = $return['company'] . '<br/>' . $return['address']; |
| 1141 | 1141 | } |
| 1142 | 1142 | } else { |
| 1143 | 1143 | $return['valid'] = false; |
| 1144 | - $return['message'] = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
| 1144 | + $return['message'] = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | return $return; |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | - public static function request_euvatrates( $group ) { |
|
| 1150 | + public static function request_euvatrates($group) { |
|
| 1151 | 1151 | $response = array(); |
| 1152 | 1152 | $response['success'] = false; |
| 1153 | 1153 | $response['error'] = null; |
| 1154 | 1154 | $response['eurates'] = null; |
| 1155 | 1155 | |
| 1156 | 1156 | $euvatrates_url = 'https://euvatrates.com/rates.json'; |
| 1157 | - $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url ); |
|
| 1158 | - $api_response = wp_remote_get( $euvatrates_url ); |
|
| 1157 | + $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url); |
|
| 1158 | + $api_response = wp_remote_get($euvatrates_url); |
|
| 1159 | 1159 | |
| 1160 | 1160 | try { |
| 1161 | - if ( is_wp_error( $api_response ) ) { |
|
| 1162 | - $response['error'] = __( $api_response->get_error_message(), 'invoicing' ); |
|
| 1161 | + if (is_wp_error($api_response)) { |
|
| 1162 | + $response['error'] = __($api_response->get_error_message(), 'invoicing'); |
|
| 1163 | 1163 | } else { |
| 1164 | - $body = json_decode( $api_response['body'] ); |
|
| 1164 | + $body = json_decode($api_response['body']); |
|
| 1165 | 1165 | |
| 1166 | - if ( isset( $body->rates ) ) { |
|
| 1166 | + if (isset($body->rates)) { |
|
| 1167 | 1167 | $rates = array(); |
| 1168 | 1168 | |
| 1169 | - foreach ( $body->rates as $country_code => $rate ) { |
|
| 1169 | + foreach ($body->rates as $country_code => $rate) { |
|
| 1170 | 1170 | $vat_rate = array(); |
| 1171 | 1171 | $vat_rate['country'] = $rate->country; |
| 1172 | 1172 | $vat_rate['standard'] = (float)$rate->standard_rate; |
@@ -1174,7 +1174,7 @@ discard block |
||
| 1174 | 1174 | $vat_rate['superreduced'] = (float)$rate->super_reduced_rate; |
| 1175 | 1175 | $vat_rate['parking'] = (float)$rate->parking_rate; |
| 1176 | 1176 | |
| 1177 | - if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) { |
|
| 1177 | + if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) { |
|
| 1178 | 1178 | $vat_rate_group = array(); |
| 1179 | 1179 | $vat_rate_group['country'] = $rate->country; |
| 1180 | 1180 | $vat_rate_group[$group] = $vat_rate[$group]; |
@@ -1186,79 +1186,79 @@ discard block |
||
| 1186 | 1186 | } |
| 1187 | 1187 | |
| 1188 | 1188 | $response['success'] = true; |
| 1189 | - $response['rates'] = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group ); |
|
| 1189 | + $response['rates'] = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group); |
|
| 1190 | 1190 | } else { |
| 1191 | - $response['error'] = __( 'No EU rates found!', 'invoicing' ); |
|
| 1191 | + $response['error'] = __('No EU rates found!', 'invoicing'); |
|
| 1192 | 1192 | } |
| 1193 | 1193 | } |
| 1194 | - } catch ( Exception $e ) { |
|
| 1195 | - $response['error'] = __( $e->getMessage(), 'invoicing' ); |
|
| 1194 | + } catch (Exception $e) { |
|
| 1195 | + $response['error'] = __($e->getMessage(), 'invoicing'); |
|
| 1196 | 1196 | } |
| 1197 | 1197 | |
| 1198 | - return apply_filters( 'wpinv_response_euvatrates', $response, $group ); |
|
| 1198 | + return apply_filters('wpinv_response_euvatrates', $response, $group); |
|
| 1199 | 1199 | } |
| 1200 | 1200 | |
| 1201 | - public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) { |
|
| 1201 | + public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) { |
|
| 1202 | 1202 | global $wpi_item_id, $wpi_country; |
| 1203 | 1203 | |
| 1204 | - if ( !empty( $_POST['wpinv_country'] ) ) { |
|
| 1205 | - $country_code = trim( $_POST['wpinv_country'] ); |
|
| 1206 | - } else if ( !empty( $_POST['country'] ) ) { |
|
| 1207 | - $country_code = trim( $_POST['country'] ); |
|
| 1208 | - } else if ( !empty( $wpi_country ) ) { |
|
| 1204 | + if (!empty($_POST['wpinv_country'])) { |
|
| 1205 | + $country_code = trim($_POST['wpinv_country']); |
|
| 1206 | + } else if (!empty($_POST['country'])) { |
|
| 1207 | + $country_code = trim($_POST['country']); |
|
| 1208 | + } else if (!empty($wpi_country)) { |
|
| 1209 | 1209 | $country_code = $wpi_country; |
| 1210 | 1210 | } else { |
| 1211 | - $country_code = self::get_user_country( '', $user_id ); |
|
| 1211 | + $country_code = self::get_user_country('', $user_id); |
|
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | - if ( $is_digital === null && $wpi_item_id ) { |
|
| 1215 | - $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules(); |
|
| 1214 | + if ($is_digital === null && $wpi_item_id) { |
|
| 1215 | + $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules(); |
|
| 1216 | 1216 | } |
| 1217 | 1217 | |
| 1218 | - if ( !empty( $country_code ) ) { |
|
| 1219 | - $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) ); |
|
| 1218 | + if (!empty($country_code)) { |
|
| 1219 | + $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country)); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | - return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id ); |
|
| 1222 | + return apply_filters('wpinv_requires_vat', $requires_vat, $user_id); |
|
| 1223 | 1223 | } |
| 1224 | 1224 | |
| 1225 | - public static function tax_label( $label = '' ) { |
|
| 1225 | + public static function tax_label($label = '') { |
|
| 1226 | 1226 | global $wpi_requires_vat; |
| 1227 | 1227 | |
| 1228 | - if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) { |
|
| 1229 | - $wpi_requires_vat = self::requires_vat( 0, false ); |
|
| 1228 | + if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) { |
|
| 1229 | + $wpi_requires_vat = self::requires_vat(0, false); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | - return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) ); |
|
| 1232 | + return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing')); |
|
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | 1235 | public static function standard_rates_label() { |
| 1236 | - return __( 'Standard Rates', 'invoicing' ); |
|
| 1236 | + return __('Standard Rates', 'invoicing'); |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | - public static function get_rate_classes( $with_desc = false ) { |
|
| 1240 | - $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true ); |
|
| 1241 | - $classes = maybe_unserialize( $rate_classes_option ); |
|
| 1239 | + public static function get_rate_classes($with_desc = false) { |
|
| 1240 | + $rate_classes_option = get_option('_wpinv_vat_rate_classes', true); |
|
| 1241 | + $classes = maybe_unserialize($rate_classes_option); |
|
| 1242 | 1242 | |
| 1243 | - if ( empty( $classes ) || !is_array( $classes ) ) { |
|
| 1243 | + if (empty($classes) || !is_array($classes)) { |
|
| 1244 | 1244 | $classes = array(); |
| 1245 | 1245 | } |
| 1246 | 1246 | |
| 1247 | 1247 | $rate_classes = array(); |
| 1248 | - if ( !array_key_exists( '_standard', $classes ) ) { |
|
| 1249 | - if ( $with_desc ) { |
|
| 1250 | - $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) ); |
|
| 1248 | + if (!array_key_exists('_standard', $classes)) { |
|
| 1249 | + if ($with_desc) { |
|
| 1250 | + $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing')); |
|
| 1251 | 1251 | } else { |
| 1252 | 1252 | $rate_classes['_standard'] = self::standard_rates_label(); |
| 1253 | 1253 | } |
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | - foreach ( $classes as $key => $class ) { |
|
| 1257 | - $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key; |
|
| 1258 | - $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : ''; |
|
| 1256 | + foreach ($classes as $key => $class) { |
|
| 1257 | + $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key; |
|
| 1258 | + $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : ''; |
|
| 1259 | 1259 | |
| 1260 | - if ( $with_desc ) { |
|
| 1261 | - $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc ); |
|
| 1260 | + if ($with_desc) { |
|
| 1261 | + $rate_classes[$key] = array('name' => $name, 'desc' => $desc); |
|
| 1262 | 1262 | } else { |
| 1263 | 1263 | $rate_classes[$key] = $name; |
| 1264 | 1264 | } |
@@ -1269,15 +1269,15 @@ discard block |
||
| 1269 | 1269 | |
| 1270 | 1270 | public static function get_all_classes() { |
| 1271 | 1271 | $classes = self::get_rate_classes(); |
| 1272 | - $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' ); |
|
| 1272 | + $classes['_exempt'] = __('Exempt (0%)', 'invoicing'); |
|
| 1273 | 1273 | |
| 1274 | - return apply_filters( 'wpinv_vat_get_all_classes', $classes ); |
|
| 1274 | + return apply_filters('wpinv_vat_get_all_classes', $classes); |
|
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | - public static function get_class_desc( $rate_class ) { |
|
| 1278 | - $rate_classes = self::get_rate_classes( true ); |
|
| 1277 | + public static function get_class_desc($rate_class) { |
|
| 1278 | + $rate_classes = self::get_rate_classes(true); |
|
| 1279 | 1279 | |
| 1280 | - if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) { |
|
| 1280 | + if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) { |
|
| 1281 | 1281 | return $rate_classes[$rate_class]['desc']; |
| 1282 | 1282 | } |
| 1283 | 1283 | |
@@ -1293,106 +1293,106 @@ discard block |
||
| 1293 | 1293 | 'increased' => 'Increased' |
| 1294 | 1294 | ); |
| 1295 | 1295 | |
| 1296 | - return apply_filters( 'wpinv_get_vat_groups', $vat_groups ); |
|
| 1296 | + return apply_filters('wpinv_get_vat_groups', $vat_groups); |
|
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | public static function get_rules() { |
| 1300 | 1300 | $vat_rules = array( |
| 1301 | - 'digital' => __( 'Digital Product', 'invoicing' ), |
|
| 1302 | - 'physical' => __( 'Physical Product', 'invoicing' ) |
|
| 1301 | + 'digital' => __('Digital Product', 'invoicing'), |
|
| 1302 | + 'physical' => __('Physical Product', 'invoicing') |
|
| 1303 | 1303 | ); |
| 1304 | - return apply_filters( 'wpinv_get_vat_rules', $vat_rules ); |
|
| 1304 | + return apply_filters('wpinv_get_vat_rules', $vat_rules); |
|
| 1305 | 1305 | } |
| 1306 | 1306 | |
| 1307 | - public static function get_vat_rates( $class ) { |
|
| 1308 | - if ( $class === '_standard' ) { |
|
| 1307 | + public static function get_vat_rates($class) { |
|
| 1308 | + if ($class === '_standard') { |
|
| 1309 | 1309 | return wpinv_get_tax_rates(); |
| 1310 | 1310 | } |
| 1311 | 1311 | |
| 1312 | 1312 | $rates = self::get_non_standard_rates(); |
| 1313 | 1313 | |
| 1314 | - return array_key_exists( $class, $rates ) ? $rates[$class] : array(); |
|
| 1314 | + return array_key_exists($class, $rates) ? $rates[$class] : array(); |
|
| 1315 | 1315 | } |
| 1316 | 1316 | |
| 1317 | 1317 | public static function get_non_standard_rates() { |
| 1318 | - $option = get_option( 'wpinv_vat_rates', array()); |
|
| 1319 | - return is_array( $option ) ? $option : array(); |
|
| 1318 | + $option = get_option('wpinv_vat_rates', array()); |
|
| 1319 | + return is_array($option) ? $option : array(); |
|
| 1320 | 1320 | } |
| 1321 | 1321 | |
| 1322 | 1322 | public static function allow_vat_rules() { |
| 1323 | - return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false ); |
|
| 1323 | + return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false); |
|
| 1324 | 1324 | } |
| 1325 | 1325 | |
| 1326 | 1326 | public static function allow_vat_classes() { |
| 1327 | 1327 | return false; // TODO |
| 1328 | - return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false ); |
|
| 1328 | + return (wpinv_get_option('vat_allow_classes') ? true : false); |
|
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | - public static function get_item_class( $postID ) { |
|
| 1332 | - $class = get_post_meta( $postID, '_wpinv_vat_class', true ); |
|
| 1331 | + public static function get_item_class($postID) { |
|
| 1332 | + $class = get_post_meta($postID, '_wpinv_vat_class', true); |
|
| 1333 | 1333 | |
| 1334 | - if ( empty( $class ) ) { |
|
| 1334 | + if (empty($class)) { |
|
| 1335 | 1335 | $class = '_standard'; |
| 1336 | 1336 | } |
| 1337 | 1337 | |
| 1338 | - return apply_filters( 'wpinv_get_item_vat_class', $class, $postID ); |
|
| 1338 | + return apply_filters('wpinv_get_item_vat_class', $class, $postID); |
|
| 1339 | 1339 | } |
| 1340 | 1340 | |
| 1341 | - public static function item_class_label( $postID ) { |
|
| 1341 | + public static function item_class_label($postID) { |
|
| 1342 | 1342 | $vat_classes = self::get_all_classes(); |
| 1343 | 1343 | |
| 1344 | - $class = self::get_item_class( $postID ); |
|
| 1345 | - $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' ); |
|
| 1344 | + $class = self::get_item_class($postID); |
|
| 1345 | + $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing'); |
|
| 1346 | 1346 | |
| 1347 | - return apply_filters( 'wpinv_item_class_label', $class, $postID ); |
|
| 1347 | + return apply_filters('wpinv_item_class_label', $class, $postID); |
|
| 1348 | 1348 | } |
| 1349 | 1349 | |
| 1350 | - public static function get_item_rule( $postID ) { |
|
| 1351 | - $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true ); |
|
| 1350 | + public static function get_item_rule($postID) { |
|
| 1351 | + $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true); |
|
| 1352 | 1352 | |
| 1353 | - if ( empty( $rule_type ) ) { |
|
| 1353 | + if (empty($rule_type)) { |
|
| 1354 | 1354 | $rule_type = self::allow_vat_rules() ? 'digital' : 'physical'; |
| 1355 | 1355 | } |
| 1356 | 1356 | |
| 1357 | - return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID ); |
|
| 1357 | + return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID); |
|
| 1358 | 1358 | } |
| 1359 | 1359 | |
| 1360 | - public static function item_rule_label( $postID ) { |
|
| 1360 | + public static function item_rule_label($postID) { |
|
| 1361 | 1361 | $vat_rules = self::get_rules(); |
| 1362 | - $vat_rule = self::get_item_rule( $postID ); |
|
| 1363 | - $vat_rule = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule; |
|
| 1362 | + $vat_rule = self::get_item_rule($postID); |
|
| 1363 | + $vat_rule = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule; |
|
| 1364 | 1364 | |
| 1365 | - return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID ); |
|
| 1365 | + return apply_filters('wpinv_item_rule_label', $vat_rule, $postID); |
|
| 1366 | 1366 | } |
| 1367 | 1367 | |
| 1368 | - public static function item_has_digital_rule( $item_id = 0 ) { |
|
| 1369 | - return self::get_item_rule( $item_id ) == 'digital' ? true : false; |
|
| 1368 | + public static function item_has_digital_rule($item_id = 0) { |
|
| 1369 | + return self::get_item_rule($item_id) == 'digital' ? true : false; |
|
| 1370 | 1370 | } |
| 1371 | 1371 | |
| 1372 | - public static function invoice_has_digital_rule( $invoice = 0 ) { |
|
| 1373 | - if ( !self::allow_vat_rules() ) { |
|
| 1372 | + public static function invoice_has_digital_rule($invoice = 0) { |
|
| 1373 | + if (!self::allow_vat_rules()) { |
|
| 1374 | 1374 | return false; |
| 1375 | 1375 | } |
| 1376 | 1376 | |
| 1377 | - if ( empty( $invoice ) ) { |
|
| 1377 | + if (empty($invoice)) { |
|
| 1378 | 1378 | return true; |
| 1379 | 1379 | } |
| 1380 | 1380 | |
| 1381 | - if ( is_int( $invoice ) ) { |
|
| 1382 | - $invoice = new WPInv_Invoice( $invoice ); |
|
| 1381 | + if (is_int($invoice)) { |
|
| 1382 | + $invoice = new WPInv_Invoice($invoice); |
|
| 1383 | 1383 | } |
| 1384 | 1384 | |
| 1385 | - if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) { |
|
| 1385 | + if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) { |
|
| 1386 | 1386 | return true; |
| 1387 | 1387 | } |
| 1388 | 1388 | |
| 1389 | - $cart_items = $invoice->get_cart_details(); |
|
| 1389 | + $cart_items = $invoice->get_cart_details(); |
|
| 1390 | 1390 | |
| 1391 | - if ( !empty( $cart_items ) ) { |
|
| 1391 | + if (!empty($cart_items)) { |
|
| 1392 | 1392 | $has_digital_rule = false; |
| 1393 | 1393 | |
| 1394 | - foreach ( $cart_items as $key => $item ) { |
|
| 1395 | - if ( self::item_has_digital_rule( $item['id'] ) ) { |
|
| 1394 | + foreach ($cart_items as $key => $item) { |
|
| 1395 | + if (self::item_has_digital_rule($item['id'])) { |
|
| 1396 | 1396 | $has_digital_rule = true; |
| 1397 | 1397 | break; |
| 1398 | 1398 | } |
@@ -1404,67 +1404,67 @@ discard block |
||
| 1404 | 1404 | return $has_digital_rule; |
| 1405 | 1405 | } |
| 1406 | 1406 | |
| 1407 | - public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) { |
|
| 1408 | - if ( !wpinv_use_taxes() ) { |
|
| 1407 | + public static function item_is_taxable($item_id = 0, $country = false, $state = false) { |
|
| 1408 | + if (!wpinv_use_taxes()) { |
|
| 1409 | 1409 | return false; |
| 1410 | 1410 | } |
| 1411 | 1411 | |
| 1412 | 1412 | $is_taxable = true; |
| 1413 | 1413 | |
| 1414 | - if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) { |
|
| 1414 | + if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') { |
|
| 1415 | 1415 | $is_taxable = false; |
| 1416 | 1416 | } |
| 1417 | 1417 | |
| 1418 | - return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state ); |
|
| 1418 | + return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state); |
|
| 1419 | 1419 | } |
| 1420 | 1420 | |
| 1421 | - public static function find_rate( $country, $state, $rate, $class ) { |
|
| 1421 | + public static function find_rate($country, $state, $rate, $class) { |
|
| 1422 | 1422 | global $wpi_zero_tax; |
| 1423 | 1423 | |
| 1424 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
| 1424 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
| 1425 | 1425 | return 0; |
| 1426 | 1426 | } |
| 1427 | 1427 | |
| 1428 | - $tax_rates = wpinv_get_tax_rates(); |
|
| 1428 | + $tax_rates = wpinv_get_tax_rates(); |
|
| 1429 | 1429 | |
| 1430 | - if ( $class !== '_standard' ) { |
|
| 1431 | - $class_rates = self::get_vat_rates( $class ); |
|
| 1430 | + if ($class !== '_standard') { |
|
| 1431 | + $class_rates = self::get_vat_rates($class); |
|
| 1432 | 1432 | |
| 1433 | - if ( is_array( $class_rates ) ) { |
|
| 1433 | + if (is_array($class_rates)) { |
|
| 1434 | 1434 | $indexed_class_rates = array(); |
| 1435 | 1435 | |
| 1436 | - foreach ( $class_rates as $key => $cr ) { |
|
| 1436 | + foreach ($class_rates as $key => $cr) { |
|
| 1437 | 1437 | $indexed_class_rates[$cr['country']] = $cr; |
| 1438 | 1438 | } |
| 1439 | 1439 | |
| 1440 | - $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) { |
|
| 1440 | + $tax_rates = array_map(function($tr) use($indexed_class_rates) { |
|
| 1441 | 1441 | $tr_country = $tr['country']; |
| 1442 | - if ( !isset( $indexed_class_rates[$tr_country] ) ) { |
|
| 1442 | + if (!isset($indexed_class_rates[$tr_country])) { |
|
| 1443 | 1443 | return $tr; |
| 1444 | 1444 | } |
| 1445 | 1445 | $icr = $indexed_class_rates[$tr_country]; |
| 1446 | - return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr; |
|
| 1446 | + return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr; |
|
| 1447 | 1447 | |
| 1448 | - }, $tax_rates, $class_rates ); |
|
| 1448 | + }, $tax_rates, $class_rates); |
|
| 1449 | 1449 | } |
| 1450 | 1450 | } |
| 1451 | 1451 | |
| 1452 | - if ( !empty( $tax_rates ) ) { |
|
| 1453 | - foreach ( $tax_rates as $key => $tax_rate ) { |
|
| 1454 | - if ( $country != $tax_rate['country'] ) |
|
| 1452 | + if (!empty($tax_rates)) { |
|
| 1453 | + foreach ($tax_rates as $key => $tax_rate) { |
|
| 1454 | + if ($country != $tax_rate['country']) |
|
| 1455 | 1455 | continue; |
| 1456 | 1456 | |
| 1457 | - if ( !empty( $tax_rate['global'] ) ) { |
|
| 1458 | - if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) { |
|
| 1459 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
| 1457 | + if (!empty($tax_rate['global'])) { |
|
| 1458 | + if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) { |
|
| 1459 | + $rate = number_format($tax_rate['rate'], 4); |
|
| 1460 | 1460 | } |
| 1461 | 1461 | } else { |
| 1462 | - if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
| 1462 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
| 1463 | 1463 | continue; |
| 1464 | 1464 | |
| 1465 | 1465 | $state_rate = $tax_rate['rate']; |
| 1466 | - if ( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
| 1467 | - $rate = number_format( $state_rate, 4 ); |
|
| 1466 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
| 1467 | + $rate = number_format($state_rate, 4); |
|
| 1468 | 1468 | } |
| 1469 | 1469 | } |
| 1470 | 1470 | } |
@@ -1473,84 +1473,84 @@ discard block |
||
| 1473 | 1473 | return $rate; |
| 1474 | 1474 | } |
| 1475 | 1475 | |
| 1476 | - public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) { |
|
| 1476 | + public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) { |
|
| 1477 | 1477 | global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax; |
| 1478 | 1478 | |
| 1479 | 1479 | $item_id = $item_id > 0 ? $item_id : $wpi_item_id; |
| 1480 | 1480 | $allow_vat_classes = self::allow_vat_classes(); |
| 1481 | - $class = $item_id ? self::get_item_class( $item_id ) : '_standard'; |
|
| 1481 | + $class = $item_id ? self::get_item_class($item_id) : '_standard'; |
|
| 1482 | 1482 | |
| 1483 | - if ( $class === '_exempt' || $wpi_zero_tax ) { |
|
| 1483 | + if ($class === '_exempt' || $wpi_zero_tax) { |
|
| 1484 | 1484 | return 0; |
| 1485 | - } else if ( !$allow_vat_classes ) { |
|
| 1485 | + } else if (!$allow_vat_classes) { |
|
| 1486 | 1486 | $class = '_standard'; |
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 1489 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
| 1489 | + if (!empty($_POST['wpinv_country'])) { |
|
| 1490 | 1490 | $post_country = $_POST['wpinv_country']; |
| 1491 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
| 1491 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
| 1492 | 1492 | $post_country = $_POST['wpinv_country']; |
| 1493 | - } elseif( !empty( $_POST['country'] ) ) { |
|
| 1493 | + } elseif (!empty($_POST['country'])) { |
|
| 1494 | 1494 | $post_country = $_POST['country']; |
| 1495 | 1495 | } else { |
| 1496 | 1496 | $post_country = ''; |
| 1497 | 1497 | } |
| 1498 | 1498 | |
| 1499 | - $country = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country ); |
|
| 1500 | - $base_country = wpinv_is_base_country( $country ); |
|
| 1499 | + $country = !empty($post_country) ? $post_country : wpinv_default_billing_country($country); |
|
| 1500 | + $base_country = wpinv_is_base_country($country); |
|
| 1501 | 1501 | |
| 1502 | - $requires_vat = self::requires_vat( 0, false ); |
|
| 1503 | - $is_digital = self::get_item_rule( $item_id ) == 'digital' ; |
|
| 1504 | - $rate = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
| 1502 | + $requires_vat = self::requires_vat(0, false); |
|
| 1503 | + $is_digital = self::get_item_rule($item_id) == 'digital'; |
|
| 1504 | + $rate = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate; |
|
| 1505 | 1505 | |
| 1506 | - if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country |
|
| 1506 | + if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country |
|
| 1507 | 1507 | $rate = 0; |
| 1508 | - } else if ( $requires_vat ) { |
|
| 1509 | - $vat_number = self::get_user_vat_number( '', 0, true ); |
|
| 1508 | + } else if ($requires_vat) { |
|
| 1509 | + $vat_number = self::get_user_vat_number('', 0, true); |
|
| 1510 | 1510 | $vat_info = self::current_vat_data(); |
| 1511 | 1511 | |
| 1512 | - if ( is_array( $vat_info ) ) { |
|
| 1513 | - $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : ""; |
|
| 1512 | + if (is_array($vat_info)) { |
|
| 1513 | + $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : ""; |
|
| 1514 | 1514 | } |
| 1515 | 1515 | |
| 1516 | - if ( $country == 'UK' ) { |
|
| 1516 | + if ($country == 'UK') { |
|
| 1517 | 1517 | $country = 'GB'; |
| 1518 | 1518 | } |
| 1519 | 1519 | |
| 1520 | - if ( !empty( $vat_number ) ) { |
|
| 1520 | + if (!empty($vat_number)) { |
|
| 1521 | 1521 | $rate = 0; |
| 1522 | 1522 | } else { |
| 1523 | - $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
| 1523 | + $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate |
|
| 1524 | 1524 | } |
| 1525 | 1525 | |
| 1526 | - if ( empty( $vat_number ) && !$is_digital ) { |
|
| 1527 | - if ( $base_country ) { |
|
| 1528 | - $rate = self::find_rate( $country, null, $rate, $class ); |
|
| 1526 | + if (empty($vat_number) && !$is_digital) { |
|
| 1527 | + if ($base_country) { |
|
| 1528 | + $rate = self::find_rate($country, null, $rate, $class); |
|
| 1529 | 1529 | } else { |
| 1530 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
| 1530 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
| 1531 | 1531 | $rate = $wpinv_options['eu_fallback_rate']; |
| 1532 | - } else if( !empty( $country ) ) { |
|
| 1533 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1532 | + } else if (!empty($country)) { |
|
| 1533 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1534 | 1534 | } |
| 1535 | 1535 | } |
| 1536 | - } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) { |
|
| 1537 | - if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) { |
|
| 1536 | + } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) { |
|
| 1537 | + if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) { |
|
| 1538 | 1538 | $rate = $wpinv_options['eu_fallback_rate']; |
| 1539 | - } else if( !empty( $country ) ) { |
|
| 1540 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1539 | + } else if (!empty($country)) { |
|
| 1540 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1541 | 1541 | } |
| 1542 | 1542 | } |
| 1543 | 1543 | } else { |
| 1544 | - if ( $is_digital ) { |
|
| 1544 | + if ($is_digital) { |
|
| 1545 | 1545 | $ip_country_code = self::get_country_by_ip(); |
| 1546 | 1546 | |
| 1547 | - if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) { |
|
| 1548 | - $rate = self::find_rate( $ip_country_code, '', 0, $class ); |
|
| 1547 | + if ($ip_country_code && self::is_eu_state($ip_country_code)) { |
|
| 1548 | + $rate = self::find_rate($ip_country_code, '', 0, $class); |
|
| 1549 | 1549 | } else { |
| 1550 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1550 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1551 | 1551 | } |
| 1552 | 1552 | } else { |
| 1553 | - $rate = self::find_rate( $country, $state, $rate, $class ); |
|
| 1553 | + $rate = self::find_rate($country, $state, $rate, $class); |
|
| 1554 | 1554 | } |
| 1555 | 1555 | } |
| 1556 | 1556 | |
@@ -1560,48 +1560,48 @@ discard block |
||
| 1560 | 1560 | public static function current_vat_data() { |
| 1561 | 1561 | global $wpi_session; |
| 1562 | 1562 | |
| 1563 | - return $wpi_session->get( 'user_vat_data' ); |
|
| 1563 | + return $wpi_session->get('user_vat_data'); |
|
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | - public static function get_user_country( $country = '', $user_id = 0 ) { |
|
| 1567 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
| 1566 | + public static function get_user_country($country = '', $user_id = 0) { |
|
| 1567 | + $user_address = wpinv_get_user_address($user_id, false); |
|
| 1568 | 1568 | |
| 1569 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
| 1569 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
| 1570 | 1570 | $country = ''; |
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | - $country = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country']; |
|
| 1574 | - $result = apply_filters( 'wpinv_get_user_country', $country, $user_id ); |
|
| 1573 | + $country = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country']; |
|
| 1574 | + $result = apply_filters('wpinv_get_user_country', $country, $user_id); |
|
| 1575 | 1575 | |
| 1576 | - if ( empty( $result ) ) { |
|
| 1576 | + if (empty($result)) { |
|
| 1577 | 1577 | $result = self::get_country_by_ip(); |
| 1578 | 1578 | } |
| 1579 | 1579 | |
| 1580 | 1580 | return $result; |
| 1581 | 1581 | } |
| 1582 | 1582 | |
| 1583 | - public static function set_user_country( $country = '', $user_id = 0 ) { |
|
| 1583 | + public static function set_user_country($country = '', $user_id = 0) { |
|
| 1584 | 1584 | global $wpi_userID; |
| 1585 | 1585 | |
| 1586 | - if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) { |
|
| 1586 | + if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) { |
|
| 1587 | 1587 | $country = wpinv_get_default_country(); |
| 1588 | 1588 | } |
| 1589 | 1589 | |
| 1590 | 1590 | return $country; |
| 1591 | 1591 | } |
| 1592 | 1592 | |
| 1593 | - public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) { |
|
| 1593 | + public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) { |
|
| 1594 | 1594 | global $wpi_current_id, $wpi_userID; |
| 1595 | 1595 | |
| 1596 | - if ( !empty( $_POST['new_user'] ) ) { |
|
| 1596 | + if (!empty($_POST['new_user'])) { |
|
| 1597 | 1597 | return ''; |
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | - if ( empty( $user_id ) ) { |
|
| 1601 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
| 1600 | + if (empty($user_id)) { |
|
| 1601 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
| 1602 | 1602 | } |
| 1603 | 1603 | |
| 1604 | - $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true ); |
|
| 1604 | + $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true); |
|
| 1605 | 1605 | |
| 1606 | 1606 | /* TODO |
| 1607 | 1607 | if ( $is_valid && $vat_number ) { |
@@ -1612,38 +1612,38 @@ discard block |
||
| 1612 | 1612 | } |
| 1613 | 1613 | */ |
| 1614 | 1614 | |
| 1615 | - return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid ); |
|
| 1615 | + return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid); |
|
| 1616 | 1616 | } |
| 1617 | 1617 | |
| 1618 | - public static function get_user_company( $company = '', $user_id = 0 ) { |
|
| 1618 | + public static function get_user_company($company = '', $user_id = 0) { |
|
| 1619 | 1619 | global $wpi_current_id, $wpi_userID; |
| 1620 | 1620 | |
| 1621 | - if ( empty( $user_id ) ) { |
|
| 1622 | - $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() ); |
|
| 1621 | + if (empty($user_id)) { |
|
| 1622 | + $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id()); |
|
| 1623 | 1623 | } |
| 1624 | 1624 | |
| 1625 | - $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true ); |
|
| 1625 | + $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true); |
|
| 1626 | 1626 | |
| 1627 | - return apply_filters( 'wpinv_user_company', $company, $user_id ); |
|
| 1627 | + return apply_filters('wpinv_user_company', $company, $user_id); |
|
| 1628 | 1628 | } |
| 1629 | 1629 | |
| 1630 | - public static function save_user_vat_details( $company = '', $vat_number = '' ) { |
|
| 1631 | - $save = apply_filters( 'wpinv_allow_save_user_vat_details', true ); |
|
| 1630 | + public static function save_user_vat_details($company = '', $vat_number = '') { |
|
| 1631 | + $save = apply_filters('wpinv_allow_save_user_vat_details', true); |
|
| 1632 | 1632 | |
| 1633 | - if ( is_user_logged_in() && $save ) { |
|
| 1633 | + if (is_user_logged_in() && $save) { |
|
| 1634 | 1634 | $user_id = get_current_user_id(); |
| 1635 | 1635 | |
| 1636 | - if ( !empty( $vat_number ) ) { |
|
| 1637 | - update_user_meta( $user_id, '_wpinv_vat_number', $vat_number ); |
|
| 1636 | + if (!empty($vat_number)) { |
|
| 1637 | + update_user_meta($user_id, '_wpinv_vat_number', $vat_number); |
|
| 1638 | 1638 | } else { |
| 1639 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
| 1639 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | - if ( !empty( $company ) ) { |
|
| 1643 | - update_user_meta( $user_id, '_wpinv_company', $company ); |
|
| 1642 | + if (!empty($company)) { |
|
| 1643 | + update_user_meta($user_id, '_wpinv_company', $company); |
|
| 1644 | 1644 | } else { |
| 1645 | - delete_user_meta( $user_id, '_wpinv_company'); |
|
| 1646 | - delete_user_meta( $user_id, '_wpinv_vat_number'); |
|
| 1645 | + delete_user_meta($user_id, '_wpinv_company'); |
|
| 1646 | + delete_user_meta($user_id, '_wpinv_vat_number'); |
|
| 1647 | 1647 | } |
| 1648 | 1648 | } |
| 1649 | 1649 | |
@@ -1653,113 +1653,113 @@ discard block |
||
| 1653 | 1653 | public static function ajax_vat_validate() { |
| 1654 | 1654 | global $wpinv_options, $wpi_session; |
| 1655 | 1655 | |
| 1656 | - $is_checkout = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false; |
|
| 1656 | + $is_checkout = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false; |
|
| 1657 | 1657 | $response = array(); |
| 1658 | 1658 | $response['success'] = false; |
| 1659 | 1659 | |
| 1660 | - if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) { |
|
| 1661 | - $response['error'] = __( 'Invalid security nonce', 'invoicing' ); |
|
| 1662 | - wp_send_json( $response ); |
|
| 1660 | + if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) { |
|
| 1661 | + $response['error'] = __('Invalid security nonce', 'invoicing'); |
|
| 1662 | + wp_send_json($response); |
|
| 1663 | 1663 | } |
| 1664 | 1664 | |
| 1665 | - $vat_name = self::get_vat_name(); |
|
| 1665 | + $vat_name = self::get_vat_name(); |
|
| 1666 | 1666 | |
| 1667 | - if ( $is_checkout ) { |
|
| 1667 | + if ($is_checkout) { |
|
| 1668 | 1668 | $invoice = wpinv_get_invoice_cart(); |
| 1669 | 1669 | |
| 1670 | - if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) { |
|
| 1670 | + if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) { |
|
| 1671 | 1671 | $vat_info = array(); |
| 1672 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1672 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1673 | 1673 | |
| 1674 | 1674 | self::save_user_vat_details(); |
| 1675 | 1675 | |
| 1676 | 1676 | $response['success'] = true; |
| 1677 | - $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name ); |
|
| 1678 | - wp_send_json( $response ); |
|
| 1677 | + $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name); |
|
| 1678 | + wp_send_json($response); |
|
| 1679 | 1679 | } |
| 1680 | 1680 | } |
| 1681 | 1681 | |
| 1682 | - $company = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : ''; |
|
| 1683 | - $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : ''; |
|
| 1682 | + $company = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : ''; |
|
| 1683 | + $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : ''; |
|
| 1684 | 1684 | |
| 1685 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 1686 | - if ( !is_array( $vat_info ) || empty( $vat_info ) ) { |
|
| 1687 | - $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true ); |
|
| 1685 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 1686 | + if (!is_array($vat_info) || empty($vat_info)) { |
|
| 1687 | + $vat_info = array('company'=> $company, 'number' => '', 'valid' => true); |
|
| 1688 | 1688 | } |
| 1689 | 1689 | |
| 1690 | - if ( empty( $vat_number ) ) { |
|
| 1691 | - if ( $is_checkout ) { |
|
| 1690 | + if (empty($vat_number)) { |
|
| 1691 | + if ($is_checkout) { |
|
| 1692 | 1692 | $response['success'] = true; |
| 1693 | - $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name ); |
|
| 1693 | + $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name); |
|
| 1694 | 1694 | |
| 1695 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 1695 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 1696 | 1696 | $vat_info['number'] = ""; |
| 1697 | 1697 | $vat_info['valid'] = true; |
| 1698 | 1698 | |
| 1699 | - self::save_user_vat_details( $company ); |
|
| 1699 | + self::save_user_vat_details($company); |
|
| 1700 | 1700 | } else { |
| 1701 | - $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name ); |
|
| 1701 | + $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name); |
|
| 1702 | 1702 | |
| 1703 | 1703 | $vat_info['valid'] = false; |
| 1704 | 1704 | } |
| 1705 | 1705 | |
| 1706 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1707 | - wp_send_json( $response ); |
|
| 1706 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1707 | + wp_send_json($response); |
|
| 1708 | 1708 | } |
| 1709 | 1709 | |
| 1710 | - if ( empty( $company ) ) { |
|
| 1710 | + if (empty($company)) { |
|
| 1711 | 1711 | $vat_info['valid'] = false; |
| 1712 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1712 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1713 | 1713 | |
| 1714 | - $response['error'] = __( 'Please enter your registered company name!', 'invoicing' ); |
|
| 1715 | - wp_send_json( $response ); |
|
| 1714 | + $response['error'] = __('Please enter your registered company name!', 'invoicing'); |
|
| 1715 | + wp_send_json($response); |
|
| 1716 | 1716 | } |
| 1717 | 1717 | |
| 1718 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
| 1719 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
| 1718 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
| 1719 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
| 1720 | 1720 | $vat_info['valid'] = false; |
| 1721 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1721 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1722 | 1722 | |
| 1723 | - $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name ); |
|
| 1724 | - wp_send_json( $response ); |
|
| 1723 | + $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name); |
|
| 1724 | + wp_send_json($response); |
|
| 1725 | 1725 | } |
| 1726 | 1726 | |
| 1727 | 1727 | $response['success'] = true; |
| 1728 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
| 1728 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
| 1729 | 1729 | } else { |
| 1730 | - $result = self::check_vat( $vat_number ); |
|
| 1730 | + $result = self::check_vat($vat_number); |
|
| 1731 | 1731 | |
| 1732 | - if ( empty( $result['valid'] ) ) { |
|
| 1732 | + if (empty($result['valid'])) { |
|
| 1733 | 1733 | $response['error'] = $result['message']; |
| 1734 | - wp_send_json( $response ); |
|
| 1734 | + wp_send_json($response); |
|
| 1735 | 1735 | } |
| 1736 | 1736 | |
| 1737 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
| 1738 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
| 1737 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
| 1738 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
| 1739 | 1739 | |
| 1740 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
| 1740 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
| 1741 | 1741 | |
| 1742 | - if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) { |
|
| 1742 | + if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) { |
|
| 1743 | 1743 | $response['success'] = true; |
| 1744 | - $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name ); |
|
| 1744 | + $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name); |
|
| 1745 | 1745 | } else { |
| 1746 | 1746 | $vat_info['valid'] = false; |
| 1747 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1747 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1748 | 1748 | |
| 1749 | 1749 | $response['success'] = false; |
| 1750 | - $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
| 1751 | - wp_send_json( $response ); |
|
| 1750 | + $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
| 1751 | + wp_send_json($response); |
|
| 1752 | 1752 | } |
| 1753 | 1753 | } |
| 1754 | 1754 | |
| 1755 | - if ( $is_checkout ) { |
|
| 1756 | - self::save_user_vat_details( $company, $vat_number ); |
|
| 1755 | + if ($is_checkout) { |
|
| 1756 | + self::save_user_vat_details($company, $vat_number); |
|
| 1757 | 1757 | |
| 1758 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true ); |
|
| 1759 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1758 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true); |
|
| 1759 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1760 | 1760 | } |
| 1761 | 1761 | |
| 1762 | - wp_send_json( $response ); |
|
| 1762 | + wp_send_json($response); |
|
| 1763 | 1763 | } |
| 1764 | 1764 | |
| 1765 | 1765 | public static function ajax_vat_reset() { |
@@ -1768,161 +1768,161 @@ discard block |
||
| 1768 | 1768 | $company = is_user_logged_in() ? self::get_user_company() : ''; |
| 1769 | 1769 | $vat_number = self::get_user_vat_number(); |
| 1770 | 1770 | |
| 1771 | - $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false ); |
|
| 1772 | - $wpi_session->set( 'user_vat_data', $vat_info ); |
|
| 1771 | + $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => false); |
|
| 1772 | + $wpi_session->set('user_vat_data', $vat_info); |
|
| 1773 | 1773 | |
| 1774 | 1774 | $response = array(); |
| 1775 | 1775 | $response['success'] = true; |
| 1776 | 1776 | $response['data']['company'] = $company; |
| 1777 | 1777 | $response['data']['number'] = $vat_number; |
| 1778 | 1778 | |
| 1779 | - wp_send_json( $response ); |
|
| 1779 | + wp_send_json($response); |
|
| 1780 | 1780 | } |
| 1781 | 1781 | |
| 1782 | - public static function checkout_vat_validate( $valid_data, $post ) { |
|
| 1782 | + public static function checkout_vat_validate($valid_data, $post) { |
|
| 1783 | 1783 | global $wpinv_options, $wpi_session; |
| 1784 | 1784 | |
| 1785 | - $vat_name = __( self::get_vat_name(), 'invoicing' ); |
|
| 1785 | + $vat_name = __(self::get_vat_name(), 'invoicing'); |
|
| 1786 | 1786 | |
| 1787 | - if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) { |
|
| 1788 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) ); |
|
| 1787 | + if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) { |
|
| 1788 | + wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name)); |
|
| 1789 | 1789 | return; |
| 1790 | 1790 | } |
| 1791 | 1791 | |
| 1792 | - $vat_saved = $wpi_session->get( 'user_vat_data' ); |
|
| 1793 | - $wpi_session->set( 'user_vat_data', null ); |
|
| 1792 | + $vat_saved = $wpi_session->get('user_vat_data'); |
|
| 1793 | + $wpi_session->set('user_vat_data', null); |
|
| 1794 | 1794 | |
| 1795 | 1795 | $invoice = wpinv_get_invoice_cart(); |
| 1796 | 1796 | $amount = $invoice->get_total(); |
| 1797 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
| 1798 | - $no_vat = !self::requires_vat( 0, false, $is_digital ); |
|
| 1797 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
| 1798 | + $no_vat = !self::requires_vat(0, false, $is_digital); |
|
| 1799 | 1799 | |
| 1800 | - $company = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null; |
|
| 1801 | - $vat_number = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null; |
|
| 1802 | - $country = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country; |
|
| 1803 | - if ( empty( $country ) ) { |
|
| 1800 | + $company = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null; |
|
| 1801 | + $vat_number = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null; |
|
| 1802 | + $country = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country; |
|
| 1803 | + if (empty($country)) { |
|
| 1804 | 1804 | $country = wpinv_default_billing_country(); |
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | - if ( !$is_digital && $no_vat ) { |
|
| 1807 | + if (!$is_digital && $no_vat) { |
|
| 1808 | 1808 | return; |
| 1809 | 1809 | } |
| 1810 | 1810 | |
| 1811 | - $vat_data = array( 'company' => '', 'number' => '', 'valid' => false ); |
|
| 1811 | + $vat_data = array('company' => '', 'number' => '', 'valid' => false); |
|
| 1812 | 1812 | |
| 1813 | 1813 | $ip_country_code = self::get_country_by_ip(); |
| 1814 | - $is_eu_state = self::is_eu_state( $country ); |
|
| 1815 | - $is_eu_state_ip = self::is_eu_state( $ip_country_code ); |
|
| 1814 | + $is_eu_state = self::is_eu_state($country); |
|
| 1815 | + $is_eu_state_ip = self::is_eu_state($ip_country_code); |
|
| 1816 | 1816 | $is_non_eu_user = !$is_eu_state && !$is_eu_state_ip; |
| 1817 | 1817 | |
| 1818 | - if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) { |
|
| 1818 | + if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) { |
|
| 1819 | 1819 | $vat_data['adddress_confirmed'] = false; |
| 1820 | 1820 | |
| 1821 | - if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) { |
|
| 1822 | - if ( $ip_country_code != $country ) { |
|
| 1823 | - wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) ); |
|
| 1821 | + if (!isset($_POST['wpinv_adddress_confirmed'])) { |
|
| 1822 | + if ($ip_country_code != $country) { |
|
| 1823 | + wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>')); |
|
| 1824 | 1824 | } |
| 1825 | 1825 | } else { |
| 1826 | 1826 | $vat_data['adddress_confirmed'] = true; |
| 1827 | 1827 | } |
| 1828 | 1828 | } |
| 1829 | 1829 | |
| 1830 | - if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) { |
|
| 1831 | - if ( $is_eu_state ) { |
|
| 1832 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) ); |
|
| 1833 | - } else if ( $is_digital && $is_eu_state_ip ) { |
|
| 1834 | - wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) ); |
|
| 1830 | + if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) { |
|
| 1831 | + if ($is_eu_state) { |
|
| 1832 | + wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name)); |
|
| 1833 | + } else if ($is_digital && $is_eu_state_ip) { |
|
| 1834 | + wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name)); |
|
| 1835 | 1835 | } |
| 1836 | 1836 | } |
| 1837 | 1837 | |
| 1838 | - if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) { |
|
| 1838 | + if (!$is_eu_state || $no_vat || empty($vat_number)) { |
|
| 1839 | 1839 | return; |
| 1840 | 1840 | } |
| 1841 | 1841 | |
| 1842 | - if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) { |
|
| 1843 | - $vat_data['valid'] = $vat_saved['valid']; |
|
| 1842 | + if (!empty($vat_saved) && isset($vat_saved['valid'])) { |
|
| 1843 | + $vat_data['valid'] = $vat_saved['valid']; |
|
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | - if ( $company !== null ) { |
|
| 1846 | + if ($company !== null) { |
|
| 1847 | 1847 | $vat_data['company'] = $company; |
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | 1850 | $message = ''; |
| 1851 | - if ( $vat_number !== null ) { |
|
| 1851 | + if ($vat_number !== null) { |
|
| 1852 | 1852 | $vat_data['number'] = $vat_number; |
| 1853 | 1853 | |
| 1854 | - if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) { |
|
| 1855 | - if ( !empty( $wpinv_options['vat_vies_check'] ) ) { |
|
| 1856 | - if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) { |
|
| 1854 | + if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) { |
|
| 1855 | + if (!empty($wpinv_options['vat_vies_check'])) { |
|
| 1856 | + if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) { |
|
| 1857 | 1857 | $vat_data['valid'] = false; |
| 1858 | 1858 | } |
| 1859 | 1859 | } else { |
| 1860 | - $result = self::check_vat( $vat_number ); |
|
| 1860 | + $result = self::check_vat($vat_number); |
|
| 1861 | 1861 | |
| 1862 | - if ( !empty( $result['valid'] ) ) { |
|
| 1862 | + if (!empty($result['valid'])) { |
|
| 1863 | 1863 | $vat_data['valid'] = true; |
| 1864 | - $vies_company = !empty( $result['company'] ) ? $result['company'] : ''; |
|
| 1865 | - $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company ); |
|
| 1864 | + $vies_company = !empty($result['company']) ? $result['company'] : ''; |
|
| 1865 | + $vies_company = apply_filters('wpinv_vies_company_name', $vies_company); |
|
| 1866 | 1866 | |
| 1867 | - $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false; |
|
| 1867 | + $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false; |
|
| 1868 | 1868 | |
| 1869 | - if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) { |
|
| 1869 | + if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) { |
|
| 1870 | 1870 | $vat_data['valid'] = false; |
| 1871 | 1871 | |
| 1872 | - $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name ); |
|
| 1872 | + $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name); |
|
| 1873 | 1873 | } |
| 1874 | 1874 | } else { |
| 1875 | - $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name ); |
|
| 1875 | + $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name); |
|
| 1876 | 1876 | } |
| 1877 | 1877 | } |
| 1878 | 1878 | |
| 1879 | - if ( !$vat_data['valid'] ) { |
|
| 1880 | - $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' ); |
|
| 1881 | - wpinv_set_error( 'vat_validation', $error ); |
|
| 1879 | + if (!$vat_data['valid']) { |
|
| 1880 | + $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : ''); |
|
| 1881 | + wpinv_set_error('vat_validation', $error); |
|
| 1882 | 1882 | } |
| 1883 | 1883 | } |
| 1884 | 1884 | } |
| 1885 | 1885 | |
| 1886 | - $wpi_session->set( 'user_vat_data', $vat_data ); |
|
| 1886 | + $wpi_session->set('user_vat_data', $vat_data); |
|
| 1887 | 1887 | } |
| 1888 | 1888 | |
| 1889 | - public static function checkout_vat_fields( $billing_details ) { |
|
| 1889 | + public static function checkout_vat_fields($billing_details) { |
|
| 1890 | 1890 | global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat; |
| 1891 | 1891 | |
| 1892 | 1892 | $ip_address = wpinv_get_ip(); |
| 1893 | 1893 | $ip_country_code = self::get_country_by_ip(); |
| 1894 | 1894 | |
| 1895 | - $tax_label = __( self::get_vat_name(), 'invoicing' ); |
|
| 1895 | + $tax_label = __(self::get_vat_name(), 'invoicing'); |
|
| 1896 | 1896 | $invoice = wpinv_get_invoice_cart(); |
| 1897 | - $is_digital = self::invoice_has_digital_rule( $invoice ); |
|
| 1897 | + $is_digital = self::invoice_has_digital_rule($invoice); |
|
| 1898 | 1898 | $wpi_country = $invoice->country; |
| 1899 | 1899 | |
| 1900 | - $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital ); |
|
| 1900 | + $requires_vat = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital); |
|
| 1901 | 1901 | $wpi_requires_vat = $requires_vat; |
| 1902 | 1902 | |
| 1903 | 1903 | $company = self::get_user_company(); |
| 1904 | 1904 | $vat_number = self::get_user_vat_number(); |
| 1905 | 1905 | |
| 1906 | - $validated = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1; |
|
| 1907 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 1906 | + $validated = $vat_number ? self::get_user_vat_number('', 0, true) : 1; |
|
| 1907 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 1908 | 1908 | |
| 1909 | - if ( is_array( $vat_info ) ) { |
|
| 1910 | - $company = isset( $vat_info['company'] ) ? $vat_info['company'] : ''; |
|
| 1911 | - $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : ''; |
|
| 1912 | - $validated = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false; |
|
| 1909 | + if (is_array($vat_info)) { |
|
| 1910 | + $company = isset($vat_info['company']) ? $vat_info['company'] : ''; |
|
| 1911 | + $vat_number = isset($vat_info['number']) ? $vat_info['number'] : ''; |
|
| 1912 | + $validated = isset($vat_info['valid']) ? $vat_info['valid'] : false; |
|
| 1913 | 1913 | } |
| 1914 | 1914 | |
| 1915 | 1915 | $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country(); |
| 1916 | 1916 | |
| 1917 | - if ( $ip_country_code == 'UK' ) { |
|
| 1917 | + if ($ip_country_code == 'UK') { |
|
| 1918 | 1918 | $ip_country_code = 'GB'; |
| 1919 | 1919 | } |
| 1920 | 1920 | |
| 1921 | - if ( $selected_country == 'UK' ) { |
|
| 1921 | + if ($selected_country == 'UK') { |
|
| 1922 | 1922 | $selected_country = 'GB'; |
| 1923 | 1923 | } |
| 1924 | 1924 | |
| 1925 | - if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) { |
|
| 1925 | + if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) { |
|
| 1926 | 1926 | $requires_vat = false; |
| 1927 | 1927 | } |
| 1928 | 1928 | |
@@ -1930,52 +1930,52 @@ discard block |
||
| 1930 | 1930 | $display_validate_btn = 'none'; |
| 1931 | 1931 | $display_reset_btn = 'none'; |
| 1932 | 1932 | |
| 1933 | - if ( !empty( $vat_number ) && $validated ) { |
|
| 1934 | - $vat_vailidated_text = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label ); |
|
| 1933 | + if (!empty($vat_number) && $validated) { |
|
| 1934 | + $vat_vailidated_text = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label); |
|
| 1935 | 1935 | $vat_vailidated_class = 'wpinv-vat-stat-1'; |
| 1936 | 1936 | $display_reset_btn = 'block'; |
| 1937 | 1937 | } else { |
| 1938 | - $vat_vailidated_text = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label ); |
|
| 1939 | - $vat_vailidated_class = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0'; |
|
| 1938 | + $vat_vailidated_text = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label); |
|
| 1939 | + $vat_vailidated_class = empty($vat_number) ? '' : 'wpinv-vat-stat-0'; |
|
| 1940 | 1940 | $display_validate_btn = 'block'; |
| 1941 | 1941 | } |
| 1942 | 1942 | |
| 1943 | - $show_ip_country = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
| 1943 | + $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none'; |
|
| 1944 | 1944 | ?> |
| 1945 | 1945 | <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>"> |
| 1946 | 1946 | <div id="wpi_vat_info" class="clearfix panel panel-default"> |
| 1947 | - <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div> |
|
| 1947 | + <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div> |
|
| 1948 | 1948 | <div id="wpinv-fields-box" class="panel-body"> |
| 1949 | 1949 | <p id="wpi_show_vat_note"> |
| 1950 | - <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?> |
|
| 1950 | + <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?> |
|
| 1951 | 1951 | </p> |
| 1952 | 1952 | <div id="wpi_vat_fields" class="wpi_vat_info"> |
| 1953 | 1953 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1954 | - <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label> |
|
| 1954 | + <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label> |
|
| 1955 | 1955 | <?php |
| 1956 | - echo wpinv_html_text( array( |
|
| 1956 | + echo wpinv_html_text(array( |
|
| 1957 | 1957 | 'id' => 'wpinv_company', |
| 1958 | 1958 | 'name' => 'wpinv_company', |
| 1959 | 1959 | 'value' => $company, |
| 1960 | 1960 | 'class' => 'wpi-input form-control', |
| 1961 | - 'placeholder' => __( 'Company name', 'invoicing' ), |
|
| 1962 | - ) ); |
|
| 1961 | + 'placeholder' => __('Company name', 'invoicing'), |
|
| 1962 | + )); |
|
| 1963 | 1963 | ?> |
| 1964 | 1964 | </p> |
| 1965 | 1965 | <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat"> |
| 1966 | - <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label> |
|
| 1966 | + <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label> |
|
| 1967 | 1967 | <span id="wpinv_vat_number-wrap"> |
| 1968 | 1968 | <label for="wpinv_vat_number" class="wpinv-label"></label> |
| 1969 | - <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
| 1970 | - <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text;?></font></span> |
|
| 1969 | + <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number"> |
|
| 1970 | + <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i> <font><?php echo $vat_vailidated_text; ?></font></span> |
|
| 1971 | 1971 | </span> |
| 1972 | 1972 | </p> |
| 1973 | 1973 | <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions"> |
| 1974 | - <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button> |
|
| 1975 | - <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button> |
|
| 1974 | + <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button> |
|
| 1975 | + <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button> |
|
| 1976 | 1976 | <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span> |
| 1977 | 1977 | <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span> |
| 1978 | - <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" /> |
|
| 1978 | + <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" /> |
|
| 1979 | 1979 | </p> |
| 1980 | 1980 | </div> |
| 1981 | 1981 | </div> |
@@ -1989,32 +1989,32 @@ discard block |
||
| 1989 | 1989 | </span> |
| 1990 | 1990 | </div> |
| 1991 | 1991 | </div> |
| 1992 | - <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { |
|
| 1993 | - $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
| 1992 | + <?php if (empty($wpinv_options['hide_ip_address'])) { |
|
| 1993 | + $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . ' <i class="fa fa-external-link-square" aria-hidden="true"></i></a>'; |
|
| 1994 | 1994 | ?> |
| 1995 | 1995 | <div class="wpi-ip-info clearfix panel panel-info"> |
| 1996 | 1996 | <div id="wpinv-fields-box" class="panel-body"> |
| 1997 | - <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span> |
|
| 1997 | + <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span> |
|
| 1998 | 1998 | </div> |
| 1999 | 1999 | </div> |
| 2000 | 2000 | <?php } |
| 2001 | 2001 | } |
| 2002 | 2002 | |
| 2003 | - public static function show_vat_notice( $invoice ) { |
|
| 2004 | - if ( empty( $invoice ) ) { |
|
| 2003 | + public static function show_vat_notice($invoice) { |
|
| 2004 | + if (empty($invoice)) { |
|
| 2005 | 2005 | return NULL; |
| 2006 | 2006 | } |
| 2007 | 2007 | |
| 2008 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
| 2009 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
| 2010 | - if ( $label || $notice ) { |
|
| 2008 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
| 2009 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
| 2010 | + if ($label || $notice) { |
|
| 2011 | 2011 | ?> |
| 2012 | 2012 | <div class="row wpinv-vat-notice"> |
| 2013 | 2013 | <div class="col-sm-12"> |
| 2014 | - <?php if ( $label ) { ?> |
|
| 2015 | - <strong><?php _e( $label, 'invoicing' ); ?></strong> |
|
| 2016 | - <?php } if ( $notice ) { ?> |
|
| 2017 | - <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?> |
|
| 2014 | + <?php if ($label) { ?> |
|
| 2015 | + <strong><?php _e($label, 'invoicing'); ?></strong> |
|
| 2016 | + <?php } if ($notice) { ?> |
|
| 2017 | + <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?> |
|
| 2018 | 2018 | <?php } ?> |
| 2019 | 2019 | </div> |
| 2020 | 2020 | </div> |
@@ -7,15 +7,15 @@ 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_Plugin { |
| 15 | 15 | private static $instance; |
| 16 | 16 | |
| 17 | 17 | public static function run() { |
| 18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
| 18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
| 19 | 19 | self::$instance = new WPInv_Plugin; |
| 20 | 20 | self::$instance->includes(); |
| 21 | 21 | self::$instance->actions(); |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | self::$instance->reports = new WPInv_Reports(); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - do_action( 'wpinv_loaded' ); |
|
| 26 | + do_action('wpinv_loaded'); |
|
| 27 | 27 | |
| 28 | 28 | return self::$instance; |
| 29 | 29 | } |
@@ -33,31 +33,31 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function define_constants() { |
| 36 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 37 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 36 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 37 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | private function actions() { |
| 41 | 41 | /* Internationalize the text strings used. */ |
| 42 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 42 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 43 | 43 | |
| 44 | 44 | /* Perform actions on admin initialization. */ |
| 45 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
| 46 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
| 47 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
| 48 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 45 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
| 46 | + add_action('init', array(&$this, 'init'), 3); |
|
| 47 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
| 48 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
| 49 | 49 | |
| 50 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 51 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 50 | + if (class_exists('BuddyPress')) { |
|
| 51 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 54 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
| 55 | 55 | |
| 56 | - if ( is_admin() ) { |
|
| 57 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
| 58 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
| 56 | + if (is_admin()) { |
|
| 57 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
| 58 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
| 59 | 59 | } else { |
| 60 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 60 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
| 69 | 69 | */ |
| 70 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
| 70 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
| 71 | 71 | |
| 72 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
| 72 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | public function plugins_loaded() { |
@@ -83,200 +83,200 @@ discard block |
||
| 83 | 83 | * @since 1.0 |
| 84 | 84 | */ |
| 85 | 85 | public function load_textdomain() { |
| 86 | - $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' ); |
|
| 86 | + $locale = apply_filters('plugin_locale', get_locale(), 'invoicing'); |
|
| 87 | 87 | |
| 88 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 89 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 88 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
| 89 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | 92 | * Define language constants. |
| 93 | 93 | */ |
| 94 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 94 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | public function includes() { |
| 98 | 98 | global $wpinv_options; |
| 99 | 99 | |
| 100 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 100 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
| 101 | 101 | $wpinv_options = wpinv_get_settings(); |
| 102 | 102 | |
| 103 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
| 104 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 105 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 106 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 107 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
| 111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
| 103 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
| 104 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
| 105 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
| 106 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
| 107 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
| 108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
| 109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
| 110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
| 111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
| 112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
| 113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
| 114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
| 115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
| 116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
| 117 | 117 | //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
| 118 | 118 | //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
| 119 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
| 119 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
| 120 | 120 | //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscription.php' ); |
| 121 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
| 122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
| 123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' ); |
|
| 124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 126 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 127 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
| 128 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 129 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
| 130 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 121 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
| 122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
| 123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php'); |
|
| 124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
| 125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
| 126 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
| 127 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
| 128 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
| 129 | + if (!class_exists('WPInv_EUVat')) { |
|
| 130 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 134 | - if ( !empty( $gateways ) ) { |
|
| 135 | - foreach ( $gateways as $gateway ) { |
|
| 136 | - if ( $gateway == 'manual' ) { |
|
| 133 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 134 | + if (!empty($gateways)) { |
|
| 135 | + foreach ($gateways as $gateway) { |
|
| 136 | + if ($gateway == 'manual') { |
|
| 137 | 137 | continue; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
| 141 | 141 | |
| 142 | - if ( file_exists( $gateway_file ) ) { |
|
| 143 | - require_once( $gateway_file ); |
|
| 142 | + if (file_exists($gateway_file)) { |
|
| 143 | + require_once($gateway_file); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
| 147 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
| 148 | 148 | |
| 149 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 150 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 151 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 152 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
| 149 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 150 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
| 151 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
| 152 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
| 153 | 153 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
| 154 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
| 155 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
| 156 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 157 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
| 158 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 154 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
| 155 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
| 156 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
| 157 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
| 158 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
| 159 | 159 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // include css inliner |
| 163 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 164 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 163 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
| 164 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 167 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | public function init() { |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | public function admin_init() { |
| 174 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
| 174 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
| 177 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | public function activation_redirect() { |
| 181 | 181 | // Bail if no activation redirect |
| 182 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
| 182 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
| 183 | 183 | return; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // Delete the redirect transient |
| 187 | - delete_transient( '_wpinv_activation_redirect' ); |
|
| 187 | + delete_transient('_wpinv_activation_redirect'); |
|
| 188 | 188 | |
| 189 | 189 | // Bail if activating from network, or bulk |
| 190 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 190 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
| 191 | 191 | return; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 194 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
| 195 | 195 | exit; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | public function enqueue_scripts() { |
| 199 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 199 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 200 | 200 | |
| 201 | - wp_deregister_style( 'font-awesome' ); |
|
| 202 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
| 203 | - wp_enqueue_style( 'font-awesome' ); |
|
| 201 | + wp_deregister_style('font-awesome'); |
|
| 202 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
| 203 | + wp_enqueue_style('font-awesome'); |
|
| 204 | 204 | |
| 205 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
| 206 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 205 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
| 206 | + wp_enqueue_style('wpinv_front_style'); |
|
| 207 | 207 | |
| 208 | 208 | // Register scripts |
| 209 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 210 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ), WPINV_VERSION ); |
|
| 209 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 210 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION); |
|
| 211 | 211 | |
| 212 | 212 | $localize = array(); |
| 213 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 214 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 213 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 214 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 215 | 215 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
| 216 | 216 | $localize['currency_pos'] = wpinv_currency_position(); |
| 217 | 217 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 218 | 218 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 219 | 219 | $localize['decimals'] = wpinv_decimals(); |
| 220 | - $localize['txtComplete'] = __( 'Complete', 'invoicing' ); |
|
| 220 | + $localize['txtComplete'] = __('Complete', 'invoicing'); |
|
| 221 | 221 | |
| 222 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 222 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 223 | 223 | |
| 224 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 224 | + wp_enqueue_script('jquery-blockui'); |
|
| 225 | 225 | $autofill_api = wpinv_get_option('address_autofill_api'); |
| 226 | 226 | $autofill_active = wpinv_get_option('address_autofill_active'); |
| 227 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 228 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 229 | - wp_dequeue_script( 'google-maps-api' ); |
|
| 227 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
| 228 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
| 229 | + wp_dequeue_script('google-maps-api'); |
|
| 230 | 230 | } |
| 231 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 232 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 231 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
| 232 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
| 233 | 233 | } |
| 234 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 235 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 234 | + wp_enqueue_script('wpinv-front-script'); |
|
| 235 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | public function admin_enqueue_scripts() { |
| 239 | 239 | global $post, $pagenow; |
| 240 | 240 | |
| 241 | 241 | $post_type = wpinv_admin_post_type(); |
| 242 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 243 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
| 242 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 243 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
| 244 | 244 | |
| 245 | - wp_deregister_style( 'font-awesome' ); |
|
| 246 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
| 247 | - wp_enqueue_style( 'font-awesome' ); |
|
| 245 | + wp_deregister_style('font-awesome'); |
|
| 246 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
| 247 | + wp_enqueue_style('font-awesome'); |
|
| 248 | 248 | |
| 249 | 249 | $jquery_ui_css = false; |
| 250 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
| 250 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
| 251 | 251 | $jquery_ui_css = true; |
| 252 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
| 252 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
| 253 | 253 | $jquery_ui_css = true; |
| 254 | 254 | } |
| 255 | - if ( $jquery_ui_css ) { |
|
| 256 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
| 257 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
| 255 | + if ($jquery_ui_css) { |
|
| 256 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
| 257 | + wp_enqueue_style('jquery-ui-css'); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' ); |
|
| 261 | - wp_enqueue_style( 'jquery-chosen' ); |
|
| 260 | + wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2'); |
|
| 261 | + wp_enqueue_style('jquery-chosen'); |
|
| 262 | 262 | |
| 263 | - wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' ); |
|
| 264 | - wp_enqueue_script( 'jquery-chosen' ); |
|
| 263 | + wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2'); |
|
| 264 | + wp_enqueue_script('jquery-chosen'); |
|
| 265 | 265 | |
| 266 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
| 267 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
| 266 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
| 267 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
| 268 | 268 | |
| 269 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
| 270 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
| 269 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
| 270 | + wp_enqueue_style('wpinv_admin_style'); |
|
| 271 | 271 | |
| 272 | - if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
| 273 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 272 | + if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
| 273 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 277 | - wp_enqueue_script( 'wp-color-picker' ); |
|
| 276 | + wp_enqueue_style('wp-color-picker'); |
|
| 277 | + wp_enqueue_script('wp-color-picker'); |
|
| 278 | 278 | |
| 279 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 279 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 280 | 280 | |
| 281 | 281 | if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
| 282 | 282 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -287,17 +287,17 @@ discard block |
||
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), WPINV_VERSION ); |
|
| 291 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
| 290 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION); |
|
| 291 | + wp_enqueue_script('wpinv-admin-script'); |
|
| 292 | 292 | |
| 293 | 293 | $localize = array(); |
| 294 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 295 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
| 296 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 297 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
| 298 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
| 299 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
| 300 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
| 294 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 295 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
| 296 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 297 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
| 298 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
| 299 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
| 300 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
| 301 | 301 | $localize['tax'] = wpinv_tax_amount(); |
| 302 | 302 | $localize['discount'] = wpinv_discount_amount(); |
| 303 | 303 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -305,60 +305,60 @@ discard block |
||
| 305 | 305 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 306 | 306 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 307 | 307 | $localize['decimals'] = wpinv_decimals(); |
| 308 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
| 309 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
| 310 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
| 311 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
| 312 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
| 313 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
| 314 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
| 315 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
| 316 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
| 317 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
| 308 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
| 309 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
| 310 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
| 311 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
| 312 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
| 313 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
| 314 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
| 315 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
| 316 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
| 317 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
| 318 | 318 | |
| 319 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
| 319 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
| 320 | 320 | |
| 321 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
| 321 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - public function admin_body_class( $classes ) { |
|
| 324 | + public function admin_body_class($classes) { |
|
| 325 | 325 | global $pagenow, $post, $current_screen; |
| 326 | 326 | |
| 327 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
| 327 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) { |
|
| 328 | 328 | $classes .= ' wpinv-cpt'; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
| 331 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
| 332 | 332 | |
| 333 | 333 | $add_class = false; |
| 334 | - if ( $pagenow == 'admin.php' && $page ) { |
|
| 335 | - $add_class = strpos( $page, 'wpinv-' ); |
|
| 334 | + if ($pagenow == 'admin.php' && $page) { |
|
| 335 | + $add_class = strpos($page, 'wpinv-'); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | $settings_class = array(); |
| 339 | - if ( $page == 'wpinv-settings' ) { |
|
| 340 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
| 341 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
| 339 | + if ($page == 'wpinv-settings') { |
|
| 340 | + if (!empty($_REQUEST['tab'])) { |
|
| 341 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
| 345 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
| 344 | + if (!empty($_REQUEST['section'])) { |
|
| 345 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
| 348 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - if ( !empty( $settings_class ) ) { |
|
| 352 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
| 351 | + if (!empty($settings_class)) { |
|
| 352 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | $post_type = wpinv_admin_post_type(); |
| 356 | 356 | |
| 357 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
| 357 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
| 358 | 358 | return $classes .= ' wpinv'; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
| 361 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
| 362 | 362 | $classes .= ' wpi-editable-n'; |
| 363 | 363 | } |
| 364 | 364 | |
@@ -370,20 +370,20 @@ discard block |
||
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | public function wpinv_actions() { |
| 373 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 374 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 373 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 374 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | |
| 378 | - public function pre_get_posts( $wp_query ) { |
|
| 379 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 380 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 378 | + public function pre_get_posts($wp_query) { |
|
| 379 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
| 380 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | return $wp_query; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | public function bp_invoicing_init() { |
| 387 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 387 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | 390 | \ No newline at end of file |
@@ -103,29 +103,29 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
| 105 | 105 | if ( ! empty( $args ) && is_array( $args ) ) { |
| 106 | - extract( $args ); |
|
| 107 | - } |
|
| 106 | + extract( $args ); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
| 110 | - // Allow 3rd party plugin filter template file from their plugin. |
|
| 111 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
| 109 | + $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
| 110 | + // Allow 3rd party plugin filter template file from their plugin. |
|
| 111 | + $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
| 112 | 112 | |
| 113 | - if ( ! file_exists( $located ) ) { |
|
| 113 | + if ( ! file_exists( $located ) ) { |
|
| 114 | 114 | _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
| 115 | - return; |
|
| 116 | - } |
|
| 115 | + return; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
| 118 | + do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
| 119 | 119 | |
| 120 | - include( $located ); |
|
| 120 | + include( $located ); |
|
| 121 | 121 | |
| 122 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
| 122 | + do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
| 126 | - ob_start(); |
|
| 127 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
| 128 | - return ob_get_clean(); |
|
| 126 | + ob_start(); |
|
| 127 | + wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
| 128 | + return ob_get_clean(); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
@@ -155,120 +155,120 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
| 158 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 158 | + do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 159 | 159 | |
| 160 | - // Setup possible parts |
|
| 161 | - $templates = array(); |
|
| 162 | - if ( isset( $name ) ) |
|
| 163 | - $templates[] = $slug . '-' . $name . '.php'; |
|
| 164 | - $templates[] = $slug . '.php'; |
|
| 160 | + // Setup possible parts |
|
| 161 | + $templates = array(); |
|
| 162 | + if ( isset( $name ) ) |
|
| 163 | + $templates[] = $slug . '-' . $name . '.php'; |
|
| 164 | + $templates[] = $slug . '.php'; |
|
| 165 | 165 | |
| 166 | - // Allow template parts to be filtered |
|
| 167 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 166 | + // Allow template parts to be filtered |
|
| 167 | + $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 168 | 168 | |
| 169 | - // Return the part that is found |
|
| 170 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 169 | + // Return the part that is found |
|
| 170 | + return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
| 174 | - // No file found yet |
|
| 175 | - $located = false; |
|
| 174 | + // No file found yet |
|
| 175 | + $located = false; |
|
| 176 | 176 | |
| 177 | - // Try to find a template file |
|
| 178 | - foreach ( (array)$template_names as $template_name ) { |
|
| 177 | + // Try to find a template file |
|
| 178 | + foreach ( (array)$template_names as $template_name ) { |
|
| 179 | 179 | |
| 180 | - // Continue if template is empty |
|
| 181 | - if ( empty( $template_name ) ) |
|
| 182 | - continue; |
|
| 180 | + // Continue if template is empty |
|
| 181 | + if ( empty( $template_name ) ) |
|
| 182 | + continue; |
|
| 183 | 183 | |
| 184 | - // Trim off any slashes from the template name |
|
| 185 | - $template_name = ltrim( $template_name, '/' ); |
|
| 184 | + // Trim off any slashes from the template name |
|
| 185 | + $template_name = ltrim( $template_name, '/' ); |
|
| 186 | 186 | |
| 187 | - // try locating this template file by looping through the template paths |
|
| 188 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 187 | + // try locating this template file by looping through the template paths |
|
| 188 | + foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 189 | 189 | |
| 190 | - if( file_exists( $template_path . $template_name ) ) { |
|
| 191 | - $located = $template_path . $template_name; |
|
| 192 | - break; |
|
| 193 | - } |
|
| 194 | - } |
|
| 190 | + if( file_exists( $template_path . $template_name ) ) { |
|
| 191 | + $located = $template_path . $template_name; |
|
| 192 | + break; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - if( !empty( $located ) ) { |
|
| 197 | - break; |
|
| 198 | - } |
|
| 199 | - } |
|
| 196 | + if( !empty( $located ) ) { |
|
| 197 | + break; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
| 202 | - load_template( $located, $require_once ); |
|
| 201 | + if ( ( true == $load ) && ! empty( $located ) ) |
|
| 202 | + load_template( $located, $require_once ); |
|
| 203 | 203 | |
| 204 | - return $located; |
|
| 204 | + return $located; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | function wpinv_get_theme_template_paths() { |
| 208 | - $template_dir = wpinv_get_theme_template_dir_name(); |
|
| 208 | + $template_dir = wpinv_get_theme_template_dir_name(); |
|
| 209 | 209 | |
| 210 | - $file_paths = array( |
|
| 211 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 212 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 213 | - 100 => wpinv_get_templates_dir() |
|
| 214 | - ); |
|
| 210 | + $file_paths = array( |
|
| 211 | + 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 212 | + 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 213 | + 100 => wpinv_get_templates_dir() |
|
| 214 | + ); |
|
| 215 | 215 | |
| 216 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 216 | + $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 217 | 217 | |
| 218 | - // sort the file paths based on priority |
|
| 219 | - ksort( $file_paths, SORT_NUMERIC ); |
|
| 218 | + // sort the file paths based on priority |
|
| 219 | + ksort( $file_paths, SORT_NUMERIC ); |
|
| 220 | 220 | |
| 221 | - return array_map( 'trailingslashit', $file_paths ); |
|
| 221 | + return array_map( 'trailingslashit', $file_paths ); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | function wpinv_get_theme_template_dir_name() { |
| 225 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
| 225 | + return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | function wpinv_checkout_meta_tags() { |
| 229 | 229 | |
| 230 | - $pages = array(); |
|
| 231 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
| 232 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 233 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 230 | + $pages = array(); |
|
| 231 | + $pages[] = wpinv_get_option( 'success_page' ); |
|
| 232 | + $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 233 | + $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 234 | 234 | |
| 235 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
| 236 | - return; |
|
| 237 | - } |
|
| 235 | + if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
| 236 | + return; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
| 239 | + echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
|
| 240 | 240 | } |
| 241 | 241 | add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
| 242 | 242 | |
| 243 | 243 | function wpinv_add_body_classes( $class ) { |
| 244 | - $classes = (array)$class; |
|
| 244 | + $classes = (array)$class; |
|
| 245 | 245 | |
| 246 | - if( wpinv_is_checkout() ) { |
|
| 247 | - $classes[] = 'wpinv-checkout'; |
|
| 248 | - $classes[] = 'wpinv-page'; |
|
| 249 | - } |
|
| 246 | + if( wpinv_is_checkout() ) { |
|
| 247 | + $classes[] = 'wpinv-checkout'; |
|
| 248 | + $classes[] = 'wpinv-page'; |
|
| 249 | + } |
|
| 250 | 250 | |
| 251 | - if( wpinv_is_success_page() ) { |
|
| 252 | - $classes[] = 'wpinv-success'; |
|
| 253 | - $classes[] = 'wpinv-page'; |
|
| 254 | - } |
|
| 251 | + if( wpinv_is_success_page() ) { |
|
| 252 | + $classes[] = 'wpinv-success'; |
|
| 253 | + $classes[] = 'wpinv-page'; |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - if( wpinv_is_failed_transaction_page() ) { |
|
| 257 | - $classes[] = 'wpinv-failed-transaction'; |
|
| 258 | - $classes[] = 'wpinv-page'; |
|
| 259 | - } |
|
| 256 | + if( wpinv_is_failed_transaction_page() ) { |
|
| 257 | + $classes[] = 'wpinv-failed-transaction'; |
|
| 258 | + $classes[] = 'wpinv-page'; |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - if( wpinv_is_invoice_history_page() ) { |
|
| 262 | - $classes[] = 'wpinv-history'; |
|
| 263 | - $classes[] = 'wpinv-page'; |
|
| 264 | - } |
|
| 261 | + if( wpinv_is_invoice_history_page() ) { |
|
| 262 | + $classes[] = 'wpinv-history'; |
|
| 263 | + $classes[] = 'wpinv-page'; |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - if( wpinv_is_test_mode() ) { |
|
| 267 | - $classes[] = 'wpinv-test-mode'; |
|
| 268 | - $classes[] = 'wpinv-page'; |
|
| 269 | - } |
|
| 266 | + if( wpinv_is_test_mode() ) { |
|
| 267 | + $classes[] = 'wpinv-test-mode'; |
|
| 268 | + $classes[] = 'wpinv-page'; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - return array_unique( $classes ); |
|
| 271 | + return array_unique( $classes ); |
|
| 272 | 272 | } |
| 273 | 273 | add_filter( 'body_class', 'wpinv_add_body_classes' ); |
| 274 | 274 | |
@@ -1404,7 +1404,7 @@ discard block |
||
| 1404 | 1404 | add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
| 1405 | 1405 | |
| 1406 | 1406 | function wpinv_empty_cart_message() { |
| 1407 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1407 | + return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1408 | 1408 | } |
| 1409 | 1409 | |
| 1410 | 1410 | /** |
@@ -1414,7 +1414,7 @@ discard block |
||
| 1414 | 1414 | * @return void |
| 1415 | 1415 | */ |
| 1416 | 1416 | function wpinv_empty_checkout_cart() { |
| 1417 | - echo wpinv_empty_cart_message(); |
|
| 1417 | + echo wpinv_empty_cart_message(); |
|
| 1418 | 1418 | } |
| 1419 | 1419 | add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
| 1420 | 1420 | |
@@ -1552,11 +1552,11 @@ discard block |
||
| 1552 | 1552 | do_action( 'wpinv_payment_mode_before_gateways' ); |
| 1553 | 1553 | |
| 1554 | 1554 | if(!empty($gateways)){ |
| 1555 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
| 1556 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
| 1557 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
| 1558 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
| 1559 | - ?> |
|
| 1555 | + foreach ( $gateways as $gateway_id => $gateway ) { |
|
| 1556 | + $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
| 1557 | + $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
| 1558 | + $description = wpinv_get_gateway_description( $gateway_id ); |
|
| 1559 | + ?> |
|
| 1560 | 1560 | <div class="list-group-item"> |
| 1561 | 1561 | <div class="radio"> |
| 1562 | 1562 | <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
@@ -1569,9 +1569,9 @@ discard block |
||
| 1569 | 1569 | </div> |
| 1570 | 1570 | </div> |
| 1571 | 1571 | <?php |
| 1572 | - } |
|
| 1572 | + } |
|
| 1573 | 1573 | }else{ |
| 1574 | - echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
| 1574 | + echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
| 1575 | 1575 | } |
| 1576 | 1576 | |
| 1577 | 1577 | do_action( 'wpinv_payment_mode_after_gateways' ); |
@@ -7,91 +7,91 @@ 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 | -if ( !is_admin() ) { |
|
| 15 | - add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
| 16 | - add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' ); |
|
| 17 | - add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' ); |
|
| 18 | - add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' ); |
|
| 14 | +if (!is_admin()) { |
|
| 15 | + add_filter('template_include', 'wpinv_template', 10, 1); |
|
| 16 | + add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar'); |
|
| 17 | + add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions'); |
|
| 18 | + add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions'); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | function wpinv_template_path() { |
| 22 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
| 22 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | -function wpinv_display_invoice_top_bar( $invoice ) { |
|
| 26 | - if ( empty( $invoice ) ) { |
|
| 25 | +function wpinv_display_invoice_top_bar($invoice) { |
|
| 26 | + if (empty($invoice)) { |
|
| 27 | 27 | return; |
| 28 | 28 | } |
| 29 | 29 | ?> |
| 30 | 30 | <div class="row wpinv-top-bar no-print"> |
| 31 | 31 | <div class="container"> |
| 32 | 32 | <div class="col-xs-6"> |
| 33 | - <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?> |
|
| 33 | + <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?> |
|
| 34 | 34 | </div> |
| 35 | 35 | <div class="col-xs-6 text-right"> |
| 36 | - <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?> |
|
| 36 | + <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?> |
|
| 37 | 37 | </div> |
| 38 | 38 | </div> |
| 39 | 39 | </div> |
| 40 | 40 | <?php |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | -function wpinv_invoice_display_left_actions( $invoice ) { |
|
| 44 | - if ( empty( $invoice ) ) { |
|
| 43 | +function wpinv_invoice_display_left_actions($invoice) { |
|
| 44 | + if (empty($invoice)) { |
|
| 45 | 45 | return; // Exit if invoice is not set. |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - if ( $invoice->post_type == 'wpi_invoice' ) { |
|
| 49 | - if ( $invoice->needs_payment() ) { |
|
| 50 | - ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a><?php |
|
| 48 | + if ($invoice->post_type == 'wpi_invoice') { |
|
| 49 | + if ($invoice->needs_payment()) { |
|
| 50 | + ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a><?php |
|
| 51 | 51 | } |
| 52 | 52 | } |
| 53 | 53 | do_action('wpinv_invoice_display_left_actions', $invoice); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | -function wpinv_invoice_display_right_actions( $invoice ) { |
|
| 57 | - if ( empty( $invoice ) ) { |
|
| 56 | +function wpinv_invoice_display_right_actions($invoice) { |
|
| 57 | + if (empty($invoice)) { |
|
| 58 | 58 | return; // Exit if invoice is not set. |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - if ( $invoice->post_type == 'wpi_invoice' ) { ?> |
|
| 62 | - <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a> |
|
| 63 | - <?php if ( is_user_logged_in() ) { ?> |
|
| 64 | - <a class="btn btn-warning btn-sm" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a> |
|
| 61 | + if ($invoice->post_type == 'wpi_invoice') { ?> |
|
| 62 | + <a class="btn btn-primary btn-sm" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a> |
|
| 63 | + <?php if (is_user_logged_in()) { ?> |
|
| 64 | + <a class="btn btn-warning btn-sm" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a> |
|
| 65 | 65 | <?php } |
| 66 | 66 | } |
| 67 | 67 | do_action('wpinv_invoice_display_right_actions', $invoice); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | -function wpinv_before_invoice_content( $content ) { |
|
| 70 | +function wpinv_before_invoice_content($content) { |
|
| 71 | 71 | global $post; |
| 72 | 72 | |
| 73 | - if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
| 73 | + if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
| 74 | 74 | ob_start(); |
| 75 | - do_action( 'wpinv_before_invoice_content', $post->ID ); |
|
| 75 | + do_action('wpinv_before_invoice_content', $post->ID); |
|
| 76 | 76 | $content = ob_get_clean() . $content; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | return $content; |
| 80 | 80 | } |
| 81 | -add_filter( 'the_content', 'wpinv_before_invoice_content' ); |
|
| 81 | +add_filter('the_content', 'wpinv_before_invoice_content'); |
|
| 82 | 82 | |
| 83 | -function wpinv_after_invoice_content( $content ) { |
|
| 83 | +function wpinv_after_invoice_content($content) { |
|
| 84 | 84 | global $post; |
| 85 | 85 | |
| 86 | - if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) { |
|
| 86 | + if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) { |
|
| 87 | 87 | ob_start(); |
| 88 | - do_action( 'wpinv_after_invoice_content', $post->ID ); |
|
| 88 | + do_action('wpinv_after_invoice_content', $post->ID); |
|
| 89 | 89 | $content .= ob_get_clean(); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | return $content; |
| 93 | 93 | } |
| 94 | -add_filter( 'the_content', 'wpinv_after_invoice_content' ); |
|
| 94 | +add_filter('the_content', 'wpinv_after_invoice_content'); |
|
| 95 | 95 | |
| 96 | 96 | function wpinv_get_templates_dir() { |
| 97 | 97 | return WPINV_PLUGIN_DIR . 'templates'; |
@@ -101,105 +101,105 @@ discard block |
||
| 101 | 101 | return WPINV_PLUGIN_URL . 'templates'; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 105 | - if ( ! empty( $args ) && is_array( $args ) ) { |
|
| 106 | - extract( $args ); |
|
| 104 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 105 | + if (!empty($args) && is_array($args)) { |
|
| 106 | + extract($args); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - $located = wpinv_locate_template( $template_name, $template_path, $default_path ); |
|
| 109 | + $located = wpinv_locate_template($template_name, $template_path, $default_path); |
|
| 110 | 110 | // Allow 3rd party plugin filter template file from their plugin. |
| 111 | - $located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path ); |
|
| 111 | + $located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path); |
|
| 112 | 112 | |
| 113 | - if ( ! file_exists( $located ) ) { |
|
| 114 | - _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' ); |
|
| 113 | + if (!file_exists($located)) { |
|
| 114 | + _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1'); |
|
| 115 | 115 | return; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args ); |
|
| 118 | + do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args); |
|
| 119 | 119 | |
| 120 | - include( $located ); |
|
| 120 | + include($located); |
|
| 121 | 121 | |
| 122 | - do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args ); |
|
| 122 | + do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
| 125 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
| 126 | 126 | ob_start(); |
| 127 | - wpinv_get_template( $template_name, $args, $template_path, $default_path ); |
|
| 127 | + wpinv_get_template($template_name, $args, $template_path, $default_path); |
|
| 128 | 128 | return ob_get_clean(); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
| 132 | - if ( ! $template_path ) { |
|
| 131 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
| 132 | + if (!$template_path) { |
|
| 133 | 133 | $template_path = wpinv_template_path(); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if ( ! $default_path ) { |
|
| 136 | + if (!$default_path) { |
|
| 137 | 137 | $default_path = WPINV_PLUGIN_DIR . 'templates/'; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | // Look within passed path within the theme - this is priority. |
| 141 | 141 | $template = locate_template( |
| 142 | 142 | array( |
| 143 | - trailingslashit( $template_path ) . $template_name, |
|
| 143 | + trailingslashit($template_path) . $template_name, |
|
| 144 | 144 | $template_name |
| 145 | 145 | ) |
| 146 | 146 | ); |
| 147 | 147 | |
| 148 | 148 | // Get default templates/ |
| 149 | - if ( !$template && $default_path ) { |
|
| 150 | - $template = trailingslashit( $default_path ) . $template_name; |
|
| 149 | + if (!$template && $default_path) { |
|
| 150 | + $template = trailingslashit($default_path) . $template_name; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // Return what we found. |
| 154 | - return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path ); |
|
| 154 | + return apply_filters('wpinv_locate_template', $template, $template_name, $template_path); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
| 158 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
| 157 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
| 158 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
| 159 | 159 | |
| 160 | 160 | // Setup possible parts |
| 161 | 161 | $templates = array(); |
| 162 | - if ( isset( $name ) ) |
|
| 162 | + if (isset($name)) |
|
| 163 | 163 | $templates[] = $slug . '-' . $name . '.php'; |
| 164 | 164 | $templates[] = $slug . '.php'; |
| 165 | 165 | |
| 166 | 166 | // Allow template parts to be filtered |
| 167 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
| 167 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
| 168 | 168 | |
| 169 | 169 | // Return the part that is found |
| 170 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
| 170 | + return wpinv_locate_tmpl($templates, $load, false); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
| 173 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
| 174 | 174 | // No file found yet |
| 175 | 175 | $located = false; |
| 176 | 176 | |
| 177 | 177 | // Try to find a template file |
| 178 | - foreach ( (array)$template_names as $template_name ) { |
|
| 178 | + foreach ((array)$template_names as $template_name) { |
|
| 179 | 179 | |
| 180 | 180 | // Continue if template is empty |
| 181 | - if ( empty( $template_name ) ) |
|
| 181 | + if (empty($template_name)) |
|
| 182 | 182 | continue; |
| 183 | 183 | |
| 184 | 184 | // Trim off any slashes from the template name |
| 185 | - $template_name = ltrim( $template_name, '/' ); |
|
| 185 | + $template_name = ltrim($template_name, '/'); |
|
| 186 | 186 | |
| 187 | 187 | // try locating this template file by looping through the template paths |
| 188 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
| 188 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
| 189 | 189 | |
| 190 | - if( file_exists( $template_path . $template_name ) ) { |
|
| 190 | + if (file_exists($template_path . $template_name)) { |
|
| 191 | 191 | $located = $template_path . $template_name; |
| 192 | 192 | break; |
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - if( !empty( $located ) ) { |
|
| 196 | + if (!empty($located)) { |
|
| 197 | 197 | break; |
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
| 202 | - load_template( $located, $require_once ); |
|
| 201 | + if ((true == $load) && !empty($located)) |
|
| 202 | + load_template($located, $require_once); |
|
| 203 | 203 | |
| 204 | 204 | return $located; |
| 205 | 205 | } |
@@ -208,143 +208,143 @@ discard block |
||
| 208 | 208 | $template_dir = wpinv_get_theme_template_dir_name(); |
| 209 | 209 | |
| 210 | 210 | $file_paths = array( |
| 211 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
| 212 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
| 211 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
| 212 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
| 213 | 213 | 100 => wpinv_get_templates_dir() |
| 214 | 214 | ); |
| 215 | 215 | |
| 216 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
| 216 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
| 217 | 217 | |
| 218 | 218 | // sort the file paths based on priority |
| 219 | - ksort( $file_paths, SORT_NUMERIC ); |
|
| 219 | + ksort($file_paths, SORT_NUMERIC); |
|
| 220 | 220 | |
| 221 | - return array_map( 'trailingslashit', $file_paths ); |
|
| 221 | + return array_map('trailingslashit', $file_paths); |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | function wpinv_get_theme_template_dir_name() { |
| 225 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
| 225 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | function wpinv_checkout_meta_tags() { |
| 229 | 229 | |
| 230 | 230 | $pages = array(); |
| 231 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
| 232 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
| 233 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
| 231 | + $pages[] = wpinv_get_option('success_page'); |
|
| 232 | + $pages[] = wpinv_get_option('failure_page'); |
|
| 233 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
| 234 | 234 | |
| 235 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
| 235 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
| 236 | 236 | return; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
| 240 | 240 | } |
| 241 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
| 241 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
| 242 | 242 | |
| 243 | -function wpinv_add_body_classes( $class ) { |
|
| 243 | +function wpinv_add_body_classes($class) { |
|
| 244 | 244 | $classes = (array)$class; |
| 245 | 245 | |
| 246 | - if( wpinv_is_checkout() ) { |
|
| 246 | + if (wpinv_is_checkout()) { |
|
| 247 | 247 | $classes[] = 'wpinv-checkout'; |
| 248 | 248 | $classes[] = 'wpinv-page'; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - if( wpinv_is_success_page() ) { |
|
| 251 | + if (wpinv_is_success_page()) { |
|
| 252 | 252 | $classes[] = 'wpinv-success'; |
| 253 | 253 | $classes[] = 'wpinv-page'; |
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - if( wpinv_is_failed_transaction_page() ) { |
|
| 256 | + if (wpinv_is_failed_transaction_page()) { |
|
| 257 | 257 | $classes[] = 'wpinv-failed-transaction'; |
| 258 | 258 | $classes[] = 'wpinv-page'; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - if( wpinv_is_invoice_history_page() ) { |
|
| 261 | + if (wpinv_is_invoice_history_page()) { |
|
| 262 | 262 | $classes[] = 'wpinv-history'; |
| 263 | 263 | $classes[] = 'wpinv-page'; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if( wpinv_is_test_mode() ) { |
|
| 266 | + if (wpinv_is_test_mode()) { |
|
| 267 | 267 | $classes[] = 'wpinv-test-mode'; |
| 268 | 268 | $classes[] = 'wpinv-page'; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - return array_unique( $classes ); |
|
| 271 | + return array_unique($classes); |
|
| 272 | 272 | } |
| 273 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
| 273 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
| 274 | 274 | |
| 275 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
| 276 | - $args = array( 'nopaging' => true ); |
|
| 275 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
| 276 | + $args = array('nopaging' => true); |
|
| 277 | 277 | |
| 278 | - if ( ! empty( $status ) ) |
|
| 278 | + if (!empty($status)) |
|
| 279 | 279 | $args['post_status'] = $status; |
| 280 | 280 | |
| 281 | - $discounts = wpinv_get_discounts( $args ); |
|
| 281 | + $discounts = wpinv_get_discounts($args); |
|
| 282 | 282 | $options = array(); |
| 283 | 283 | |
| 284 | - if ( $discounts ) { |
|
| 285 | - foreach ( $discounts as $discount ) { |
|
| 286 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
| 284 | + if ($discounts) { |
|
| 285 | + foreach ($discounts as $discount) { |
|
| 286 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
| 287 | 287 | } |
| 288 | 288 | } else { |
| 289 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
| 289 | + $options[0] = __('No discounts found', 'invoicing'); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - $output = wpinv_html_select( array( |
|
| 292 | + $output = wpinv_html_select(array( |
|
| 293 | 293 | 'name' => $name, |
| 294 | 294 | 'selected' => $selected, |
| 295 | 295 | 'options' => $options, |
| 296 | 296 | 'show_option_all' => false, |
| 297 | 297 | 'show_option_none' => false, |
| 298 | - ) ); |
|
| 298 | + )); |
|
| 299 | 299 | |
| 300 | 300 | return $output; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
| 304 | - $current = date( 'Y' ); |
|
| 305 | - $start_year = $current - absint( $years_before ); |
|
| 306 | - $end_year = $current + absint( $years_after ); |
|
| 307 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
| 303 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
| 304 | + $current = date('Y'); |
|
| 305 | + $start_year = $current - absint($years_before); |
|
| 306 | + $end_year = $current + absint($years_after); |
|
| 307 | + $selected = empty($selected) ? date('Y') : $selected; |
|
| 308 | 308 | $options = array(); |
| 309 | 309 | |
| 310 | - while ( $start_year <= $end_year ) { |
|
| 311 | - $options[ absint( $start_year ) ] = $start_year; |
|
| 310 | + while ($start_year <= $end_year) { |
|
| 311 | + $options[absint($start_year)] = $start_year; |
|
| 312 | 312 | $start_year++; |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | - $output = wpinv_html_select( array( |
|
| 315 | + $output = wpinv_html_select(array( |
|
| 316 | 316 | 'name' => $name, |
| 317 | 317 | 'selected' => $selected, |
| 318 | 318 | 'options' => $options, |
| 319 | 319 | 'show_option_all' => false, |
| 320 | 320 | 'show_option_none' => false |
| 321 | - ) ); |
|
| 321 | + )); |
|
| 322 | 322 | |
| 323 | 323 | return $output; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
| 326 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
| 327 | 327 | $month = 1; |
| 328 | 328 | $options = array(); |
| 329 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
| 329 | + $selected = empty($selected) ? date('n') : $selected; |
|
| 330 | 330 | |
| 331 | - while ( $month <= 12 ) { |
|
| 332 | - $options[ absint( $month ) ] = wpinv_month_num_to_name( $month ); |
|
| 331 | + while ($month <= 12) { |
|
| 332 | + $options[absint($month)] = wpinv_month_num_to_name($month); |
|
| 333 | 333 | $month++; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - $output = wpinv_html_select( array( |
|
| 336 | + $output = wpinv_html_select(array( |
|
| 337 | 337 | 'name' => $name, |
| 338 | 338 | 'selected' => $selected, |
| 339 | 339 | 'options' => $options, |
| 340 | 340 | 'show_option_all' => false, |
| 341 | 341 | 'show_option_none' => false |
| 342 | - ) ); |
|
| 342 | + )); |
|
| 343 | 343 | |
| 344 | 344 | return $output; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | -function wpinv_html_select( $args = array() ) { |
|
| 347 | +function wpinv_html_select($args = array()) { |
|
| 348 | 348 | $defaults = array( |
| 349 | 349 | 'options' => array(), |
| 350 | 350 | 'name' => null, |
@@ -354,8 +354,8 @@ discard block |
||
| 354 | 354 | 'chosen' => false, |
| 355 | 355 | 'placeholder' => null, |
| 356 | 356 | 'multiple' => false, |
| 357 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
| 358 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
| 357 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
| 358 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
| 359 | 359 | 'data' => array(), |
| 360 | 360 | 'onchange' => null, |
| 361 | 361 | 'required' => false, |
@@ -363,78 +363,78 @@ discard block |
||
| 363 | 363 | 'readonly' => false, |
| 364 | 364 | ); |
| 365 | 365 | |
| 366 | - $args = wp_parse_args( $args, $defaults ); |
|
| 366 | + $args = wp_parse_args($args, $defaults); |
|
| 367 | 367 | |
| 368 | 368 | $data_elements = ''; |
| 369 | - foreach ( $args['data'] as $key => $value ) { |
|
| 370 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
| 369 | + foreach ($args['data'] as $key => $value) { |
|
| 370 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - if( $args['multiple'] ) { |
|
| 373 | + if ($args['multiple']) { |
|
| 374 | 374 | $multiple = ' MULTIPLE'; |
| 375 | 375 | } else { |
| 376 | 376 | $multiple = ''; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if( $args['chosen'] ) { |
|
| 379 | + if ($args['chosen']) { |
|
| 380 | 380 | $args['class'] .= ' wpinv-select-chosen'; |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - if( $args['placeholder'] ) { |
|
| 383 | + if ($args['placeholder']) { |
|
| 384 | 384 | $placeholder = $args['placeholder']; |
| 385 | 385 | } else { |
| 386 | 386 | $placeholder = ''; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | 389 | $options = ''; |
| 390 | - if( !empty( $args['onchange'] ) ) { |
|
| 391 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
| 390 | + if (!empty($args['onchange'])) { |
|
| 391 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - if( !empty( $args['required'] ) ) { |
|
| 394 | + if (!empty($args['required'])) { |
|
| 395 | 395 | $options .= ' required="required"'; |
| 396 | 396 | } |
| 397 | 397 | |
| 398 | - if( !empty( $args['disabled'] ) ) { |
|
| 398 | + if (!empty($args['disabled'])) { |
|
| 399 | 399 | $options .= ' disabled'; |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - if( !empty( $args['readonly'] ) ) { |
|
| 402 | + if (!empty($args['readonly'])) { |
|
| 403 | 403 | $options .= ' readonly'; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 407 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
| 406 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 407 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
| 408 | 408 | |
| 409 | - if ( $args['show_option_all'] ) { |
|
| 410 | - if( $args['multiple'] ) { |
|
| 411 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
| 409 | + if ($args['show_option_all']) { |
|
| 410 | + if ($args['multiple']) { |
|
| 411 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
| 412 | 412 | } else { |
| 413 | - $selected = selected( $args['selected'], 0, false ); |
|
| 413 | + $selected = selected($args['selected'], 0, false); |
|
| 414 | 414 | } |
| 415 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
| 415 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | - if ( !empty( $args['options'] ) ) { |
|
| 418 | + if (!empty($args['options'])) { |
|
| 419 | 419 | |
| 420 | - if ( $args['show_option_none'] ) { |
|
| 421 | - if( $args['multiple'] ) { |
|
| 422 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
| 420 | + if ($args['show_option_none']) { |
|
| 421 | + if ($args['multiple']) { |
|
| 422 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
| 423 | 423 | } else { |
| 424 | - $selected = selected( $args['selected'] === "", true, false ); |
|
| 424 | + $selected = selected($args['selected'] === "", true, false); |
|
| 425 | 425 | } |
| 426 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
| 426 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | - foreach( $args['options'] as $key => $option ) { |
|
| 429 | + foreach ($args['options'] as $key => $option) { |
|
| 430 | 430 | |
| 431 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
| 432 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
| 431 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
| 432 | + $selected = selected(true, (bool)in_array($key, $args['selected']), false); |
|
| 433 | 433 | } else { |
| 434 | - $selected = selected( $args['selected'], $key, false ); |
|
| 434 | + $selected = selected($args['selected'], $key, false); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
| 437 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | return $output; |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | -function wpinv_item_dropdown( $args = array() ) { |
|
| 446 | +function wpinv_item_dropdown($args = array()) { |
|
| 447 | 447 | $defaults = array( |
| 448 | 448 | 'name' => 'wpi_item', |
| 449 | 449 | 'id' => 'wpi_item', |
@@ -452,14 +452,14 @@ discard block |
||
| 452 | 452 | 'selected' => 0, |
| 453 | 453 | 'chosen' => false, |
| 454 | 454 | 'number' => 100, |
| 455 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
| 456 | - 'data' => array( 'search-type' => 'item' ), |
|
| 455 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
| 456 | + 'data' => array('search-type' => 'item'), |
|
| 457 | 457 | 'show_option_all' => false, |
| 458 | 458 | 'show_option_none' => false, |
| 459 | 459 | 'show_recurring' => false, |
| 460 | 460 | ); |
| 461 | 461 | |
| 462 | - $args = wp_parse_args( $args, $defaults ); |
|
| 462 | + $args = wp_parse_args($args, $defaults); |
|
| 463 | 463 | |
| 464 | 464 | $item_args = array( |
| 465 | 465 | 'post_type' => 'wpi_item', |
@@ -468,44 +468,44 @@ discard block |
||
| 468 | 468 | 'posts_per_page' => $args['number'] |
| 469 | 469 | ); |
| 470 | 470 | |
| 471 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
| 471 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
| 472 | 472 | |
| 473 | - $items = get_posts( $item_args ); |
|
| 473 | + $items = get_posts($item_args); |
|
| 474 | 474 | $options = array(); |
| 475 | - if ( $items ) { |
|
| 476 | - foreach ( $items as $item ) { |
|
| 477 | - $title = esc_html( $item->post_title ); |
|
| 475 | + if ($items) { |
|
| 476 | + foreach ($items as $item) { |
|
| 477 | + $title = esc_html($item->post_title); |
|
| 478 | 478 | |
| 479 | - if ( !empty( $args['show_recurring'] ) ) { |
|
| 480 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
| 479 | + if (!empty($args['show_recurring'])) { |
|
| 480 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | - $options[ absint( $item->ID ) ] = $title; |
|
| 483 | + $options[absint($item->ID)] = $title; |
|
| 484 | 484 | } |
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | // This ensures that any selected items are included in the drop down |
| 488 | - if( is_array( $args['selected'] ) ) { |
|
| 489 | - foreach( $args['selected'] as $item ) { |
|
| 490 | - if( ! in_array( $item, $options ) ) { |
|
| 491 | - $title = get_the_title( $item ); |
|
| 492 | - if ( !empty( $args['show_recurring'] ) ) { |
|
| 493 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
| 488 | + if (is_array($args['selected'])) { |
|
| 489 | + foreach ($args['selected'] as $item) { |
|
| 490 | + if (!in_array($item, $options)) { |
|
| 491 | + $title = get_the_title($item); |
|
| 492 | + if (!empty($args['show_recurring'])) { |
|
| 493 | + $title .= wpinv_get_item_suffix($item, false); |
|
| 494 | 494 | } |
| 495 | 495 | $options[$item] = $title; |
| 496 | 496 | } |
| 497 | 497 | } |
| 498 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
| 499 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
| 500 | - $title = get_the_title( $args['selected'] ); |
|
| 501 | - if ( !empty( $args['show_recurring'] ) ) { |
|
| 502 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
| 498 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
| 499 | + if (!in_array($args['selected'], $options)) { |
|
| 500 | + $title = get_the_title($args['selected']); |
|
| 501 | + if (!empty($args['show_recurring'])) { |
|
| 502 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
| 503 | 503 | } |
| 504 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
| 504 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
| 505 | 505 | } |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | - $output = wpinv_html_select( array( |
|
| 508 | + $output = wpinv_html_select(array( |
|
| 509 | 509 | 'name' => $args['name'], |
| 510 | 510 | 'selected' => $args['selected'], |
| 511 | 511 | 'id' => $args['id'], |
@@ -517,12 +517,12 @@ discard block |
||
| 517 | 517 | 'show_option_all' => $args['show_option_all'], |
| 518 | 518 | 'show_option_none' => $args['show_option_none'], |
| 519 | 519 | 'data' => $args['data'], |
| 520 | - ) ); |
|
| 520 | + )); |
|
| 521 | 521 | |
| 522 | 522 | return $output; |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | -function wpinv_html_checkbox( $args = array() ) { |
|
| 525 | +function wpinv_html_checkbox($args = array()) { |
|
| 526 | 526 | $defaults = array( |
| 527 | 527 | 'name' => null, |
| 528 | 528 | 'current' => null, |
@@ -533,38 +533,38 @@ discard block |
||
| 533 | 533 | ) |
| 534 | 534 | ); |
| 535 | 535 | |
| 536 | - $args = wp_parse_args( $args, $defaults ); |
|
| 536 | + $args = wp_parse_args($args, $defaults); |
|
| 537 | 537 | |
| 538 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 538 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 539 | 539 | $options = ''; |
| 540 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
| 540 | + if (!empty($args['options']['disabled'])) { |
|
| 541 | 541 | $options .= ' disabled="disabled"'; |
| 542 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
| 542 | + } elseif (!empty($args['options']['readonly'])) { |
|
| 543 | 543 | $options .= ' readonly'; |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
| 546 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
| 547 | 547 | |
| 548 | 548 | return $output; |
| 549 | 549 | } |
| 550 | 550 | |
| 551 | -function wpinv_html_text( $args = array() ) { |
|
| 551 | +function wpinv_html_text($args = array()) { |
|
| 552 | 552 | // Backwards compatibility |
| 553 | - if ( func_num_args() > 1 ) { |
|
| 553 | + if (func_num_args() > 1) { |
|
| 554 | 554 | $args = func_get_args(); |
| 555 | 555 | |
| 556 | 556 | $name = $args[0]; |
| 557 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
| 558 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
| 559 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
| 557 | + $value = isset($args[1]) ? $args[1] : ''; |
|
| 558 | + $label = isset($args[2]) ? $args[2] : ''; |
|
| 559 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | $defaults = array( |
| 563 | 563 | 'id' => '', |
| 564 | - 'name' => isset( $name ) ? $name : 'text', |
|
| 565 | - 'value' => isset( $value ) ? $value : null, |
|
| 566 | - 'label' => isset( $label ) ? $label : null, |
|
| 567 | - 'desc' => isset( $desc ) ? $desc : null, |
|
| 564 | + 'name' => isset($name) ? $name : 'text', |
|
| 565 | + 'value' => isset($value) ? $value : null, |
|
| 566 | + 'label' => isset($label) ? $label : null, |
|
| 567 | + 'desc' => isset($desc) ? $desc : null, |
|
| 568 | 568 | 'placeholder' => '', |
| 569 | 569 | 'class' => 'regular-text', |
| 570 | 570 | 'disabled' => false, |
@@ -574,51 +574,51 @@ discard block |
||
| 574 | 574 | 'data' => false |
| 575 | 575 | ); |
| 576 | 576 | |
| 577 | - $args = wp_parse_args( $args, $defaults ); |
|
| 577 | + $args = wp_parse_args($args, $defaults); |
|
| 578 | 578 | |
| 579 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 579 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 580 | 580 | $options = ''; |
| 581 | - if( $args['required'] ) { |
|
| 581 | + if ($args['required']) { |
|
| 582 | 582 | $options .= ' required="required"'; |
| 583 | 583 | } |
| 584 | - if( $args['readonly'] ) { |
|
| 584 | + if ($args['readonly']) { |
|
| 585 | 585 | $options .= ' readonly'; |
| 586 | 586 | } |
| 587 | - if( $args['readonly'] ) { |
|
| 587 | + if ($args['readonly']) { |
|
| 588 | 588 | $options .= ' readonly'; |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | $data = ''; |
| 592 | - if ( !empty( $args['data'] ) ) { |
|
| 593 | - foreach ( $args['data'] as $key => $value ) { |
|
| 594 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
| 592 | + if (!empty($args['data'])) { |
|
| 593 | + foreach ($args['data'] as $key => $value) { |
|
| 594 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
| 595 | 595 | } |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
| 599 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
| 600 | - if ( ! empty( $args['desc'] ) ) { |
|
| 601 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
| 598 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
| 599 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
| 600 | + if (!empty($args['desc'])) { |
|
| 601 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
| 604 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
| 605 | 605 | |
| 606 | 606 | $output .= '</span>'; |
| 607 | 607 | |
| 608 | 608 | return $output; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | -function wpinv_html_date_field( $args = array() ) { |
|
| 612 | - if( empty( $args['class'] ) ) { |
|
| 611 | +function wpinv_html_date_field($args = array()) { |
|
| 612 | + if (empty($args['class'])) { |
|
| 613 | 613 | $args['class'] = 'wpiDatepicker'; |
| 614 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
| 614 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
| 615 | 615 | $args['class'] .= ' wpiDatepicker'; |
| 616 | 616 | } |
| 617 | 617 | |
| 618 | - return wpinv_html_text( $args ); |
|
| 618 | + return wpinv_html_text($args); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | -function wpinv_html_textarea( $args = array() ) { |
|
| 621 | +function wpinv_html_textarea($args = array()) { |
|
| 622 | 622 | $defaults = array( |
| 623 | 623 | 'name' => 'textarea', |
| 624 | 624 | 'value' => null, |
@@ -628,31 +628,31 @@ discard block |
||
| 628 | 628 | 'disabled' => false |
| 629 | 629 | ); |
| 630 | 630 | |
| 631 | - $args = wp_parse_args( $args, $defaults ); |
|
| 631 | + $args = wp_parse_args($args, $defaults); |
|
| 632 | 632 | |
| 633 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
| 633 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
| 634 | 634 | $disabled = ''; |
| 635 | - if( $args['disabled'] ) { |
|
| 635 | + if ($args['disabled']) { |
|
| 636 | 636 | $disabled = ' disabled="disabled"'; |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
| 640 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
| 641 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
| 639 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
| 640 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
| 641 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
| 642 | 642 | |
| 643 | - if ( ! empty( $args['desc'] ) ) { |
|
| 644 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
| 643 | + if (!empty($args['desc'])) { |
|
| 644 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
| 645 | 645 | } |
| 646 | 646 | $output .= '</span>'; |
| 647 | 647 | |
| 648 | 648 | return $output; |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
| 651 | +function wpinv_html_ajax_user_search($args = array()) { |
|
| 652 | 652 | $defaults = array( |
| 653 | 653 | 'name' => 'user_id', |
| 654 | 654 | 'value' => null, |
| 655 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
| 655 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
| 656 | 656 | 'label' => null, |
| 657 | 657 | 'desc' => null, |
| 658 | 658 | 'class' => '', |
@@ -661,13 +661,13 @@ discard block |
||
| 661 | 661 | 'data' => false |
| 662 | 662 | ); |
| 663 | 663 | |
| 664 | - $args = wp_parse_args( $args, $defaults ); |
|
| 664 | + $args = wp_parse_args($args, $defaults); |
|
| 665 | 665 | |
| 666 | 666 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
| 667 | 667 | |
| 668 | 668 | $output = '<span class="wpinv_user_search_wrap">'; |
| 669 | - $output .= wpinv_html_text( $args ); |
|
| 670 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
| 669 | + $output .= wpinv_html_text($args); |
|
| 670 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
| 671 | 671 | $output .= '</span>'; |
| 672 | 672 | |
| 673 | 673 | return $output; |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | function wpinv_ip_geolocation() { |
| 677 | 677 | global $wpinv_euvat; |
| 678 | 678 | |
| 679 | - $ip = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : ''; |
|
| 679 | + $ip = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : ''; |
|
| 680 | 680 | $content = ''; |
| 681 | 681 | $iso = ''; |
| 682 | 682 | $country = ''; |
@@ -687,69 +687,69 @@ discard block |
||
| 687 | 687 | $credit = ''; |
| 688 | 688 | $address = ''; |
| 689 | 689 | |
| 690 | - if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) { |
|
| 690 | + if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) { |
|
| 691 | 691 | try { |
| 692 | 692 | $iso = $geoip2_city->country->isoCode; |
| 693 | 693 | $country = $geoip2_city->country->name; |
| 694 | - $region = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : ''; |
|
| 694 | + $region = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : ''; |
|
| 695 | 695 | $city = $geoip2_city->city->name; |
| 696 | 696 | $longitude = $geoip2_city->location->longitude; |
| 697 | 697 | $latitude = $geoip2_city->location->latitude; |
| 698 | - $credit = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' ); |
|
| 699 | - } catch( Exception $e ) { } |
|
| 698 | + $credit = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing'); |
|
| 699 | + } catch (Exception $e) { } |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | - if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) { |
|
| 702 | + if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) { |
|
| 703 | 703 | try { |
| 704 | - $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip ); |
|
| 704 | + $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip); |
|
| 705 | 705 | |
| 706 | - if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) { |
|
| 706 | + if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) { |
|
| 707 | 707 | $iso = $load_xml->geoplugin_countryCode; |
| 708 | 708 | $country = $load_xml->geoplugin_countryName; |
| 709 | - $region = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : ''; |
|
| 710 | - $city = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : ''; |
|
| 709 | + $region = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : ''; |
|
| 710 | + $city = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : ''; |
|
| 711 | 711 | $longitude = $load_xml->geoplugin_longitude; |
| 712 | 712 | $latitude = $load_xml->geoplugin_latitude; |
| 713 | 713 | $credit = $load_xml->geoplugin_credit; |
| 714 | - $credit = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit; |
|
| 714 | + $credit = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit; |
|
| 715 | 715 | } |
| 716 | - } catch( Exception $e ) { } |
|
| 716 | + } catch (Exception $e) { } |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - if ( $iso && $longitude && $latitude ) { |
|
| 720 | - if ( $city ) { |
|
| 719 | + if ($iso && $longitude && $latitude) { |
|
| 720 | + if ($city) { |
|
| 721 | 721 | $address .= $city . ', '; |
| 722 | 722 | } |
| 723 | 723 | |
| 724 | - if ( $region ) { |
|
| 724 | + if ($region) { |
|
| 725 | 725 | $address .= $region . ', '; |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | $address .= $country . ' (' . $iso . ')'; |
| 729 | - $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>'; |
|
| 730 | - $content .= '<p>'. $credit . '</p>'; |
|
| 729 | + $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>'; |
|
| 730 | + $content .= '<p>' . $credit . '</p>'; |
|
| 731 | 731 | } else { |
| 732 | - $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>'; |
|
| 732 | + $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>'; |
|
| 733 | 733 | } |
| 734 | 734 | ?> |
| 735 | 735 | <!DOCTYPE html> |
| 736 | -<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
| 736 | +<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head> |
|
| 737 | 737 | <body> |
| 738 | - <?php if ( $latitude && $latitude ) { ?> |
|
| 738 | + <?php if ($latitude && $latitude) { ?> |
|
| 739 | 739 | <div id="map"></div> |
| 740 | 740 | <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script> |
| 741 | 741 | <script type="text/javascript"> |
| 742 | 742 | var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
| 743 | 743 | osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors', |
| 744 | 744 | osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}), |
| 745 | - latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>); |
|
| 745 | + latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>); |
|
| 746 | 746 | |
| 747 | 747 | var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]}); |
| 748 | 748 | |
| 749 | 749 | var marker = new L.Marker(latlng); |
| 750 | 750 | map.addLayer(marker); |
| 751 | 751 | |
| 752 | - marker.bindPopup("<p><?php esc_attr_e( $address );?></p>"); |
|
| 752 | + marker.bindPopup("<p><?php esc_attr_e($address); ?></p>"); |
|
| 753 | 753 | </script> |
| 754 | 754 | <?php } ?> |
| 755 | 755 | <div style="height:100px"><?php echo $content; ?></div> |
@@ -757,18 +757,18 @@ discard block |
||
| 757 | 757 | <?php |
| 758 | 758 | exit; |
| 759 | 759 | } |
| 760 | -add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
| 761 | -add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' ); |
|
| 760 | +add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
| 761 | +add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation'); |
|
| 762 | 762 | |
| 763 | 763 | // Set up the template for the invoice. |
| 764 | -function wpinv_template( $template ) { |
|
| 764 | +function wpinv_template($template) { |
|
| 765 | 765 | global $post, $wp_query; |
| 766 | 766 | |
| 767 | - if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) { |
|
| 768 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
| 769 | - $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
| 767 | + if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) { |
|
| 768 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
| 769 | + $template = wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
| 770 | 770 | } else { |
| 771 | - $template = wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
| 771 | + $template = wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
| 772 | 772 | } |
| 773 | 773 | } |
| 774 | 774 | |
@@ -777,7 +777,7 @@ discard block |
||
| 777 | 777 | |
| 778 | 778 | function wpinv_get_business_address() { |
| 779 | 779 | $business_address = wpinv_store_address(); |
| 780 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
| 780 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
| 781 | 781 | |
| 782 | 782 | /* |
| 783 | 783 | $default_country = wpinv_get_default_country(); |
@@ -801,7 +801,7 @@ discard block |
||
| 801 | 801 | |
| 802 | 802 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
| 803 | 803 | |
| 804 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
| 804 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | function wpinv_display_from_address() { |
@@ -811,187 +811,187 @@ discard block |
||
| 811 | 811 | if (empty($from_name)) { |
| 812 | 812 | $from_name = wpinv_get_business_name(); |
| 813 | 813 | } |
| 814 | - ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div> |
|
| 814 | + ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div> |
|
| 815 | 815 | <div class="wrapper col-xs-10"> |
| 816 | - <div class="name"><?php echo esc_html( $from_name ); ?></div> |
|
| 817 | - <?php if ( $address = wpinv_get_business_address() ) { ?> |
|
| 818 | - <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div> |
|
| 816 | + <div class="name"><?php echo esc_html($from_name); ?></div> |
|
| 817 | + <?php if ($address = wpinv_get_business_address()) { ?> |
|
| 818 | + <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div> |
|
| 819 | 819 | <?php } ?> |
| 820 | - <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?> |
|
| 821 | - <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s', 'invoicing' ), $email_from );?></div> |
|
| 820 | + <?php if ($email_from = wpinv_mail_get_from_address()) { ?> |
|
| 821 | + <div class="email_from"><?php echo wp_sprintf(__('Email: %s', 'invoicing'), $email_from); ?></div> |
|
| 822 | 822 | <?php } ?> |
| 823 | 823 | </div> |
| 824 | 824 | <?php |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | -function wpinv_watermark( $id = 0 ) { |
|
| 828 | - $output = wpinv_get_watermark( $id ); |
|
| 827 | +function wpinv_watermark($id = 0) { |
|
| 828 | + $output = wpinv_get_watermark($id); |
|
| 829 | 829 | |
| 830 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
| 830 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | -function wpinv_get_watermark( $id ) { |
|
| 834 | - if ( !$id > 0 ) { |
|
| 833 | +function wpinv_get_watermark($id) { |
|
| 834 | + if (!$id > 0) { |
|
| 835 | 835 | return NULL; |
| 836 | 836 | } |
| 837 | - $invoice = wpinv_get_invoice( $id ); |
|
| 837 | + $invoice = wpinv_get_invoice($id); |
|
| 838 | 838 | |
| 839 | - if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) { |
|
| 840 | - if ( $invoice->is_paid() ) { |
|
| 841 | - return __( 'Paid', 'invoicing' ); |
|
| 839 | + if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) { |
|
| 840 | + if ($invoice->is_paid()) { |
|
| 841 | + return __('Paid', 'invoicing'); |
|
| 842 | 842 | } |
| 843 | - if ( $invoice->is_refunded() ) { |
|
| 844 | - return __( 'Refunded', 'invoicing' ); |
|
| 843 | + if ($invoice->is_refunded()) { |
|
| 844 | + return __('Refunded', 'invoicing'); |
|
| 845 | 845 | } |
| 846 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
| 847 | - return __( 'Cancelled', 'invoicing' ); |
|
| 846 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
| 847 | + return __('Cancelled', 'invoicing'); |
|
| 848 | 848 | } |
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | return NULL; |
| 852 | 852 | } |
| 853 | 853 | |
| 854 | -function wpinv_display_invoice_details( $invoice ) { |
|
| 854 | +function wpinv_display_invoice_details($invoice) { |
|
| 855 | 855 | global $wpinv_euvat; |
| 856 | 856 | |
| 857 | 857 | $invoice_id = $invoice->ID; |
| 858 | 858 | $vat_name = $wpinv_euvat->get_vat_name(); |
| 859 | 859 | $use_taxes = wpinv_use_taxes(); |
| 860 | 860 | |
| 861 | - $invoice_status = wpinv_get_invoice_status( $invoice_id ); |
|
| 861 | + $invoice_status = wpinv_get_invoice_status($invoice_id); |
|
| 862 | 862 | ?> |
| 863 | 863 | <table class="table table-bordered table-sm"> |
| 864 | - <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?> |
|
| 864 | + <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?> |
|
| 865 | 865 | <tr class="wpi-row-number"> |
| 866 | - <th><?php echo apply_filters( 'wpinv_invoice_number_label', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></th> |
|
| 867 | - <td><?php echo esc_html( $invoice_number ); ?></td> |
|
| 866 | + <th><?php echo apply_filters('wpinv_invoice_number_label', __('Invoice Number', 'invoicing'), $invoice); ?></th> |
|
| 867 | + <td><?php echo esc_html($invoice_number); ?></td> |
|
| 868 | 868 | </tr> |
| 869 | 869 | <?php } ?> |
| 870 | 870 | <tr class="wpi-row-status"> |
| 871 | - <th><?php echo apply_filters( 'wpinv_invoice_status_label', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></th> |
|
| 872 | - <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td> |
|
| 871 | + <th><?php echo apply_filters('wpinv_invoice_status_label', __('Invoice Status', 'invoicing'), $invoice); ?></th> |
|
| 872 | + <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td> |
|
| 873 | 873 | </tr> |
| 874 | - <?php if ( $invoice->is_renewal() ) { ?> |
|
| 874 | + <?php if ($invoice->is_renewal()) { ?> |
|
| 875 | 875 | <tr class="wpi-row-parent"> |
| 876 | - <th><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Parent Invoice', 'invoicing' ), $invoice ); ?></th> |
|
| 877 | - <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td> |
|
| 876 | + <th><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Parent Invoice', 'invoicing'), $invoice); ?></th> |
|
| 877 | + <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td> |
|
| 878 | 878 | </tr> |
| 879 | 879 | <?php } ?> |
| 880 | - <?php if ( ( $gateway_name = wpinv_get_payment_gateway_name( $invoice_id ) ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?> |
|
| 880 | + <?php if (($gateway_name = wpinv_get_payment_gateway_name($invoice_id)) && ($invoice->is_paid() || $invoice->is_refunded())) { ?> |
|
| 881 | 881 | <tr class="wpi-row-gateway"> |
| 882 | - <th><?php echo apply_filters( 'wpinv_invoice_payment_method_label', __( 'Payment Method', 'invoicing' ), $invoice ); ?></th> |
|
| 882 | + <th><?php echo apply_filters('wpinv_invoice_payment_method_label', __('Payment Method', 'invoicing'), $invoice); ?></th> |
|
| 883 | 883 | <td><?php echo $gateway_name; ?></td> |
| 884 | 884 | </tr> |
| 885 | 885 | <?php } ?> |
| 886 | - <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?> |
|
| 886 | + <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?> |
|
| 887 | 887 | <tr class="wpi-row-date"> |
| 888 | - <th><?php echo apply_filters( 'wpinv_invoice_date_label', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></th> |
|
| 888 | + <th><?php echo apply_filters('wpinv_invoice_date_label', __('Invoice Date', 'invoicing'), $invoice); ?></th> |
|
| 889 | 889 | <td><?php echo $invoice_date; ?></td> |
| 890 | 890 | </tr> |
| 891 | 891 | <?php } ?> |
| 892 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?> |
|
| 892 | + <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?> |
|
| 893 | 893 | <tr class="wpi-row-date"> |
| 894 | - <th><?php echo apply_filters( 'wpinv_invoice_due_date_label', __( 'Due Date', 'invoicing' ), $invoice ); ?></th> |
|
| 894 | + <th><?php echo apply_filters('wpinv_invoice_due_date_label', __('Due Date', 'invoicing'), $invoice); ?></th> |
|
| 895 | 895 | <td><?php echo $due_date; ?></td> |
| 896 | 896 | </tr> |
| 897 | 897 | <?php } ?> |
| 898 | - <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?> |
|
| 898 | + <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?> |
|
| 899 | 899 | <tr class="wpi-row-ovatno"> |
| 900 | - <th><?php echo apply_filters( 'wpinv_invoice_owner_vat_number_label', wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th> |
|
| 900 | + <th><?php echo apply_filters('wpinv_invoice_owner_vat_number_label', wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th> |
|
| 901 | 901 | <td><?php echo $owner_vat_number; ?></td> |
| 902 | 902 | </tr> |
| 903 | 903 | <?php } ?> |
| 904 | - <?php if ( $use_taxes && ( $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) ) { ?> |
|
| 904 | + <?php if ($use_taxes && ($user_vat_number = wpinv_get_invoice_vat_number($invoice_id))) { ?> |
|
| 905 | 905 | <tr class="wpi-row-uvatno"> |
| 906 | - <th><?php echo apply_filters( 'wpinv_invoice_user_vat_number_label', wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th> |
|
| 906 | + <th><?php echo apply_filters('wpinv_invoice_user_vat_number_label', wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th> |
|
| 907 | 907 | <td><?php echo $user_vat_number; ?></td> |
| 908 | 908 | </tr> |
| 909 | 909 | <?php } ?> |
| 910 | 910 | <tr class="table-active tr-total wpi-row-total"> |
| 911 | - <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th> |
|
| 912 | - <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td> |
|
| 911 | + <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th> |
|
| 912 | + <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td> |
|
| 913 | 913 | </tr> |
| 914 | 914 | </table> |
| 915 | 915 | <?php |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | -function wpinv_display_to_address( $invoice_id = 0 ) { |
|
| 919 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 918 | +function wpinv_display_to_address($invoice_id = 0) { |
|
| 919 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 920 | 920 | |
| 921 | - if ( empty( $invoice ) ) { |
|
| 921 | + if (empty($invoice)) { |
|
| 922 | 922 | return NULL; |
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | $billing_details = $invoice->get_user_info(); |
| 926 | - $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>'; |
|
| 926 | + $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>'; |
|
| 927 | 927 | $output .= '<div class="wrapper col-xs-10">'; |
| 928 | 928 | |
| 929 | 929 | ob_start(); |
| 930 | - do_action( 'wpinv_display_to_address_top', $invoice ); |
|
| 930 | + do_action('wpinv_display_to_address_top', $invoice); |
|
| 931 | 931 | $output .= ob_get_clean(); |
| 932 | 932 | |
| 933 | - $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>'; |
|
| 934 | - if ( $company = $billing_details['company'] ) { |
|
| 935 | - $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>'; |
|
| 933 | + $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>'; |
|
| 934 | + if ($company = $billing_details['company']) { |
|
| 935 | + $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>'; |
|
| 936 | 936 | } |
| 937 | 937 | $address_row = ''; |
| 938 | - if ( $address = $billing_details['address'] ) { |
|
| 939 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
| 938 | + if ($address = $billing_details['address']) { |
|
| 939 | + $address_row .= wpautop(wp_kses_post($address)); |
|
| 940 | 940 | } |
| 941 | 941 | |
| 942 | 942 | $address_fields = array(); |
| 943 | - if ( !empty( $billing_details['city'] ) ) { |
|
| 943 | + if (!empty($billing_details['city'])) { |
|
| 944 | 944 | $address_fields[] = $billing_details['city']; |
| 945 | 945 | } |
| 946 | 946 | |
| 947 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
| 948 | - if ( !empty( $billing_details['state'] ) ) { |
|
| 949 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
| 947 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
| 948 | + if (!empty($billing_details['state'])) { |
|
| 949 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
| 950 | 950 | } |
| 951 | 951 | |
| 952 | - if ( !empty( $billing_country ) ) { |
|
| 953 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
| 952 | + if (!empty($billing_country)) { |
|
| 953 | + $address_fields[] = wpinv_country_name($billing_country); |
|
| 954 | 954 | } |
| 955 | 955 | |
| 956 | - if ( !empty( $address_fields ) ) { |
|
| 957 | - $address_fields = implode( ", ", $address_fields ); |
|
| 956 | + if (!empty($address_fields)) { |
|
| 957 | + $address_fields = implode(", ", $address_fields); |
|
| 958 | 958 | |
| 959 | - if ( !empty( $billing_details['zip'] ) ) { |
|
| 959 | + if (!empty($billing_details['zip'])) { |
|
| 960 | 960 | $address_fields .= ' ' . $billing_details['zip']; |
| 961 | 961 | } |
| 962 | 962 | |
| 963 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
| 963 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
| 964 | 964 | } |
| 965 | 965 | |
| 966 | - if ( $address_row ) { |
|
| 966 | + if ($address_row) { |
|
| 967 | 967 | $output .= '<div class="address">' . $address_row . '</div>'; |
| 968 | 968 | } |
| 969 | 969 | |
| 970 | - if ( $phone = $invoice->get_phone() ) { |
|
| 971 | - $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>'; |
|
| 970 | + if ($phone = $invoice->get_phone()) { |
|
| 971 | + $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s', 'invoicing'), esc_html($phone)) . '</div>'; |
|
| 972 | 972 | } |
| 973 | - if ( $email = $invoice->get_email() ) { |
|
| 974 | - $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>'; |
|
| 973 | + if ($email = $invoice->get_email()) { |
|
| 974 | + $output .= '<div class="email">' . wp_sprintf(__('Email: %s', 'invoicing'), esc_html($email)) . '</div>'; |
|
| 975 | 975 | } |
| 976 | 976 | |
| 977 | 977 | ob_start(); |
| 978 | - do_action( 'wpinv_display_to_address_bottom', $invoice ); |
|
| 978 | + do_action('wpinv_display_to_address_bottom', $invoice); |
|
| 979 | 979 | $output .= ob_get_clean(); |
| 980 | 980 | |
| 981 | 981 | $output .= '</div>'; |
| 982 | - $output = apply_filters( 'wpinv_display_to_address', $output, $invoice ); |
|
| 982 | + $output = apply_filters('wpinv_display_to_address', $output, $invoice); |
|
| 983 | 983 | |
| 984 | 984 | echo $output; |
| 985 | 985 | } |
| 986 | 986 | |
| 987 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
| 987 | +function wpinv_display_line_items($invoice_id = 0) { |
|
| 988 | 988 | global $wpinv_euvat, $ajax_cart_details; |
| 989 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 989 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 990 | 990 | $quantities_enabled = wpinv_item_quantities_enabled(); |
| 991 | 991 | $use_taxes = wpinv_use_taxes(); |
| 992 | 992 | $zero_tax = !(float)$invoice->get_tax() > 0 ? true : false; |
| 993 | - $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' ); |
|
| 994 | - $tax_title = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : ''; |
|
| 993 | + $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing'); |
|
| 994 | + $tax_title = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : ''; |
|
| 995 | 995 | |
| 996 | 996 | $cart_details = $invoice->get_cart_details(); |
| 997 | 997 | $ajax_cart_details = $cart_details; |
@@ -1000,64 +1000,64 @@ discard block |
||
| 1000 | 1000 | <table class="table table-sm table-bordered table-responsive"> |
| 1001 | 1001 | <thead> |
| 1002 | 1002 | <tr> |
| 1003 | - <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th> |
|
| 1004 | - <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th> |
|
| 1003 | + <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th> |
|
| 1004 | + <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th> |
|
| 1005 | 1005 | <?php if ($quantities_enabled) { ?> |
| 1006 | - <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th> |
|
| 1006 | + <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th> |
|
| 1007 | 1007 | <?php } ?> |
| 1008 | 1008 | <?php if ($use_taxes && !$zero_tax) { ?> |
| 1009 | 1009 | <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th> |
| 1010 | 1010 | <?php } ?> |
| 1011 | - <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th> |
|
| 1011 | + <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th> |
|
| 1012 | 1012 | </tr> |
| 1013 | 1013 | </thead> |
| 1014 | 1014 | <tbody> |
| 1015 | 1015 | <?php |
| 1016 | - if ( !empty( $cart_details ) ) { |
|
| 1017 | - do_action( 'wpinv_display_line_items_start', $invoice ); |
|
| 1016 | + if (!empty($cart_details)) { |
|
| 1017 | + do_action('wpinv_display_line_items_start', $invoice); |
|
| 1018 | 1018 | |
| 1019 | 1019 | $count = 0; |
| 1020 | 1020 | $cols = 3; |
| 1021 | - foreach ( $cart_details as $key => $cart_item ) { |
|
| 1022 | - $item_id = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : ''; |
|
| 1023 | - $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0; |
|
| 1024 | - $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0; |
|
| 1025 | - $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
| 1021 | + foreach ($cart_details as $key => $cart_item) { |
|
| 1022 | + $item_id = !empty($cart_item['id']) ? absint($cart_item['id']) : ''; |
|
| 1023 | + $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0; |
|
| 1024 | + $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0; |
|
| 1025 | + $quantity = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
| 1026 | 1026 | |
| 1027 | - $item = $item_id ? new WPInv_Item( $item_id ) : NULL; |
|
| 1027 | + $item = $item_id ? new WPInv_Item($item_id) : NULL; |
|
| 1028 | 1028 | $summary = ''; |
| 1029 | 1029 | $cols = 3; |
| 1030 | - if ( !empty($item) ) { |
|
| 1030 | + if (!empty($item)) { |
|
| 1031 | 1031 | $item_name = $item->get_name(); |
| 1032 | 1032 | $summary = $item->get_summary(); |
| 1033 | 1033 | } |
| 1034 | - $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
| 1034 | + $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name; |
|
| 1035 | 1035 | |
| 1036 | - $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice ); |
|
| 1036 | + $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice); |
|
| 1037 | 1037 | |
| 1038 | 1038 | $item_tax = ''; |
| 1039 | 1039 | $tax_rate = ''; |
| 1040 | - if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
| 1041 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() ); |
|
| 1042 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
| 1043 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
| 1040 | + if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
| 1041 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency()); |
|
| 1042 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
| 1043 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
| 1044 | 1044 | $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : ''; |
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | $line_item_tax = $item_tax . $tax_rate; |
| 1048 | 1048 | |
| 1049 | - if ( $line_item_tax === '' ) { |
|
| 1049 | + if ($line_item_tax === '') { |
|
| 1050 | 1050 | $line_item_tax = 0; // Zero tax |
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | - $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">'; |
|
| 1054 | - $line_item .= '<td class="name">' . esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item ); |
|
| 1055 | - if ( $summary !== '' ) { |
|
| 1056 | - $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>'; |
|
| 1053 | + $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">'; |
|
| 1054 | + $line_item .= '<td class="name">' . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item); |
|
| 1055 | + if ($summary !== '') { |
|
| 1056 | + $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>'; |
|
| 1057 | 1057 | } |
| 1058 | 1058 | $line_item .= '</td>'; |
| 1059 | 1059 | |
| 1060 | - $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>'; |
|
| 1060 | + $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>'; |
|
| 1061 | 1061 | if ($quantities_enabled) { |
| 1062 | 1062 | $cols++; |
| 1063 | 1063 | $line_item .= '<td class="qty">' . $quantity . '</td>'; |
@@ -1066,55 +1066,55 @@ discard block |
||
| 1066 | 1066 | $cols++; |
| 1067 | 1067 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
| 1068 | 1068 | } |
| 1069 | - $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>'; |
|
| 1069 | + $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>'; |
|
| 1070 | 1070 | $line_item .= '</tr>'; |
| 1071 | 1071 | |
| 1072 | - echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols ); |
|
| 1072 | + echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols); |
|
| 1073 | 1073 | |
| 1074 | 1074 | $count++; |
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | - do_action( 'wpinv_display_before_subtotal', $invoice, $cols ); |
|
| 1077 | + do_action('wpinv_display_before_subtotal', $invoice, $cols); |
|
| 1078 | 1078 | ?> |
| 1079 | 1079 | <tr class="row-sub-total row_odd"> |
| 1080 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
| 1081 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
| 1080 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
| 1081 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
| 1082 | 1082 | </tr> |
| 1083 | 1083 | <?php |
| 1084 | - do_action( 'wpinv_display_after_subtotal', $invoice, $cols ); |
|
| 1084 | + do_action('wpinv_display_after_subtotal', $invoice, $cols); |
|
| 1085 | 1085 | |
| 1086 | - if ( wpinv_discount( $invoice_id, false ) > 0 ) { |
|
| 1087 | - do_action( 'wpinv_display_before_discount', $invoice, $cols ); |
|
| 1086 | + if (wpinv_discount($invoice_id, false) > 0) { |
|
| 1087 | + do_action('wpinv_display_before_discount', $invoice, $cols); |
|
| 1088 | 1088 | ?> |
| 1089 | 1089 | <tr class="row-discount"> |
| 1090 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td> |
|
| 1091 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
| 1090 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td> |
|
| 1091 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
| 1092 | 1092 | </tr> |
| 1093 | 1093 | <?php |
| 1094 | - do_action( 'wpinv_display_after_discount', $invoice, $cols ); |
|
| 1094 | + do_action('wpinv_display_after_discount', $invoice, $cols); |
|
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | - if ( $use_taxes ) { |
|
| 1098 | - do_action( 'wpinv_display_before_tax', $invoice, $cols ); |
|
| 1097 | + if ($use_taxes) { |
|
| 1098 | + do_action('wpinv_display_before_tax', $invoice, $cols); |
|
| 1099 | 1099 | ?> |
| 1100 | 1100 | <tr class="row-tax"> |
| 1101 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td> |
|
| 1102 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
| 1101 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td> |
|
| 1102 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
| 1103 | 1103 | </tr> |
| 1104 | 1104 | <?php |
| 1105 | - do_action( 'wpinv_display_after_tax', $invoice, $cols ); |
|
| 1105 | + do_action('wpinv_display_after_tax', $invoice, $cols); |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | - do_action( 'wpinv_display_before_total', $invoice, $cols ); |
|
| 1108 | + do_action('wpinv_display_before_total', $invoice, $cols); |
|
| 1109 | 1109 | ?> |
| 1110 | 1110 | <tr class="table-active row-total"> |
| 1111 | - <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td> |
|
| 1112 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
| 1111 | + <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td> |
|
| 1112 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
| 1113 | 1113 | </tr> |
| 1114 | 1114 | <?php |
| 1115 | - do_action( 'wpinv_display_after_total', $invoice, $cols ); |
|
| 1115 | + do_action('wpinv_display_after_total', $invoice, $cols); |
|
| 1116 | 1116 | |
| 1117 | - do_action( 'wpinv_display_line_end', $invoice, $cols ); |
|
| 1117 | + do_action('wpinv_display_line_end', $invoice, $cols); |
|
| 1118 | 1118 | } |
| 1119 | 1119 | ?> |
| 1120 | 1120 | </tbody> |
@@ -1123,35 +1123,35 @@ discard block |
||
| 1123 | 1123 | echo ob_get_clean(); |
| 1124 | 1124 | } |
| 1125 | 1125 | |
| 1126 | -function wpinv_display_invoice_totals( $invoice_id = 0 ) { |
|
| 1126 | +function wpinv_display_invoice_totals($invoice_id = 0) { |
|
| 1127 | 1127 | $use_taxes = wpinv_use_taxes(); |
| 1128 | 1128 | |
| 1129 | - do_action( 'wpinv_before_display_totals_table', $invoice_id ); |
|
| 1129 | + do_action('wpinv_before_display_totals_table', $invoice_id); |
|
| 1130 | 1130 | ?> |
| 1131 | 1131 | <table class="table table-sm table-bordered table-responsive"> |
| 1132 | 1132 | <tbody> |
| 1133 | - <?php do_action( 'wpinv_before_display_totals' ); ?> |
|
| 1133 | + <?php do_action('wpinv_before_display_totals'); ?> |
|
| 1134 | 1134 | <tr class="row-sub-total"> |
| 1135 | - <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td> |
|
| 1136 | - <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td> |
|
| 1135 | + <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td> |
|
| 1136 | + <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td> |
|
| 1137 | 1137 | </tr> |
| 1138 | - <?php do_action( 'wpinv_after_display_totals' ); ?> |
|
| 1139 | - <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?> |
|
| 1138 | + <?php do_action('wpinv_after_display_totals'); ?> |
|
| 1139 | + <?php if (wpinv_discount($invoice_id, false) > 0) { ?> |
|
| 1140 | 1140 | <tr class="row-discount"> |
| 1141 | - <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td> |
|
| 1142 | - <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td> |
|
| 1141 | + <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td> |
|
| 1142 | + <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td> |
|
| 1143 | 1143 | </tr> |
| 1144 | - <?php do_action( 'wpinv_after_display_discount' ); ?> |
|
| 1144 | + <?php do_action('wpinv_after_display_discount'); ?> |
|
| 1145 | 1145 | <?php } ?> |
| 1146 | - <?php if ( $use_taxes ) { ?> |
|
| 1146 | + <?php if ($use_taxes) { ?> |
|
| 1147 | 1147 | <tr class="row-tax"> |
| 1148 | - <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td> |
|
| 1149 | - <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td> |
|
| 1148 | + <td class="rate"><?php _e('Tax', 'invoicing'); ?></td> |
|
| 1149 | + <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td> |
|
| 1150 | 1150 | </tr> |
| 1151 | - <?php do_action( 'wpinv_after_display_tax' ); ?> |
|
| 1151 | + <?php do_action('wpinv_after_display_tax'); ?> |
|
| 1152 | 1152 | <?php } ?> |
| 1153 | - <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?> |
|
| 1154 | - <?php foreach ( $fees as $fee ) { ?> |
|
| 1153 | + <?php if ($fees = wpinv_get_fees($invoice_id)) { ?> |
|
| 1154 | + <?php foreach ($fees as $fee) { ?> |
|
| 1155 | 1155 | <tr class="row-fee"> |
| 1156 | 1156 | <td class="rate"><?php echo $fee['label']; ?></td> |
| 1157 | 1157 | <td class="total"><?php echo $fee['amount_display']; ?></td> |
@@ -1159,73 +1159,73 @@ discard block |
||
| 1159 | 1159 | <?php } ?> |
| 1160 | 1160 | <?php } ?> |
| 1161 | 1161 | <tr class="table-active row-total"> |
| 1162 | - <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td> |
|
| 1163 | - <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td> |
|
| 1162 | + <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td> |
|
| 1163 | + <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td> |
|
| 1164 | 1164 | </tr> |
| 1165 | - <?php do_action( 'wpinv_after_totals' ); ?> |
|
| 1165 | + <?php do_action('wpinv_after_totals'); ?> |
|
| 1166 | 1166 | </tbody> |
| 1167 | 1167 | |
| 1168 | 1168 | </table> |
| 1169 | 1169 | |
| 1170 | - <?php do_action( 'wpinv_after_totals_table' ); |
|
| 1170 | + <?php do_action('wpinv_after_totals_table'); |
|
| 1171 | 1171 | } |
| 1172 | 1172 | |
| 1173 | -function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) { |
|
| 1174 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1173 | +function wpinv_display_payments_info($invoice_id = 0, $echo = true) { |
|
| 1174 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1175 | 1175 | |
| 1176 | 1176 | ob_start(); |
| 1177 | - do_action( 'wpinv_before_display_payments_info', $invoice_id ); |
|
| 1178 | - if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) { |
|
| 1177 | + do_action('wpinv_before_display_payments_info', $invoice_id); |
|
| 1178 | + if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) { |
|
| 1179 | 1179 | ?> |
| 1180 | 1180 | <div class="wpi-payment-info"> |
| 1181 | - <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p> |
|
| 1182 | - <?php if ( $gateway_title ) { ?> |
|
| 1183 | - <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p> |
|
| 1181 | + <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p> |
|
| 1182 | + <?php if ($gateway_title) { ?> |
|
| 1183 | + <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p> |
|
| 1184 | 1184 | <?php } ?> |
| 1185 | 1185 | </div> |
| 1186 | 1186 | <?php |
| 1187 | 1187 | } |
| 1188 | - do_action( 'wpinv_after_display_payments_info', $invoice_id ); |
|
| 1188 | + do_action('wpinv_after_display_payments_info', $invoice_id); |
|
| 1189 | 1189 | $outout = ob_get_clean(); |
| 1190 | 1190 | |
| 1191 | - if ( $echo ) { |
|
| 1191 | + if ($echo) { |
|
| 1192 | 1192 | echo $outout; |
| 1193 | 1193 | } else { |
| 1194 | 1194 | return $outout; |
| 1195 | 1195 | } |
| 1196 | 1196 | } |
| 1197 | 1197 | |
| 1198 | -function wpinv_display_style( $invoice ) { |
|
| 1199 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION ); |
|
| 1198 | +function wpinv_display_style($invoice) { |
|
| 1199 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION); |
|
| 1200 | 1200 | |
| 1201 | - wp_print_styles( 'open-sans' ); |
|
| 1202 | - wp_print_styles( 'wpinv-single-style' ); |
|
| 1201 | + wp_print_styles('open-sans'); |
|
| 1202 | + wp_print_styles('wpinv-single-style'); |
|
| 1203 | 1203 | } |
| 1204 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
| 1205 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
| 1204 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
| 1205 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
| 1206 | 1206 | |
| 1207 | 1207 | function wpinv_checkout_billing_details() { |
| 1208 | 1208 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
| 1209 | 1209 | if (empty($invoice_id)) { |
| 1210 | - wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ ); |
|
| 1210 | + wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__); |
|
| 1211 | 1211 | return null; |
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
| 1214 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
| 1215 | 1215 | if (empty($invoice)) { |
| 1216 | - wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ ); |
|
| 1216 | + wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__); |
|
| 1217 | 1217 | return null; |
| 1218 | 1218 | } |
| 1219 | 1219 | $user_id = $invoice->get_user_id(); |
| 1220 | 1220 | $user_info = $invoice->get_user_info(); |
| 1221 | - $address_info = wpinv_get_user_address( $user_id ); |
|
| 1221 | + $address_info = wpinv_get_user_address($user_id); |
|
| 1222 | 1222 | |
| 1223 | - if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) { |
|
| 1223 | + if (empty($user_info['first_name']) && !empty($user_info['first_name'])) { |
|
| 1224 | 1224 | $user_info['first_name'] = $user_info['first_name']; |
| 1225 | 1225 | $user_info['last_name'] = $user_info['last_name']; |
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | - if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) { |
|
| 1228 | + if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) { |
|
| 1229 | 1229 | $user_info['country'] = $address_info['country']; |
| 1230 | 1230 | $user_info['state'] = $address_info['state']; |
| 1231 | 1231 | $user_info['city'] = $address_info['city']; |
@@ -1241,98 +1241,98 @@ discard block |
||
| 1241 | 1241 | 'address' |
| 1242 | 1242 | ); |
| 1243 | 1243 | |
| 1244 | - foreach ( $address_fields as $field ) { |
|
| 1245 | - if ( empty( $user_info[$field] ) ) { |
|
| 1244 | + foreach ($address_fields as $field) { |
|
| 1245 | + if (empty($user_info[$field])) { |
|
| 1246 | 1246 | $user_info[$field] = $address_info[$field]; |
| 1247 | 1247 | } |
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | - return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice ); |
|
| 1250 | + return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice); |
|
| 1251 | 1251 | } |
| 1252 | 1252 | |
| 1253 | 1253 | function wpinv_admin_get_line_items($invoice = array()) { |
| 1254 | 1254 | $item_quantities = wpinv_item_quantities_enabled(); |
| 1255 | 1255 | $use_taxes = wpinv_use_taxes(); |
| 1256 | 1256 | |
| 1257 | - if ( empty( $invoice ) ) { |
|
| 1257 | + if (empty($invoice)) { |
|
| 1258 | 1258 | return NULL; |
| 1259 | 1259 | } |
| 1260 | 1260 | |
| 1261 | 1261 | $cart_items = $invoice->get_cart_details(); |
| 1262 | - if ( empty( $cart_items ) ) { |
|
| 1262 | + if (empty($cart_items)) { |
|
| 1263 | 1263 | return NULL; |
| 1264 | 1264 | } |
| 1265 | 1265 | ob_start(); |
| 1266 | 1266 | |
| 1267 | - do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice ); |
|
| 1267 | + do_action('wpinv_admin_before_line_items', $cart_items, $invoice); |
|
| 1268 | 1268 | |
| 1269 | 1269 | $count = 0; |
| 1270 | - foreach ( $cart_items as $key => $cart_item ) { |
|
| 1270 | + foreach ($cart_items as $key => $cart_item) { |
|
| 1271 | 1271 | $item_id = $cart_item['id']; |
| 1272 | - $wpi_item = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL; |
|
| 1272 | + $wpi_item = $item_id > 0 ? new WPInv_Item($item_id) : NULL; |
|
| 1273 | 1273 | |
| 1274 | 1274 | if (empty($wpi_item)) { |
| 1275 | 1275 | continue; |
| 1276 | 1276 | } |
| 1277 | 1277 | |
| 1278 | - $item_price = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ), $invoice->get_currency() ); |
|
| 1279 | - $quantity = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
| 1280 | - $item_subtotal = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ), $invoice->get_currency() ); |
|
| 1278 | + $item_price = wpinv_price(wpinv_format_amount($cart_item['item_price']), $invoice->get_currency()); |
|
| 1279 | + $quantity = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1; |
|
| 1280 | + $item_subtotal = wpinv_price(wpinv_format_amount($cart_item['subtotal']), $invoice->get_currency()); |
|
| 1281 | 1281 | $can_remove = true; |
| 1282 | 1282 | |
| 1283 | - $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice ); |
|
| 1283 | + $summary = apply_filters('wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice); |
|
| 1284 | 1284 | |
| 1285 | 1285 | $item_tax = ''; |
| 1286 | 1286 | $tax_rate = ''; |
| 1287 | - if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) { |
|
| 1288 | - $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() ); |
|
| 1289 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100; |
|
| 1290 | - $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : ''; |
|
| 1287 | + if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) { |
|
| 1288 | + $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency()); |
|
| 1289 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100; |
|
| 1290 | + $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : ''; |
|
| 1291 | 1291 | $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : ''; |
| 1292 | 1292 | } |
| 1293 | 1293 | $line_item_tax = $item_tax . $tax_rate; |
| 1294 | 1294 | |
| 1295 | - if ( $line_item_tax === '' ) { |
|
| 1295 | + if ($line_item_tax === '') { |
|
| 1296 | 1296 | $line_item_tax = 0; // Zero tax |
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | - $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">'; |
|
| 1299 | + $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">'; |
|
| 1300 | 1300 | $line_item .= '<td class="id">' . $item_id . '</td>'; |
| 1301 | - $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item ); |
|
| 1302 | - if ( $summary !== '' ) { |
|
| 1303 | - $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>'; |
|
| 1301 | + $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item); |
|
| 1302 | + if ($summary !== '') { |
|
| 1303 | + $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>'; |
|
| 1304 | 1304 | } |
| 1305 | 1305 | $line_item .= '</td>'; |
| 1306 | 1306 | $line_item .= '<td class="price">' . $item_price . '</td>'; |
| 1307 | 1307 | |
| 1308 | - if ( $item_quantities ) { |
|
| 1309 | - if ( count( $cart_items ) == 1 && $quantity <= 1 ) { |
|
| 1308 | + if ($item_quantities) { |
|
| 1309 | + if (count($cart_items) == 1 && $quantity <= 1) { |
|
| 1310 | 1310 | $can_remove = false; |
| 1311 | 1311 | } |
| 1312 | 1312 | $line_item .= '<td class="qty" data-quantity="' . $quantity . '"> × ' . $quantity . '</td>'; |
| 1313 | 1313 | } else { |
| 1314 | - if ( count( $cart_items ) == 1 ) { |
|
| 1314 | + if (count($cart_items) == 1) { |
|
| 1315 | 1315 | $can_remove = false; |
| 1316 | 1316 | } |
| 1317 | 1317 | } |
| 1318 | 1318 | $line_item .= '<td class="total">' . $item_subtotal . '</td>'; |
| 1319 | 1319 | |
| 1320 | - if ( $use_taxes ) { |
|
| 1320 | + if ($use_taxes) { |
|
| 1321 | 1321 | $line_item .= '<td class="tax">' . $line_item_tax . '</td>'; |
| 1322 | 1322 | } |
| 1323 | 1323 | $line_item .= '<td class="action">'; |
| 1324 | - if ( !$invoice->is_paid() && !$invoice->is_refunded() && $can_remove ) { |
|
| 1324 | + if (!$invoice->is_paid() && !$invoice->is_refunded() && $can_remove) { |
|
| 1325 | 1325 | $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>'; |
| 1326 | 1326 | } |
| 1327 | 1327 | $line_item .= '</td>'; |
| 1328 | 1328 | $line_item .= '</tr>'; |
| 1329 | 1329 | |
| 1330 | - echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice ); |
|
| 1330 | + echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice); |
|
| 1331 | 1331 | |
| 1332 | 1332 | $count++; |
| 1333 | 1333 | } |
| 1334 | 1334 | |
| 1335 | - do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice ); |
|
| 1335 | + do_action('wpinv_admin_after_line_items', $cart_items, $invoice); |
|
| 1336 | 1336 | |
| 1337 | 1337 | return ob_get_clean(); |
| 1338 | 1338 | } |
@@ -1343,35 +1343,35 @@ discard block |
||
| 1343 | 1343 | // Set current invoice id. |
| 1344 | 1344 | $wpi_checkout_id = wpinv_get_invoice_cart_id(); |
| 1345 | 1345 | |
| 1346 | - $form_action = esc_url( wpinv_get_checkout_uri() ); |
|
| 1346 | + $form_action = esc_url(wpinv_get_checkout_uri()); |
|
| 1347 | 1347 | |
| 1348 | 1348 | ob_start(); |
| 1349 | 1349 | echo '<div id="wpinv_checkout_wrap">'; |
| 1350 | 1350 | |
| 1351 | - if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) { |
|
| 1351 | + if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) { |
|
| 1352 | 1352 | ?> |
| 1353 | 1353 | <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive"> |
| 1354 | - <?php do_action( 'wpinv_before_checkout_form' ); ?> |
|
| 1354 | + <?php do_action('wpinv_before_checkout_form'); ?> |
|
| 1355 | 1355 | <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST"> |
| 1356 | 1356 | <?php |
| 1357 | - do_action( 'wpinv_checkout_form_top' ); |
|
| 1358 | - do_action( 'wpinv_checkout_billing_info' ); |
|
| 1359 | - do_action( 'wpinv_checkout_cart' ); |
|
| 1360 | - do_action( 'wpinv_payment_mode_select' ); |
|
| 1361 | - do_action( 'wpinv_checkout_form_bottom' ) |
|
| 1357 | + do_action('wpinv_checkout_form_top'); |
|
| 1358 | + do_action('wpinv_checkout_billing_info'); |
|
| 1359 | + do_action('wpinv_checkout_cart'); |
|
| 1360 | + do_action('wpinv_payment_mode_select'); |
|
| 1361 | + do_action('wpinv_checkout_form_bottom') |
|
| 1362 | 1362 | ?> |
| 1363 | 1363 | </form> |
| 1364 | - <?php do_action( 'wpinv_after_purchase_form' ); ?> |
|
| 1364 | + <?php do_action('wpinv_after_purchase_form'); ?> |
|
| 1365 | 1365 | </div><!--end #wpinv_checkout_form_wrap--> |
| 1366 | 1366 | <?php |
| 1367 | 1367 | } else { |
| 1368 | - do_action( 'wpinv_cart_empty' ); |
|
| 1368 | + do_action('wpinv_cart_empty'); |
|
| 1369 | 1369 | } |
| 1370 | 1370 | echo '</div><!--end #wpinv_checkout_wrap-->'; |
| 1371 | 1371 | return ob_get_clean(); |
| 1372 | 1372 | } |
| 1373 | 1373 | |
| 1374 | -function wpinv_checkout_cart( $cart_details = array(), $echo = true ) { |
|
| 1374 | +function wpinv_checkout_cart($cart_details = array(), $echo = true) { |
|
| 1375 | 1375 | global $ajax_cart_details; |
| 1376 | 1376 | $ajax_cart_details = $cart_details; |
| 1377 | 1377 | /* |
@@ -1386,25 +1386,25 @@ discard block |
||
| 1386 | 1386 | } |
| 1387 | 1387 | */ |
| 1388 | 1388 | ob_start(); |
| 1389 | - do_action( 'wpinv_before_checkout_cart' ); |
|
| 1389 | + do_action('wpinv_before_checkout_cart'); |
|
| 1390 | 1390 | echo '<div id="wpinv_checkout_cart_form" method="post">'; |
| 1391 | 1391 | echo '<div id="wpinv_checkout_cart_wrap">'; |
| 1392 | - wpinv_get_template_part( 'wpinv-checkout-cart' ); |
|
| 1392 | + wpinv_get_template_part('wpinv-checkout-cart'); |
|
| 1393 | 1393 | echo '</div>'; |
| 1394 | 1394 | echo '</div>'; |
| 1395 | - do_action( 'wpinv_after_checkout_cart' ); |
|
| 1395 | + do_action('wpinv_after_checkout_cart'); |
|
| 1396 | 1396 | $content = ob_get_clean(); |
| 1397 | 1397 | |
| 1398 | - if ( $echo ) { |
|
| 1398 | + if ($echo) { |
|
| 1399 | 1399 | echo $content; |
| 1400 | 1400 | } else { |
| 1401 | 1401 | return $content; |
| 1402 | 1402 | } |
| 1403 | 1403 | } |
| 1404 | -add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 ); |
|
| 1404 | +add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10); |
|
| 1405 | 1405 | |
| 1406 | 1406 | function wpinv_empty_cart_message() { |
| 1407 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
| 1407 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
| 1408 | 1408 | } |
| 1409 | 1409 | |
| 1410 | 1410 | /** |
@@ -1416,91 +1416,91 @@ discard block |
||
| 1416 | 1416 | function wpinv_empty_checkout_cart() { |
| 1417 | 1417 | echo wpinv_empty_cart_message(); |
| 1418 | 1418 | } |
| 1419 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
| 1419 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
| 1420 | 1420 | |
| 1421 | 1421 | function wpinv_save_cart_button() { |
| 1422 | - if ( wpinv_is_cart_saving_disabled() ) |
|
| 1422 | + if (wpinv_is_cart_saving_disabled()) |
|
| 1423 | 1423 | return; |
| 1424 | 1424 | ?> |
| 1425 | - <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a> |
|
| 1425 | + <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a> |
|
| 1426 | 1426 | <?php |
| 1427 | 1427 | } |
| 1428 | 1428 | |
| 1429 | 1429 | function wpinv_update_cart_button() { |
| 1430 | - if ( !wpinv_item_quantities_enabled() ) |
|
| 1430 | + if (!wpinv_item_quantities_enabled()) |
|
| 1431 | 1431 | return; |
| 1432 | 1432 | ?> |
| 1433 | - <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/> |
|
| 1433 | + <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/> |
|
| 1434 | 1434 | <input type="hidden" name="wpi_action" value="update_cart"/> |
| 1435 | 1435 | <?php |
| 1436 | 1436 | } |
| 1437 | 1437 | |
| 1438 | 1438 | function wpinv_checkout_cart_columns() { |
| 1439 | 1439 | $default = 3; |
| 1440 | - if ( wpinv_item_quantities_enabled() ) { |
|
| 1440 | + if (wpinv_item_quantities_enabled()) { |
|
| 1441 | 1441 | $default++; |
| 1442 | 1442 | } |
| 1443 | 1443 | |
| 1444 | - if ( wpinv_use_taxes() ) { |
|
| 1444 | + if (wpinv_use_taxes()) { |
|
| 1445 | 1445 | $default++; |
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | - return apply_filters( 'wpinv_checkout_cart_columns', $default ); |
|
| 1448 | + return apply_filters('wpinv_checkout_cart_columns', $default); |
|
| 1449 | 1449 | } |
| 1450 | 1450 | |
| 1451 | 1451 | function wpinv_display_cart_messages() { |
| 1452 | 1452 | global $wpi_session; |
| 1453 | 1453 | |
| 1454 | - $messages = $wpi_session->get( 'wpinv_cart_messages' ); |
|
| 1454 | + $messages = $wpi_session->get('wpinv_cart_messages'); |
|
| 1455 | 1455 | |
| 1456 | - if ( $messages ) { |
|
| 1457 | - foreach ( $messages as $message_id => $message ) { |
|
| 1456 | + if ($messages) { |
|
| 1457 | + foreach ($messages as $message_id => $message) { |
|
| 1458 | 1458 | // Try and detect what type of message this is |
| 1459 | - if ( strpos( strtolower( $message ), 'error' ) ) { |
|
| 1459 | + if (strpos(strtolower($message), 'error')) { |
|
| 1460 | 1460 | $type = 'error'; |
| 1461 | - } elseif ( strpos( strtolower( $message ), 'success' ) ) { |
|
| 1461 | + } elseif (strpos(strtolower($message), 'success')) { |
|
| 1462 | 1462 | $type = 'success'; |
| 1463 | 1463 | } else { |
| 1464 | 1464 | $type = 'info'; |
| 1465 | 1465 | } |
| 1466 | 1466 | |
| 1467 | - $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) ); |
|
| 1467 | + $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type)); |
|
| 1468 | 1468 | |
| 1469 | - echo '<div class="' . implode( ' ', $classes ) . '">'; |
|
| 1469 | + echo '<div class="' . implode(' ', $classes) . '">'; |
|
| 1470 | 1470 | // Loop message codes and display messages |
| 1471 | 1471 | echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>'; |
| 1472 | 1472 | echo '</div>'; |
| 1473 | 1473 | } |
| 1474 | 1474 | |
| 1475 | 1475 | // Remove all of the cart saving messages |
| 1476 | - $wpi_session->set( 'wpinv_cart_messages', null ); |
|
| 1476 | + $wpi_session->set('wpinv_cart_messages', null); |
|
| 1477 | 1477 | } |
| 1478 | 1478 | } |
| 1479 | -add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' ); |
|
| 1479 | +add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages'); |
|
| 1480 | 1480 | |
| 1481 | 1481 | function wpinv_discount_field() { |
| 1482 | - if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) { |
|
| 1482 | + if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) { |
|
| 1483 | 1483 | return; // Only show before a payment method has been selected if ajax is disabled |
| 1484 | 1484 | } |
| 1485 | 1485 | |
| 1486 | - if ( !wpinv_is_checkout() ) { |
|
| 1486 | + if (!wpinv_is_checkout()) { |
|
| 1487 | 1487 | return; |
| 1488 | 1488 | } |
| 1489 | 1489 | |
| 1490 | - if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) { |
|
| 1490 | + if (wpinv_has_active_discounts() && wpinv_get_cart_total()) { |
|
| 1491 | 1491 | ?> |
| 1492 | 1492 | <div id="wpinv-discount-field" class="panel panel-default"> |
| 1493 | 1493 | <div class="panel-body"> |
| 1494 | 1494 | <p> |
| 1495 | - <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label> |
|
| 1496 | - <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span> |
|
| 1495 | + <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label> |
|
| 1496 | + <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span> |
|
| 1497 | 1497 | </p> |
| 1498 | 1498 | <div class="form-group row"> |
| 1499 | 1499 | <div class="col-sm-4"> |
| 1500 | - <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/> |
|
| 1500 | + <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/> |
|
| 1501 | 1501 | </div> |
| 1502 | 1502 | <div class="col-sm-3"> |
| 1503 | - <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button> |
|
| 1503 | + <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button> |
|
| 1504 | 1504 | </div> |
| 1505 | 1505 | <div style="clear:both"></div> |
| 1506 | 1506 | <div class="col-sm-12 wpinv-discount-msg"> |
@@ -1513,10 +1513,10 @@ discard block |
||
| 1513 | 1513 | <?php |
| 1514 | 1514 | } |
| 1515 | 1515 | } |
| 1516 | -add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 ); |
|
| 1516 | +add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10); |
|
| 1517 | 1517 | |
| 1518 | 1518 | function wpinv_agree_to_terms_js() { |
| 1519 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
| 1519 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
| 1520 | 1520 | ?> |
| 1521 | 1521 | <script type="text/javascript"> |
| 1522 | 1522 | jQuery(document).ready(function($){ |
@@ -1531,126 +1531,126 @@ discard block |
||
| 1531 | 1531 | <?php |
| 1532 | 1532 | } |
| 1533 | 1533 | } |
| 1534 | -add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' ); |
|
| 1534 | +add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js'); |
|
| 1535 | 1535 | |
| 1536 | 1536 | function wpinv_payment_mode_select() { |
| 1537 | - $gateways = wpinv_get_enabled_payment_gateways( true ); |
|
| 1538 | - $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways ); |
|
| 1537 | + $gateways = wpinv_get_enabled_payment_gateways(true); |
|
| 1538 | + $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways); |
|
| 1539 | 1539 | $page_URL = wpinv_get_current_page_url(); |
| 1540 | - $invoice = wpinv_get_invoice( 0, true ); |
|
| 1540 | + $invoice = wpinv_get_invoice(0, true); |
|
| 1541 | 1541 | |
| 1542 | 1542 | do_action('wpinv_payment_mode_top'); |
| 1543 | 1543 | $invoice_id = (int)$invoice->ID; |
| 1544 | - $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id ); |
|
| 1544 | + $chosen_gateway = wpinv_get_chosen_gateway($invoice_id); |
|
| 1545 | 1545 | ?> |
| 1546 | - <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;" data-free="1"' : '' ); ?>> |
|
| 1547 | - <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?> |
|
| 1546 | + <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;" data-free="1"' : ''); ?>> |
|
| 1547 | + <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?> |
|
| 1548 | 1548 | <div id="wpinv-payment-mode-wrap" class="panel panel-default"> |
| 1549 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div> |
|
| 1549 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div> |
|
| 1550 | 1550 | <div class="panel-body list-group wpi-payment_methods"> |
| 1551 | 1551 | <?php |
| 1552 | - do_action( 'wpinv_payment_mode_before_gateways' ); |
|
| 1552 | + do_action('wpinv_payment_mode_before_gateways'); |
|
| 1553 | 1553 | |
| 1554 | - if(!empty($gateways)){ |
|
| 1555 | - foreach ( $gateways as $gateway_id => $gateway ) { |
|
| 1556 | - $checked = checked( $gateway_id, $chosen_gateway, false ); |
|
| 1557 | - $button_label = wpinv_get_gateway_button_label( $gateway_id ); |
|
| 1558 | - $description = wpinv_get_gateway_description( $gateway_id ); |
|
| 1554 | + if (!empty($gateways)) { |
|
| 1555 | + foreach ($gateways as $gateway_id => $gateway) { |
|
| 1556 | + $checked = checked($gateway_id, $chosen_gateway, false); |
|
| 1557 | + $button_label = wpinv_get_gateway_button_label($gateway_id); |
|
| 1558 | + $description = wpinv_get_gateway_description($gateway_id); |
|
| 1559 | 1559 | ?> |
| 1560 | 1560 | <div class="list-group-item"> |
| 1561 | 1561 | <div class="radio"> |
| 1562 | - <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label> |
|
| 1562 | + <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label> |
|
| 1563 | 1563 | </div> |
| 1564 | - <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert"> |
|
| 1565 | - <?php if ( !empty( $description ) ) { ?> |
|
| 1566 | - <div class="wpi-gateway-desc alert alert-info"><?php echo $description;?></div> |
|
| 1564 | + <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert"> |
|
| 1565 | + <?php if (!empty($description)) { ?> |
|
| 1566 | + <div class="wpi-gateway-desc alert alert-info"><?php echo $description; ?></div> |
|
| 1567 | 1567 | <?php } ?> |
| 1568 | - <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?> |
|
| 1568 | + <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?> |
|
| 1569 | 1569 | </div> |
| 1570 | 1570 | </div> |
| 1571 | 1571 | <?php |
| 1572 | 1572 | } |
| 1573 | - }else{ |
|
| 1574 | - echo '<div class="alert alert-warning">'. __('No payment gateway active','invoicing') .'</div>'; |
|
| 1573 | + } else { |
|
| 1574 | + echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>'; |
|
| 1575 | 1575 | } |
| 1576 | 1576 | |
| 1577 | - do_action( 'wpinv_payment_mode_after_gateways' ); |
|
| 1577 | + do_action('wpinv_payment_mode_after_gateways'); |
|
| 1578 | 1578 | ?> |
| 1579 | 1579 | </div> |
| 1580 | 1580 | </div> |
| 1581 | - <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?> |
|
| 1581 | + <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?> |
|
| 1582 | 1582 | </div> |
| 1583 | 1583 | <?php |
| 1584 | 1584 | do_action('wpinv_payment_mode_bottom'); |
| 1585 | 1585 | } |
| 1586 | -add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' ); |
|
| 1586 | +add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select'); |
|
| 1587 | 1587 | |
| 1588 | 1588 | function wpinv_checkout_billing_info() { |
| 1589 | - if ( wpinv_is_checkout() ) { |
|
| 1589 | + if (wpinv_is_checkout()) { |
|
| 1590 | 1590 | $logged_in = is_user_logged_in(); |
| 1591 | 1591 | $billing_details = wpinv_checkout_billing_details(); |
| 1592 | - $selected_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
| 1592 | + $selected_country = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country(); |
|
| 1593 | 1593 | ?> |
| 1594 | 1594 | <div id="wpinv-fields" class="clearfix"> |
| 1595 | 1595 | <div id="wpi-billing" class="wpi-billing clearfix panel panel-default"> |
| 1596 | - <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div> |
|
| 1596 | + <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div> |
|
| 1597 | 1597 | <div id="wpinv-fields-box" class="panel-body"> |
| 1598 | - <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?> |
|
| 1598 | + <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?> |
|
| 1599 | 1599 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1600 | - <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1600 | + <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1601 | 1601 | <?php |
| 1602 | - echo wpinv_html_text( array( |
|
| 1602 | + echo wpinv_html_text(array( |
|
| 1603 | 1603 | 'id' => 'wpinv_first_name', |
| 1604 | 1604 | 'name' => 'wpinv_first_name', |
| 1605 | 1605 | 'value' => $billing_details['first_name'], |
| 1606 | 1606 | 'class' => 'wpi-input form-control', |
| 1607 | - 'placeholder' => __( 'First name', 'invoicing' ), |
|
| 1608 | - 'required' => (bool)wpinv_get_option( 'fname_mandatory' ), |
|
| 1609 | - ) ); |
|
| 1607 | + 'placeholder' => __('First name', 'invoicing'), |
|
| 1608 | + 'required' => (bool)wpinv_get_option('fname_mandatory'), |
|
| 1609 | + )); |
|
| 1610 | 1610 | ?> |
| 1611 | 1611 | </p> |
| 1612 | 1612 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1613 | - <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1613 | + <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1614 | 1614 | <?php |
| 1615 | - echo wpinv_html_text( array( |
|
| 1615 | + echo wpinv_html_text(array( |
|
| 1616 | 1616 | 'id' => 'wpinv_last_name', |
| 1617 | 1617 | 'name' => 'wpinv_last_name', |
| 1618 | 1618 | 'value' => $billing_details['last_name'], |
| 1619 | 1619 | 'class' => 'wpi-input form-control', |
| 1620 | - 'placeholder' => __( 'Last name', 'invoicing' ), |
|
| 1621 | - 'required' => (bool)wpinv_get_option( 'lname_mandatory' ), |
|
| 1622 | - ) ); |
|
| 1620 | + 'placeholder' => __('Last name', 'invoicing'), |
|
| 1621 | + 'required' => (bool)wpinv_get_option('lname_mandatory'), |
|
| 1622 | + )); |
|
| 1623 | 1623 | ?> |
| 1624 | 1624 | </p> |
| 1625 | 1625 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1626 | - <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1626 | + <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1627 | 1627 | <?php |
| 1628 | - echo wpinv_html_text( array( |
|
| 1628 | + echo wpinv_html_text(array( |
|
| 1629 | 1629 | 'id' => 'wpinv_address', |
| 1630 | 1630 | 'name' => 'wpinv_address', |
| 1631 | 1631 | 'value' => $billing_details['address'], |
| 1632 | 1632 | 'class' => 'wpi-input form-control', |
| 1633 | - 'placeholder' => __( 'Address', 'invoicing' ), |
|
| 1634 | - 'required' => (bool)wpinv_get_option( 'address_mandatory' ), |
|
| 1635 | - ) ); |
|
| 1633 | + 'placeholder' => __('Address', 'invoicing'), |
|
| 1634 | + 'required' => (bool)wpinv_get_option('address_mandatory'), |
|
| 1635 | + )); |
|
| 1636 | 1636 | ?> |
| 1637 | 1637 | </p> |
| 1638 | 1638 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1639 | - <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1639 | + <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1640 | 1640 | <?php |
| 1641 | - echo wpinv_html_text( array( |
|
| 1641 | + echo wpinv_html_text(array( |
|
| 1642 | 1642 | 'id' => 'wpinv_city', |
| 1643 | 1643 | 'name' => 'wpinv_city', |
| 1644 | 1644 | 'value' => $billing_details['city'], |
| 1645 | 1645 | 'class' => 'wpi-input form-control', |
| 1646 | - 'placeholder' => __( 'City', 'invoicing' ), |
|
| 1647 | - 'required' => (bool)wpinv_get_option( 'city_mandatory' ), |
|
| 1648 | - ) ); |
|
| 1646 | + 'placeholder' => __('City', 'invoicing'), |
|
| 1647 | + 'required' => (bool)wpinv_get_option('city_mandatory'), |
|
| 1648 | + )); |
|
| 1649 | 1649 | ?> |
| 1650 | 1650 | </p> |
| 1651 | 1651 | <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1652 | - <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1653 | - <?php echo wpinv_html_select( array( |
|
| 1652 | + <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1653 | + <?php echo wpinv_html_select(array( |
|
| 1654 | 1654 | 'options' => wpinv_get_country_list(), |
| 1655 | 1655 | 'name' => 'wpinv_country', |
| 1656 | 1656 | 'id' => 'wpinv_country', |
@@ -1658,16 +1658,16 @@ discard block |
||
| 1658 | 1658 | 'show_option_all' => false, |
| 1659 | 1659 | 'show_option_none' => false, |
| 1660 | 1660 | 'class' => 'wpi-input form-control', |
| 1661 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
| 1662 | - 'required' => (bool)wpinv_get_option( 'country_mandatory' ), |
|
| 1663 | - ) ); ?> |
|
| 1661 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
| 1662 | + 'required' => (bool)wpinv_get_option('country_mandatory'), |
|
| 1663 | + )); ?> |
|
| 1664 | 1664 | </p> |
| 1665 | 1665 | <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1666 | - <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1666 | + <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1667 | 1667 | <?php |
| 1668 | - $states = wpinv_get_country_states( $selected_country ); |
|
| 1669 | - if( !empty( $states ) ) { |
|
| 1670 | - echo wpinv_html_select( array( |
|
| 1668 | + $states = wpinv_get_country_states($selected_country); |
|
| 1669 | + if (!empty($states)) { |
|
| 1670 | + echo wpinv_html_select(array( |
|
| 1671 | 1671 | 'options' => $states, |
| 1672 | 1672 | 'name' => 'wpinv_state', |
| 1673 | 1673 | 'id' => 'wpinv_state', |
@@ -1675,61 +1675,61 @@ discard block |
||
| 1675 | 1675 | 'show_option_all' => false, |
| 1676 | 1676 | 'show_option_none' => false, |
| 1677 | 1677 | 'class' => 'wpi-input form-control', |
| 1678 | - 'placeholder' => __( 'Choose a state', 'invoicing' ), |
|
| 1679 | - 'required' => (bool)wpinv_get_option( 'state_mandatory' ), |
|
| 1680 | - ) ); |
|
| 1678 | + 'placeholder' => __('Choose a state', 'invoicing'), |
|
| 1679 | + 'required' => (bool)wpinv_get_option('state_mandatory'), |
|
| 1680 | + )); |
|
| 1681 | 1681 | } else { |
| 1682 | - echo wpinv_html_text( array( |
|
| 1682 | + echo wpinv_html_text(array( |
|
| 1683 | 1683 | 'name' => 'wpinv_state', |
| 1684 | 1684 | 'value' => $billing_details['state'], |
| 1685 | 1685 | 'id' => 'wpinv_state', |
| 1686 | 1686 | 'class' => 'wpi-input form-control', |
| 1687 | - 'placeholder' => __( 'State / Province', 'invoicing' ), |
|
| 1688 | - 'required' => (bool)wpinv_get_option( 'state_mandatory' ), |
|
| 1689 | - ) ); |
|
| 1687 | + 'placeholder' => __('State / Province', 'invoicing'), |
|
| 1688 | + 'required' => (bool)wpinv_get_option('state_mandatory'), |
|
| 1689 | + )); |
|
| 1690 | 1690 | } |
| 1691 | 1691 | ?> |
| 1692 | 1692 | </p> |
| 1693 | 1693 | <p class="wpi-cart-field wpi-col2 wpi-colf"> |
| 1694 | - <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1694 | + <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1695 | 1695 | <?php |
| 1696 | - echo wpinv_html_text( array( |
|
| 1696 | + echo wpinv_html_text(array( |
|
| 1697 | 1697 | 'name' => 'wpinv_zip', |
| 1698 | 1698 | 'value' => $billing_details['zip'], |
| 1699 | 1699 | 'id' => 'wpinv_zip', |
| 1700 | 1700 | 'class' => 'wpi-input form-control', |
| 1701 | - 'placeholder' => __( 'ZIP / Postcode', 'invoicing' ), |
|
| 1702 | - 'required' => (bool)wpinv_get_option( 'zip_mandatory' ), |
|
| 1703 | - ) ); |
|
| 1701 | + 'placeholder' => __('ZIP / Postcode', 'invoicing'), |
|
| 1702 | + 'required' => (bool)wpinv_get_option('zip_mandatory'), |
|
| 1703 | + )); |
|
| 1704 | 1704 | ?> |
| 1705 | 1705 | </p> |
| 1706 | 1706 | <p class="wpi-cart-field wpi-col2 wpi-coll"> |
| 1707 | - <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1707 | + <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label> |
|
| 1708 | 1708 | <?php |
| 1709 | - echo wpinv_html_text( array( |
|
| 1709 | + echo wpinv_html_text(array( |
|
| 1710 | 1710 | 'id' => 'wpinv_phone', |
| 1711 | 1711 | 'name' => 'wpinv_phone', |
| 1712 | 1712 | 'value' => $billing_details['phone'], |
| 1713 | 1713 | 'class' => 'wpi-input form-control', |
| 1714 | - 'placeholder' => __( 'Phone', 'invoicing' ), |
|
| 1715 | - 'required' => (bool)wpinv_get_option( 'phone_mandatory' ), |
|
| 1716 | - ) ); |
|
| 1714 | + 'placeholder' => __('Phone', 'invoicing'), |
|
| 1715 | + 'required' => (bool)wpinv_get_option('phone_mandatory'), |
|
| 1716 | + )); |
|
| 1717 | 1717 | ?> |
| 1718 | 1718 | </p> |
| 1719 | - <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?> |
|
| 1719 | + <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?> |
|
| 1720 | 1720 | <div class="clearfix"></div> |
| 1721 | 1721 | </div> |
| 1722 | 1722 | </div> |
| 1723 | - <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?> |
|
| 1723 | + <?php do_action('wpinv_after_billing_fields', $billing_details); ?> |
|
| 1724 | 1724 | </div> |
| 1725 | 1725 | <?php |
| 1726 | 1726 | } |
| 1727 | 1727 | } |
| 1728 | -add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' ); |
|
| 1728 | +add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info'); |
|
| 1729 | 1729 | |
| 1730 | 1730 | function wpinv_checkout_hidden_fields() { |
| 1731 | 1731 | ?> |
| 1732 | - <?php if ( is_user_logged_in() ) { ?> |
|
| 1732 | + <?php if (is_user_logged_in()) { ?> |
|
| 1733 | 1733 | <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/> |
| 1734 | 1734 | <?php } ?> |
| 1735 | 1735 | <input type="hidden" name="wpi_action" value="payment" /> |
@@ -1739,9 +1739,9 @@ discard block |
||
| 1739 | 1739 | function wpinv_checkout_button_purchase() { |
| 1740 | 1740 | ob_start(); |
| 1741 | 1741 | ?> |
| 1742 | - <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/> |
|
| 1742 | + <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/> |
|
| 1743 | 1743 | <?php |
| 1744 | - return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() ); |
|
| 1744 | + return apply_filters('wpinv_checkout_button_purchase', ob_get_clean()); |
|
| 1745 | 1745 | } |
| 1746 | 1746 | |
| 1747 | 1747 | function wpinv_checkout_total() { |
@@ -1750,96 +1750,96 @@ discard block |
||
| 1750 | 1750 | <div id="wpinv_checkout_total" class="panel panel-info"> |
| 1751 | 1751 | <div class="panel-body"> |
| 1752 | 1752 | <?php |
| 1753 | - do_action( 'wpinv_purchase_form_before_checkout_total' ); |
|
| 1753 | + do_action('wpinv_purchase_form_before_checkout_total'); |
|
| 1754 | 1754 | ?> |
| 1755 | - <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span> |
|
| 1755 | + <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span> |
|
| 1756 | 1756 | <?php |
| 1757 | - do_action( 'wpinv_purchase_form_after_checkout_total' ); |
|
| 1757 | + do_action('wpinv_purchase_form_after_checkout_total'); |
|
| 1758 | 1758 | ?> |
| 1759 | 1759 | </div> |
| 1760 | 1760 | </div> |
| 1761 | 1761 | <?php |
| 1762 | 1762 | } |
| 1763 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 ); |
|
| 1763 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998); |
|
| 1764 | 1764 | |
| 1765 | 1765 | function wpinv_checkout_submit() { |
| 1766 | 1766 | ?> |
| 1767 | 1767 | <div id="wpinv_purchase_submit" class="panel panel-success"> |
| 1768 | 1768 | <div class="panel-body text-center"> |
| 1769 | 1769 | <?php |
| 1770 | - do_action( 'wpinv_purchase_form_before_submit' ); |
|
| 1770 | + do_action('wpinv_purchase_form_before_submit'); |
|
| 1771 | 1771 | wpinv_checkout_hidden_fields(); |
| 1772 | 1772 | echo wpinv_checkout_button_purchase(); |
| 1773 | - do_action( 'wpinv_purchase_form_after_submit' ); |
|
| 1773 | + do_action('wpinv_purchase_form_after_submit'); |
|
| 1774 | 1774 | ?> |
| 1775 | 1775 | </div> |
| 1776 | 1776 | </div> |
| 1777 | 1777 | <?php |
| 1778 | 1778 | } |
| 1779 | -add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 ); |
|
| 1779 | +add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999); |
|
| 1780 | 1780 | |
| 1781 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
| 1782 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1781 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
| 1782 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1783 | 1783 | |
| 1784 | - if ( empty( $invoice ) ) { |
|
| 1784 | + if (empty($invoice)) { |
|
| 1785 | 1785 | return NULL; |
| 1786 | 1786 | } |
| 1787 | 1787 | |
| 1788 | 1788 | $billing_details = $invoice->get_user_info(); |
| 1789 | 1789 | $address_row = ''; |
| 1790 | - if ( $address = $billing_details['address'] ) { |
|
| 1791 | - $address_row .= wpautop( wp_kses_post( $address ) ); |
|
| 1790 | + if ($address = $billing_details['address']) { |
|
| 1791 | + $address_row .= wpautop(wp_kses_post($address)); |
|
| 1792 | 1792 | } |
| 1793 | 1793 | |
| 1794 | 1794 | $address_fields = array(); |
| 1795 | - if ( !empty( $billing_details['city'] ) ) { |
|
| 1795 | + if (!empty($billing_details['city'])) { |
|
| 1796 | 1796 | $address_fields[] = $billing_details['city']; |
| 1797 | 1797 | } |
| 1798 | 1798 | |
| 1799 | - $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : ''; |
|
| 1800 | - if ( !empty( $billing_details['state'] ) ) { |
|
| 1801 | - $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country ); |
|
| 1799 | + $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : ''; |
|
| 1800 | + if (!empty($billing_details['state'])) { |
|
| 1801 | + $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country); |
|
| 1802 | 1802 | } |
| 1803 | 1803 | |
| 1804 | - if ( !empty( $billing_country ) ) { |
|
| 1805 | - $address_fields[] = wpinv_country_name( $billing_country ); |
|
| 1804 | + if (!empty($billing_country)) { |
|
| 1805 | + $address_fields[] = wpinv_country_name($billing_country); |
|
| 1806 | 1806 | } |
| 1807 | 1807 | |
| 1808 | - if ( !empty( $address_fields ) ) { |
|
| 1809 | - $address_fields = implode( ", ", $address_fields ); |
|
| 1808 | + if (!empty($address_fields)) { |
|
| 1809 | + $address_fields = implode(", ", $address_fields); |
|
| 1810 | 1810 | |
| 1811 | - if ( !empty( $billing_details['zip'] ) ) { |
|
| 1811 | + if (!empty($billing_details['zip'])) { |
|
| 1812 | 1812 | $address_fields .= ' ' . $billing_details['zip']; |
| 1813 | 1813 | } |
| 1814 | 1814 | |
| 1815 | - $address_row .= wpautop( wp_kses_post( $address_fields ) ); |
|
| 1815 | + $address_row .= wpautop(wp_kses_post($address_fields)); |
|
| 1816 | 1816 | } |
| 1817 | 1817 | ob_start(); |
| 1818 | 1818 | ?> |
| 1819 | 1819 | <table class="table table-bordered table-sm wpi-billing-details"> |
| 1820 | 1820 | <tbody> |
| 1821 | 1821 | <tr class="wpi-receipt-name"> |
| 1822 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
| 1823 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
| 1822 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
| 1823 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
| 1824 | 1824 | </tr> |
| 1825 | 1825 | <tr class="wpi-receipt-email"> |
| 1826 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
| 1827 | - <td><?php echo $billing_details['email'] ;?></td> |
|
| 1826 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
| 1827 | + <td><?php echo $billing_details['email']; ?></td> |
|
| 1828 | 1828 | </tr> |
| 1829 | - <?php if ( $billing_details['company'] ) { ?> |
|
| 1829 | + <?php if ($billing_details['company']) { ?> |
|
| 1830 | 1830 | <tr class="wpi-receipt-company"> |
| 1831 | - <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th> |
|
| 1832 | - <td><?php echo esc_html( $billing_details['company'] ) ;?></td> |
|
| 1831 | + <th class="text-left"><?php _e('Company', 'invoicing'); ?></th> |
|
| 1832 | + <td><?php echo esc_html($billing_details['company']); ?></td> |
|
| 1833 | 1833 | </tr> |
| 1834 | 1834 | <?php } ?> |
| 1835 | 1835 | <tr class="wpi-receipt-address"> |
| 1836 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
| 1837 | - <td><?php echo $address_row ;?></td> |
|
| 1836 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
| 1837 | + <td><?php echo $address_row; ?></td> |
|
| 1838 | 1838 | </tr> |
| 1839 | - <?php if ( $billing_details['phone'] ) { ?> |
|
| 1839 | + <?php if ($billing_details['phone']) { ?> |
|
| 1840 | 1840 | <tr class="wpi-receipt-phone"> |
| 1841 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
| 1842 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
| 1841 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
| 1842 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
| 1843 | 1843 | </tr> |
| 1844 | 1844 | <?php } ?> |
| 1845 | 1845 | </tbody> |
@@ -1847,103 +1847,103 @@ discard block |
||
| 1847 | 1847 | <?php |
| 1848 | 1848 | $output = ob_get_clean(); |
| 1849 | 1849 | |
| 1850 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
| 1850 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
| 1851 | 1851 | |
| 1852 | 1852 | echo $output; |
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | -function wpinv_filter_success_page_content( $content ) { |
|
| 1856 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
| 1857 | - if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) { |
|
| 1858 | - $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content ); |
|
| 1855 | +function wpinv_filter_success_page_content($content) { |
|
| 1856 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
| 1857 | + if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) { |
|
| 1858 | + $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content); |
|
| 1859 | 1859 | } |
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | return $content; |
| 1863 | 1863 | } |
| 1864 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
| 1864 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
| 1865 | 1865 | |
| 1866 | -function wpinv_receipt_actions( $invoice ) { |
|
| 1867 | - if ( !empty( $invoice ) ) { |
|
| 1866 | +function wpinv_receipt_actions($invoice) { |
|
| 1867 | + if (!empty($invoice)) { |
|
| 1868 | 1868 | $actions = array(); |
| 1869 | 1869 | |
| 1870 | - if ( wpinv_user_can_view_invoice( $invoice->ID ) ) { |
|
| 1871 | - $actions['print'] = array( |
|
| 1872 | - 'url' => $invoice->get_view_url( true ), |
|
| 1873 | - 'name' => __( 'Print Invoice', 'invoicing' ), |
|
| 1870 | + if (wpinv_user_can_view_invoice($invoice->ID)) { |
|
| 1871 | + $actions['print'] = array( |
|
| 1872 | + 'url' => $invoice->get_view_url(true), |
|
| 1873 | + 'name' => __('Print Invoice', 'invoicing'), |
|
| 1874 | 1874 | 'class' => 'btn-primary', |
| 1875 | 1875 | ); |
| 1876 | 1876 | } |
| 1877 | 1877 | |
| 1878 | - if ( is_user_logged_in() ) { |
|
| 1878 | + if (is_user_logged_in()) { |
|
| 1879 | 1879 | $actions['history'] = array( |
| 1880 | 1880 | 'url' => wpinv_get_history_page_uri(), |
| 1881 | - 'name' => __( 'Invoice History', 'invoicing' ), |
|
| 1881 | + 'name' => __('Invoice History', 'invoicing'), |
|
| 1882 | 1882 | 'class' => 'btn-warning', |
| 1883 | 1883 | ); |
| 1884 | 1884 | } |
| 1885 | 1885 | |
| 1886 | - $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice ); |
|
| 1886 | + $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice); |
|
| 1887 | 1887 | |
| 1888 | - if ( !empty( $actions ) ) { |
|
| 1888 | + if (!empty($actions)) { |
|
| 1889 | 1889 | ?> |
| 1890 | 1890 | <div class="wpinv-receipt-actions text-right"> |
| 1891 | - <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?> |
|
| 1892 | - <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a> |
|
| 1891 | + <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?> |
|
| 1892 | + <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a> |
|
| 1893 | 1893 | <?php } ?> |
| 1894 | 1894 | </div> |
| 1895 | 1895 | <?php |
| 1896 | 1896 | } |
| 1897 | 1897 | } |
| 1898 | 1898 | } |
| 1899 | -add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 ); |
|
| 1899 | +add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1); |
|
| 1900 | 1900 | |
| 1901 | -function wpinv_invoice_link( $invoice_id ) { |
|
| 1902 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1901 | +function wpinv_invoice_link($invoice_id) { |
|
| 1902 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1903 | 1903 | |
| 1904 | - if ( empty( $invoice ) ) { |
|
| 1904 | + if (empty($invoice)) { |
|
| 1905 | 1905 | return NULL; |
| 1906 | 1906 | } |
| 1907 | 1907 | |
| 1908 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
| 1908 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
| 1909 | 1909 | |
| 1910 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
| 1910 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
| 1911 | 1911 | } |
| 1912 | 1912 | |
| 1913 | -function wpinv_invoice_subscription_details( $invoice ) { |
|
| 1914 | - if ( !empty( $invoice ) && $invoice->is_recurring() && !wpinv_is_subscription_payment( $invoice ) ) { |
|
| 1913 | +function wpinv_invoice_subscription_details($invoice) { |
|
| 1914 | + if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) { |
|
| 1915 | 1915 | $total_payments = (int)$invoice->get_total_payments(); |
| 1916 | 1916 | $payments = $invoice->get_child_payments(); |
| 1917 | 1917 | |
| 1918 | 1918 | $subscription = $invoice->get_subscription_data(); |
| 1919 | 1919 | |
| 1920 | - if ( !( !empty( $subscription ) && !empty( $subscription['item_id'] ) ) ) { |
|
| 1920 | + if (!(!empty($subscription) && !empty($subscription['item_id']))) { |
|
| 1921 | 1921 | return; |
| 1922 | 1922 | } |
| 1923 | 1923 | |
| 1924 | - $billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
| 1925 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
| 1924 | + $billing_cycle = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency()); |
|
| 1925 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
| 1926 | 1926 | |
| 1927 | 1927 | $subscription_status = $invoice->get_subscription_status(); |
| 1928 | 1928 | |
| 1929 | 1929 | $status_desc = ''; |
| 1930 | - if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { |
|
| 1931 | - $status_desc = wp_sprintf( __( 'Until: %s', 'invoicing' ), $trial_end_date ); |
|
| 1932 | - } else if ( $subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date() ) { |
|
| 1933 | - $status_desc = wp_sprintf( __( 'On: %s', 'invoicing' ), $cancelled_date ); |
|
| 1930 | + if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { |
|
| 1931 | + $status_desc = wp_sprintf(__('Until: %s', 'invoicing'), $trial_end_date); |
|
| 1932 | + } else if ($subscription_status == 'cancelled' && $cancelled_date = $invoice->get_cancelled_date()) { |
|
| 1933 | + $status_desc = wp_sprintf(__('On: %s', 'invoicing'), $cancelled_date); |
|
| 1934 | 1934 | } |
| 1935 | 1935 | $status_desc = $status_desc != '' ? '<span class="meta">' . $status_desc . '</span>' : ''; |
| 1936 | 1936 | ?> |
| 1937 | 1937 | <div class="wpinv-subscriptions-details"> |
| 1938 | - <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3> |
|
| 1938 | + <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3> |
|
| 1939 | 1939 | <table class="table"> |
| 1940 | 1940 | <thead> |
| 1941 | 1941 | <tr> |
| 1942 | - <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th> |
|
| 1943 | - <th><?php _e( 'Start Date', 'invoicing' ) ;?></th> |
|
| 1944 | - <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th> |
|
| 1945 | - <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th> |
|
| 1946 | - <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th> |
|
| 1942 | + <th><?php _e('Billing Cycle', 'invoicing'); ?></th> |
|
| 1943 | + <th><?php _e('Start Date', 'invoicing'); ?></th> |
|
| 1944 | + <th><?php _e('Expiration Date', 'invoicing'); ?></th> |
|
| 1945 | + <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th> |
|
| 1946 | + <th class="text-center"><?php _e('Status', 'invoicing'); ?></th> |
|
| 1947 | 1947 | </tr> |
| 1948 | 1948 | </thead> |
| 1949 | 1949 | <tbody> |
@@ -1952,32 +1952,32 @@ discard block |
||
| 1952 | 1952 | <td><?php echo $invoice->get_subscription_start(); ?></td> |
| 1953 | 1953 | <td><?php echo $invoice->get_subscription_end(); ?></td> |
| 1954 | 1954 | <td class="text-center"><?php echo $times_billed; ?></td> |
| 1955 | - <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label() ;?> |
|
| 1955 | + <td class="text-center wpi-sub-status"><?php echo $invoice->get_subscription_status_label(); ?> |
|
| 1956 | 1956 | <?php echo $status_desc; ?> |
| 1957 | 1957 | </td> |
| 1958 | 1958 | </tr> |
| 1959 | 1959 | </tbody> |
| 1960 | 1960 | </table> |
| 1961 | 1961 | </div> |
| 1962 | - <?php if ( !empty( $payments ) ) { ?> |
|
| 1962 | + <?php if (!empty($payments)) { ?> |
|
| 1963 | 1963 | <div class="wpinv-renewal-payments"> |
| 1964 | - <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3> |
|
| 1964 | + <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3> |
|
| 1965 | 1965 | <table class="table"> |
| 1966 | 1966 | <thead> |
| 1967 | 1967 | <tr> |
| 1968 | 1968 | <th>#</th> |
| 1969 | - <th><?php _e( 'Invoice', 'invoicing' ) ;?></th> |
|
| 1970 | - <th><?php _e( 'Date', 'invoicing' ) ;?></th> |
|
| 1971 | - <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th> |
|
| 1969 | + <th><?php _e('Invoice', 'invoicing'); ?></th> |
|
| 1970 | + <th><?php _e('Date', 'invoicing'); ?></th> |
|
| 1971 | + <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th> |
|
| 1972 | 1972 | </tr> |
| 1973 | 1973 | </thead> |
| 1974 | 1974 | <tbody> |
| 1975 | - <?php foreach ( $payments as $key => $invoice_id ) { ?> |
|
| 1975 | + <?php foreach ($payments as $key => $invoice_id) { ?> |
|
| 1976 | 1976 | <tr> |
| 1977 | - <th scope="row"><?php echo ( $key + 1 );?></th> |
|
| 1978 | - <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td> |
|
| 1979 | - <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td> |
|
| 1980 | - <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td> |
|
| 1977 | + <th scope="row"><?php echo ($key + 1); ?></th> |
|
| 1978 | + <td><?php echo wpinv_invoice_link($invoice_id); ?></td> |
|
| 1979 | + <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td> |
|
| 1980 | + <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td> |
|
| 1981 | 1981 | </tr> |
| 1982 | 1982 | <?php } ?> |
| 1983 | 1983 | <tr><td colspan="4" style="padding:0"></td></tr> |
@@ -1989,52 +1989,52 @@ discard block |
||
| 1989 | 1989 | } |
| 1990 | 1990 | } |
| 1991 | 1991 | |
| 1992 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
| 1993 | - if ( empty( $invoice ) ) { |
|
| 1992 | +function wpinv_cart_total_label($label, $invoice) { |
|
| 1993 | + if (empty($invoice)) { |
|
| 1994 | 1994 | return $label; |
| 1995 | 1995 | } |
| 1996 | 1996 | |
| 1997 | 1997 | $prefix_label = ''; |
| 1998 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
| 1999 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
| 2000 | - } else if ( $invoice->is_renewal() ) { |
|
| 2001 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
| 1998 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
| 1999 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
| 2000 | + } else if ($invoice->is_renewal()) { |
|
| 2001 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
| 2002 | 2002 | } |
| 2003 | 2003 | |
| 2004 | - if ( $prefix_label != '' ) { |
|
| 2005 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
| 2004 | + if ($prefix_label != '') { |
|
| 2005 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
| 2006 | 2006 | } |
| 2007 | 2007 | |
| 2008 | 2008 | return $label; |
| 2009 | 2009 | } |
| 2010 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
| 2011 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
| 2012 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
| 2010 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
| 2011 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
| 2012 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
| 2013 | 2013 | |
| 2014 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 ); |
|
| 2014 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1); |
|
| 2015 | 2015 | |
| 2016 | -function wpinv_invoice_print_description( $invoice ) { |
|
| 2017 | - if ( empty( $invoice ) ) { |
|
| 2016 | +function wpinv_invoice_print_description($invoice) { |
|
| 2017 | + if (empty($invoice)) { |
|
| 2018 | 2018 | return NULL; |
| 2019 | 2019 | } |
| 2020 | - if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) { |
|
| 2020 | + if ($description = wpinv_get_invoice_description($invoice->ID)) { |
|
| 2021 | 2021 | ?> |
| 2022 | 2022 | <div class="row wpinv-lower"> |
| 2023 | 2023 | <div class="col-sm-12 wpinv-description"> |
| 2024 | - <?php echo wpautop( $description ); ?> |
|
| 2024 | + <?php echo wpautop($description); ?> |
|
| 2025 | 2025 | </div> |
| 2026 | 2026 | </div> |
| 2027 | 2027 | <?php |
| 2028 | 2028 | } |
| 2029 | 2029 | } |
| 2030 | -add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 ); |
|
| 2030 | +add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1); |
|
| 2031 | 2031 | |
| 2032 | -function wpinv_invoice_print_payment_info( $invoice ) { |
|
| 2033 | - if ( empty( $invoice ) ) { |
|
| 2032 | +function wpinv_invoice_print_payment_info($invoice) { |
|
| 2033 | + if (empty($invoice)) { |
|
| 2034 | 2034 | return NULL; |
| 2035 | 2035 | } |
| 2036 | 2036 | |
| 2037 | - if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) { |
|
| 2037 | + if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) { |
|
| 2038 | 2038 | ?> |
| 2039 | 2039 | <div class="row wpinv-payments"> |
| 2040 | 2040 | <div class="col-sm-12"> |
@@ -2046,43 +2046,43 @@ discard block |
||
| 2046 | 2046 | } |
| 2047 | 2047 | // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 ); |
| 2048 | 2048 | |
| 2049 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
| 2050 | - if ( empty( $note ) ) { |
|
| 2049 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
| 2050 | + if (empty($note)) { |
|
| 2051 | 2051 | return NULL; |
| 2052 | 2052 | } |
| 2053 | 2053 | |
| 2054 | - if ( is_int( $note ) ) { |
|
| 2055 | - $note = get_comment( $note ); |
|
| 2054 | + if (is_int($note)) { |
|
| 2055 | + $note = get_comment($note); |
|
| 2056 | 2056 | } |
| 2057 | 2057 | |
| 2058 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
| 2058 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
| 2059 | 2059 | return NULL; |
| 2060 | 2060 | } |
| 2061 | 2061 | |
| 2062 | - $note_classes = array( 'note' ); |
|
| 2063 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
| 2064 | - $note_classes[] = $note->comment_author === __( 'System', 'invoicing' ) ? 'system-note' : ''; |
|
| 2065 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
| 2066 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
| 2062 | + $note_classes = array('note'); |
|
| 2063 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
| 2064 | + $note_classes[] = $note->comment_author === __('System', 'invoicing') ? 'system-note' : ''; |
|
| 2065 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
| 2066 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
| 2067 | 2067 | |
| 2068 | 2068 | ob_start(); |
| 2069 | 2069 | ?> |
| 2070 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>"> |
|
| 2070 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>"> |
|
| 2071 | 2071 | <div class="note_content"> |
| 2072 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
| 2072 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
| 2073 | 2073 | </div> |
| 2074 | 2074 | <p class="meta"> |
| 2075 | - <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr> |
|
| 2076 | - <?php if($note->comment_author !== 'System') {?> |
|
| 2077 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
| 2075 | + <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr> |
|
| 2076 | + <?php if ($note->comment_author !== 'System') {?> |
|
| 2077 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
| 2078 | 2078 | <?php } ?> |
| 2079 | 2079 | </p> |
| 2080 | 2080 | </li> |
| 2081 | 2081 | <?php |
| 2082 | 2082 | $note_content = ob_get_clean(); |
| 2083 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
| 2083 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
| 2084 | 2084 | |
| 2085 | - if ( $echo ) { |
|
| 2085 | + if ($echo) { |
|
| 2086 | 2086 | echo $note_content; |
| 2087 | 2087 | } else { |
| 2088 | 2088 | return $note_content; |
@@ -2092,33 +2092,33 @@ discard block |
||
| 2092 | 2092 | function wpinv_invalid_invoice_content() { |
| 2093 | 2093 | global $post; |
| 2094 | 2094 | |
| 2095 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
| 2095 | + $invoice = wpinv_get_invoice($post->ID); |
|
| 2096 | 2096 | |
| 2097 | - $error = __( 'This invoice is only viewable by clicking on the invoice link that sent to you via email.', 'invoicing' ); |
|
| 2098 | - if ( !empty( $invoice->ID ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
| 2099 | - if ( is_user_logged_in() ) { |
|
| 2100 | - if ( wpinv_require_login_to_checkout() ) { |
|
| 2101 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
| 2102 | - $error = __( 'You are not allowed to view this invoice.', 'invoicing' ); |
|
| 2097 | + $error = __('This invoice is only viewable by clicking on the invoice link that sent to you via email.', 'invoicing'); |
|
| 2098 | + if (!empty($invoice->ID) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { |
|
| 2099 | + if (is_user_logged_in()) { |
|
| 2100 | + if (wpinv_require_login_to_checkout()) { |
|
| 2101 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
| 2102 | + $error = __('You are not allowed to view this invoice.', 'invoicing'); |
|
| 2103 | 2103 | } |
| 2104 | 2104 | } |
| 2105 | 2105 | } else { |
| 2106 | - if ( wpinv_require_login_to_checkout() ) { |
|
| 2107 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
| 2108 | - $error = __( 'You must be logged in to view this invoice.', 'invoicing' ); |
|
| 2106 | + if (wpinv_require_login_to_checkout()) { |
|
| 2107 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
| 2108 | + $error = __('You must be logged in to view this invoice.', 'invoicing'); |
|
| 2109 | 2109 | } |
| 2110 | 2110 | } |
| 2111 | 2111 | } |
| 2112 | 2112 | } else { |
| 2113 | - $error = __( 'This invoice is deleted or does not exist.', 'invoicing' ); |
|
| 2113 | + $error = __('This invoice is deleted or does not exist.', 'invoicing'); |
|
| 2114 | 2114 | } |
| 2115 | 2115 | ?> |
| 2116 | 2116 | <div class="row wpinv-row-invalid"> |
| 2117 | 2117 | <div class="col-md-6 col-md-offset-3 wpinv-message error"> |
| 2118 | - <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3> |
|
| 2118 | + <h3><?php _e('Access Denied', 'invoicing'); ?></h3> |
|
| 2119 | 2119 | <p class="wpinv-msg-text"><?php echo $error; ?></p> |
| 2120 | 2120 | </div> |
| 2121 | 2121 | </div> |
| 2122 | 2122 | <?php |
| 2123 | 2123 | } |
| 2124 | -add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' ); |
|
| 2125 | 2124 | \ No newline at end of file |
| 2125 | +add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content'); |
|
| 2126 | 2126 | \ No newline at end of file |