@@ -1,121 +1,121 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // MUST have WordPress. |
| 3 | -if ( !defined( 'WPINC' ) ) { |
|
| 4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 3 | +if (!defined('WPINC')) { |
|
| 4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | function wpinv_use_taxes() { |
| 8 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
| 8 | + $ret = wpinv_get_option('enable_taxes', false); |
|
| 9 | 9 | |
| 10 | - return (bool) apply_filters( 'wpinv_use_taxes', $ret ); |
|
| 10 | + return (bool)apply_filters('wpinv_use_taxes', $ret); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | function wpinv_get_tax_rates() { |
| 14 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
| 14 | + $rates = get_option('wpinv_tax_rates', array()); |
|
| 15 | 15 | |
| 16 | - return apply_filters( 'wpinv_get_tax_rates', $rates ); |
|
| 16 | + return apply_filters('wpinv_get_tax_rates', $rates); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | -function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) { |
|
| 19 | +function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) { |
|
| 20 | 20 | global $wpinv_euvat, $wpi_tax_rates, $wpi_userID; |
| 21 | - $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array(); |
|
| 21 | + $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array(); |
|
| 22 | 22 | |
| 23 | - if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) { |
|
| 23 | + if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) { |
|
| 24 | 24 | return $wpi_tax_rates[$item_id]; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) { |
|
| 27 | + if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) { |
|
| 28 | 28 | $wpi_tax_rates[$item_id] = 0; |
| 29 | 29 | return 0; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $is_global = false; |
| 33 | - if ( $item_id == 'global' ) { |
|
| 33 | + if ($item_id == 'global') { |
|
| 34 | 34 | $is_global = true; |
| 35 | 35 | $item_id = 0; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - $rate = (float)wpinv_get_option( 'tax_rate', 0 ); |
|
| 39 | - $user_address = wpinv_get_user_address( $wpi_userID ); |
|
| 38 | + $rate = (float)wpinv_get_option('tax_rate', 0); |
|
| 39 | + $user_address = wpinv_get_user_address($wpi_userID); |
|
| 40 | 40 | |
| 41 | - if( empty( $country ) ) { |
|
| 42 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
| 41 | + if (empty($country)) { |
|
| 42 | + if (!empty($_POST['wpinv_country'])) { |
|
| 43 | 43 | $country = $_POST['wpinv_country']; |
| 44 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
| 44 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
| 45 | 45 | $country = $_POST['wpinv_country']; |
| 46 | - } elseif( !empty( $_POST['country'] ) ) { |
|
| 46 | + } elseif (!empty($_POST['country'])) { |
|
| 47 | 47 | $country = $_POST['country']; |
| 48 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
| 48 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
| 49 | 49 | $country = $user_address['country']; |
| 50 | 50 | } |
| 51 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
| 51 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if( empty( $state ) ) { |
|
| 55 | - if( !empty( $_POST['wpinv_state'] ) ) { |
|
| 54 | + if (empty($state)) { |
|
| 55 | + if (!empty($_POST['wpinv_state'])) { |
|
| 56 | 56 | $state = $_POST['wpinv_state']; |
| 57 | - } elseif( !empty( $_POST['wpinv_state'] ) ) { |
|
| 57 | + } elseif (!empty($_POST['wpinv_state'])) { |
|
| 58 | 58 | $state = $_POST['wpinv_state']; |
| 59 | - } elseif( !empty( $_POST['state'] ) ) { |
|
| 59 | + } elseif (!empty($_POST['state'])) { |
|
| 60 | 60 | $state = $_POST['state']; |
| 61 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
| 61 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
| 62 | 62 | $state = $user_address['state']; |
| 63 | 63 | } |
| 64 | - $state = !empty( $state ) ? $state : wpinv_get_default_state(); |
|
| 64 | + $state = !empty($state) ? $state : wpinv_get_default_state(); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if( !empty( $country ) ) { |
|
| 68 | - $tax_rates = wpinv_get_tax_rates(); |
|
| 67 | + if (!empty($country)) { |
|
| 68 | + $tax_rates = wpinv_get_tax_rates(); |
|
| 69 | 69 | |
| 70 | - if( !empty( $tax_rates ) ) { |
|
| 70 | + if (!empty($tax_rates)) { |
|
| 71 | 71 | // Locate the tax rate for this country / state, if it exists |
| 72 | - foreach( $tax_rates as $key => $tax_rate ) { |
|
| 73 | - if( $country != $tax_rate['country'] ) |
|
| 72 | + foreach ($tax_rates as $key => $tax_rate) { |
|
| 73 | + if ($country != $tax_rate['country']) |
|
| 74 | 74 | continue; |
| 75 | 75 | |
| 76 | - if( !empty( $tax_rate['global'] ) ) { |
|
| 77 | - if( !empty( $tax_rate['rate'] ) ) { |
|
| 78 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
| 76 | + if (!empty($tax_rate['global'])) { |
|
| 77 | + if (!empty($tax_rate['rate'])) { |
|
| 78 | + $rate = number_format($tax_rate['rate'], 4); |
|
| 79 | 79 | } |
| 80 | 80 | } else { |
| 81 | 81 | |
| 82 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
| 82 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
| 83 | 83 | continue; |
| 84 | 84 | |
| 85 | 85 | $state_rate = $tax_rate['rate']; |
| 86 | - if( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
| 87 | - $rate = number_format( $state_rate, 4 ); |
|
| 86 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
| 87 | + $rate = number_format($state_rate, 4); |
|
| 88 | 88 | } |
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id ); |
|
| 94 | + $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id); |
|
| 95 | 95 | |
| 96 | - if ( !empty( $item_id ) ) { |
|
| 96 | + if (!empty($item_id)) { |
|
| 97 | 97 | $wpi_tax_rates[$item_id] = $rate; |
| 98 | - } else if ( $is_global ) { |
|
| 98 | + } else if ($is_global) { |
|
| 99 | 99 | $wpi_tax_rates['global'] = $rate; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | return $rate; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | -function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) { |
|
| 106 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
| 107 | - $rate = round( $rate, 4 ); |
|
| 105 | +function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) { |
|
| 106 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
| 107 | + $rate = round($rate, 4); |
|
| 108 | 108 | $formatted = $rate .= '%'; |
| 109 | - return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id ); |
|
| 109 | + return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | -function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) { |
|
| 113 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
| 112 | +function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) { |
|
| 113 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
| 114 | 114 | $tax = 0.00; |
| 115 | 115 | |
| 116 | - if ( wpinv_use_taxes() ) { |
|
| 117 | - if ( wpinv_prices_include_tax() ) { |
|
| 118 | - $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) ); |
|
| 116 | + if (wpinv_use_taxes()) { |
|
| 117 | + if (wpinv_prices_include_tax()) { |
|
| 118 | + $pre_tax = ($amount / ((1 + $rate) * 0.01)); |
|
| 119 | 119 | $tax = $amount - $pre_tax; |
| 120 | 120 | } else { |
| 121 | 121 | $tax = $amount * $rate * 0.01; |
@@ -123,46 +123,46 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id ); |
|
| 126 | + return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | function wpinv_prices_include_tax() { |
| 130 | 130 | return false; // TODO |
| 131 | - $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
| 131 | + $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
| 132 | 132 | |
| 133 | - return apply_filters( 'wpinv_prices_include_tax', $ret ); |
|
| 133 | + return apply_filters('wpinv_prices_include_tax', $ret); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
| 137 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
| 136 | +function wpinv_sales_tax_for_year($year = null) { |
|
| 137 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
| 140 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
| 141 | 141 | global $wpdb; |
| 142 | 142 | |
| 143 | 143 | // Start at zero |
| 144 | 144 | $tax = 0; |
| 145 | 145 | |
| 146 | - if ( ! empty( $year ) ) { |
|
| 146 | + if (!empty($year)) { |
|
| 147 | 147 | $args = array( |
| 148 | 148 | 'post_type' => 'wpi_invoice', |
| 149 | - 'post_status' => array( 'publish' ), |
|
| 149 | + 'post_status' => array('publish'), |
|
| 150 | 150 | 'posts_per_page' => -1, |
| 151 | 151 | 'year' => $year, |
| 152 | 152 | 'fields' => 'ids' |
| 153 | 153 | ); |
| 154 | 154 | |
| 155 | - $payments = get_posts( $args ); |
|
| 156 | - $payment_ids = implode( ',', $payments ); |
|
| 155 | + $payments = get_posts($args); |
|
| 156 | + $payment_ids = implode(',', $payments); |
|
| 157 | 157 | |
| 158 | - if ( count( $payments ) > 0 ) { |
|
| 158 | + if (count($payments) > 0) { |
|
| 159 | 159 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
| 160 | - $tax = $wpdb->get_var( $sql ); |
|
| 160 | + $tax = $wpdb->get_var($sql); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
| 165 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | function wpinv_is_cart_taxed() { |
@@ -171,33 +171,33 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | function wpinv_prices_show_tax_on_checkout() { |
| 173 | 173 | return false; // TODO |
| 174 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
| 174 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
| 175 | 175 | |
| 176 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
| 176 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | function wpinv_display_tax_rate() { |
| 180 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
| 180 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
| 181 | 181 | |
| 182 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
| 182 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | function wpinv_cart_needs_tax_address_fields() { |
| 186 | - if( !wpinv_is_cart_taxed() ) |
|
| 186 | + if (!wpinv_is_cart_taxed()) |
|
| 187 | 187 | return false; |
| 188 | 188 | |
| 189 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
| 189 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
| 193 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
| 194 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
| 192 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
| 193 | + $ret = (bool)get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
| 194 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
| 197 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
| 198 | 198 | $currency = wpinv_get_currency(); |
| 199 | 199 | |
| 200 | - switch ( $currency ) { |
|
| 200 | + switch ($currency) { |
|
| 201 | 201 | case 'RIAL' : |
| 202 | 202 | case 'JPY' : |
| 203 | 203 | case 'TWD' : |
@@ -206,48 +206,48 @@ discard block |
||
| 206 | 206 | break; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
| 209 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function wpinv_tax_amount() { |
| 213 | 213 | $output = 0.00; |
| 214 | 214 | |
| 215 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
| 215 | + return apply_filters('wpinv_tax_amount', $output); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | function wpinv_recalculated_tax() { |
| 219 | - define( 'WPINV_RECALCTAX', true ); |
|
| 219 | + define('WPINV_RECALCTAX', true); |
|
| 220 | 220 | } |
| 221 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 ); |
|
| 221 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1); |
|
| 222 | 222 | |
| 223 | -function wpinv_recalculate_tax( $return = false ) { |
|
| 223 | +function wpinv_recalculate_tax($return = false) { |
|
| 224 | 224 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
| 225 | - if ( empty( $invoice_id ) ) { |
|
| 225 | + if (empty($invoice_id)) { |
|
| 226 | 226 | return false; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
| 229 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
| 230 | 230 | |
| 231 | - if ( empty( $invoice ) ) { |
|
| 231 | + if (empty($invoice)) { |
|
| 232 | 232 | return false; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - if ( empty( $_POST['country'] ) ) { |
|
| 235 | + if (empty($_POST['country'])) { |
|
| 236 | 236 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | $invoice->country = sanitize_text_field($_POST['country']); |
| 240 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 240 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 241 | 241 | if (isset($_POST['state'])) { |
| 242 | 242 | $invoice->state = sanitize_text_field($_POST['state']); |
| 243 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 243 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | $invoice->cart_details = wpinv_get_cart_content_details(); |
| 247 | 247 | |
| 248 | - $subtotal = wpinv_get_cart_subtotal( $invoice->cart_details ); |
|
| 249 | - $tax = wpinv_get_cart_tax( $invoice->cart_details ); |
|
| 250 | - $total = wpinv_get_cart_total( $invoice->cart_details ); |
|
| 248 | + $subtotal = wpinv_get_cart_subtotal($invoice->cart_details); |
|
| 249 | + $tax = wpinv_get_cart_tax($invoice->cart_details); |
|
| 250 | + $total = wpinv_get_cart_total($invoice->cart_details); |
|
| 251 | 251 | |
| 252 | 252 | $invoice->tax = $tax; |
| 253 | 253 | $invoice->subtotal = $subtotal; |
@@ -255,61 +255,61 @@ discard block |
||
| 255 | 255 | |
| 256 | 256 | $invoice->save(); |
| 257 | 257 | |
| 258 | - if ( $invoice->is_free_trial() ) { |
|
| 258 | + if ($invoice->is_free_trial()) { |
|
| 259 | 259 | $total = 0; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | $response = array( |
| 263 | - 'total' => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ), |
|
| 263 | + 'total' => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'), |
|
| 264 | 264 | 'total_raw' => $total, |
| 265 | - 'free' => !( (float)$total > 0 ) && $invoice->is_free() ? true : false, |
|
| 266 | - 'html' => wpinv_checkout_cart( $invoice->cart_details, false ), |
|
| 265 | + 'free' => !((float)$total > 0) && $invoice->is_free() ? true : false, |
|
| 266 | + 'html' => wpinv_checkout_cart($invoice->cart_details, false), |
|
| 267 | 267 | ); |
| 268 | 268 | |
| 269 | - if ( $return ) { |
|
| 269 | + if ($return) { |
|
| 270 | 270 | return $response; |
| 271 | 271 | } |
| 272 | 272 | |
| 273 | - wp_send_json( $response ); |
|
| 273 | + wp_send_json($response); |
|
| 274 | 274 | } |
| 275 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
| 276 | -add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
| 275 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
| 276 | +add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
| 277 | 277 | |
| 278 | 278 | // VAT Settings |
| 279 | -function wpinv_vat_rate_add_callback( $args ) { |
|
| 279 | +function wpinv_vat_rate_add_callback($args) { |
|
| 280 | 280 | ?> |
| 281 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
| 281 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
| 282 | 282 | <?php |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
| 285 | +function wpinv_vat_rate_delete_callback($args) { |
|
| 286 | 286 | global $wpinv_euvat; |
| 287 | 287 | |
| 288 | 288 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
| 289 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
| 290 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
| 289 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
| 290 | + if (isset($vat_classes[$vat_class])) { |
|
| 291 | 291 | ?> |
| 292 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
| 292 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
| 293 | 293 | <?php |
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | |
| 297 | -function wpinv_vat_rates_callback( $args ) { |
|
| 297 | +function wpinv_vat_rates_callback($args) { |
|
| 298 | 298 | global $wpinv_euvat; |
| 299 | 299 | |
| 300 | 300 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
| 301 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
| 301 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
| 302 | 302 | |
| 303 | 303 | $eu_states = $wpinv_euvat->get_eu_states(); |
| 304 | 304 | $countries = wpinv_get_country_list(); |
| 305 | 305 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
| 306 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
| 306 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
| 307 | 307 | ob_start(); |
| 308 | 308 | ?> |
| 309 | 309 | </td><tr> |
| 310 | 310 | <td colspan="2" class="wpinv_vat_tdbox"> |
| 311 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
| 312 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
| 311 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
| 312 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
| 313 | 313 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
| 314 | 314 | <colgroup> |
| 315 | 315 | <col width="50px" /> |
@@ -321,43 +321,43 @@ discard block |
||
| 321 | 321 | </colgroup> |
| 322 | 322 | <thead> |
| 323 | 323 | <tr> |
| 324 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
| 325 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
| 326 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
| 327 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
| 328 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
| 324 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
| 325 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
| 326 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
| 327 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
| 328 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
| 329 | 329 | </tr> |
| 330 | 330 | </thead> |
| 331 | 331 | <tbody> |
| 332 | - <?php if( !empty( $eu_states ) ) { ?> |
|
| 332 | + <?php if (!empty($eu_states)) { ?> |
|
| 333 | 333 | <?php |
| 334 | - foreach ( $eu_states as $state ) { |
|
| 335 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
| 334 | + foreach ($eu_states as $state) { |
|
| 335 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
| 336 | 336 | |
| 337 | 337 | // Filter the rate for each country |
| 338 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
| 338 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
| 339 | 339 | |
| 340 | 340 | // If one does not exist create a default |
| 341 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
| 341 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
| 342 | 342 | |
| 343 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
| 344 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
| 345 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
| 346 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
| 343 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
| 344 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
| 345 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
| 346 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
| 347 | 347 | ?> |
| 348 | 348 | <tr> |
| 349 | 349 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
| 350 | 350 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
| 351 | 351 | <td class="wpinv_vat_global"> |
| 352 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
| 353 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
| 354 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
| 352 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
| 353 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
| 354 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
| 355 | 355 | </td> |
| 356 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
| 357 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
| 356 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
| 357 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
| 358 | 358 | <td class="wpinv_vat_group"> |
| 359 | 359 | <?php |
| 360 | - echo wpinv_html_select( array( |
|
| 360 | + echo wpinv_html_select(array( |
|
| 361 | 361 | 'name' => 'vat_rates[' . $state . '][group]', |
| 362 | 362 | 'selected' => $vat_group, |
| 363 | 363 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -366,14 +366,14 @@ discard block |
||
| 366 | 366 | 'multiple' => false, |
| 367 | 367 | 'show_option_all' => false, |
| 368 | 368 | 'show_option_none' => false |
| 369 | - ) ); |
|
| 369 | + )); |
|
| 370 | 370 | ?> |
| 371 | 371 | </td> |
| 372 | 372 | </tr> |
| 373 | 373 | <?php } ?> |
| 374 | 374 | <tr> |
| 375 | 375 | <td colspan="6" style="background-color:#fafafa;"> |
| 376 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
| 376 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
| 377 | 377 | </td> |
| 378 | 378 | </tr> |
| 379 | 379 | <?php } ?> |
@@ -385,35 +385,35 @@ discard block |
||
| 385 | 385 | echo $content; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | -function wpinv_vat_number_callback( $args ) { |
|
| 388 | +function wpinv_vat_number_callback($args) { |
|
| 389 | 389 | global $wpinv_euvat; |
| 390 | 390 | |
| 391 | 391 | $vat_number = $wpinv_euvat->get_vat_number(); |
| 392 | 392 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
| 393 | 393 | |
| 394 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
| 395 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
| 394 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
| 395 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
| 396 | 396 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
| 397 | 397 | |
| 398 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
| 399 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
| 398 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
| 399 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
| 400 | 400 | $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
| 401 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
| 402 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
| 401 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
| 402 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
| 403 | 403 | |
| 404 | 404 | echo $html; |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
| 407 | +function wpinv_eu_fallback_rate_callback($args) { |
|
| 408 | 408 | global $wpinv_options; |
| 409 | 409 | |
| 410 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
| 411 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
| 410 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
| 411 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
| 412 | 412 | |
| 413 | - $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
| 414 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
| 415 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
| 416 | - $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
| 413 | + $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
| 414 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
| 415 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
| 416 | + $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
| 417 | 417 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
| 418 | 418 | echo $html; |
| 419 | 419 | ?> |
@@ -421,36 +421,36 @@ discard block |
||
| 421 | 421 | <?php |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | -function wpinv_vat_ip_lookup_callback( $args ) { |
|
| 424 | +function wpinv_vat_ip_lookup_callback($args) { |
|
| 425 | 425 | global $wpinv_options, $wpinv_euvat; |
| 426 | 426 | |
| 427 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : 'default' ); |
|
| 427 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default'); |
|
| 428 | 428 | |
| 429 | 429 | $options = array(); |
| 430 | - if ( function_exists( 'geoip_country_code_by_name' ) ) { |
|
| 431 | - $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' ); |
|
| 430 | + if (function_exists('geoip_country_code_by_name')) { |
|
| 431 | + $options['geoip'] = __('PHP GeoIP extension', 'invoicing'); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | $geoip2_database = $wpinv_euvat->geoip2_country_dbfile(); |
| 435 | 435 | |
| 436 | - if ( !function_exists( 'bcadd' ) ) { |
|
| 437 | - $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' ); |
|
| 436 | + if (!function_exists('bcadd')) { |
|
| 437 | + $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing'); |
|
| 438 | 438 | } else { |
| 439 | - $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : ''; |
|
| 439 | + $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : ''; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | - if ( $geoip2_database !== false && empty( $geoip2_message ) ) { |
|
| 443 | - $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' ); |
|
| 442 | + if ($geoip2_database !== false && empty($geoip2_message)) { |
|
| 443 | + $options['geoip2'] = __('GeoIP2 Database', 'invoicing'); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | - if ( function_exists( 'simplexml_load_file' ) ) { |
|
| 447 | - $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' ); |
|
| 446 | + if (function_exists('simplexml_load_file')) { |
|
| 447 | + $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing'); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | - $options['site'] = __( 'Use default country', 'invoicing' ); |
|
| 451 | - $options['default'] = __( 'Auto', 'invoicing' ); |
|
| 450 | + $options['site'] = __('Use default country', 'invoicing'); |
|
| 451 | + $options['default'] = __('Auto', 'invoicing'); |
|
| 452 | 452 | |
| 453 | - $html = wpinv_html_select( array( |
|
| 453 | + $html = wpinv_html_select(array( |
|
| 454 | 454 | 'name' => "wpinv_settings[{$args['id']}]", |
| 455 | 455 | 'selected' => $value, |
| 456 | 456 | 'id' => "wpinv_settings[{$args['id']}]", |
@@ -462,23 +462,23 @@ discard block |
||
| 462 | 462 | )); |
| 463 | 463 | |
| 464 | 464 | $desc = '<label for="wpinv_settings[' . $args['id'] . ']">'; |
| 465 | - $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' ); |
|
| 465 | + $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing'); |
|
| 466 | 466 | $desc .= '<p>'; |
| 467 | - if ( empty( $geoip2_message ) ) { |
|
| 468 | - if ( $geoip2_database ) { |
|
| 467 | + if (empty($geoip2_message)) { |
|
| 468 | + if ($geoip2_database) { |
|
| 469 | 469 | $last_updated = ''; |
| 470 | - if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) { |
|
| 471 | - $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated ); |
|
| 472 | - $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated ); |
|
| 470 | + if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) { |
|
| 471 | + $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated); |
|
| 472 | + $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated); |
|
| 473 | 473 | } |
| 474 | - $desc .= __( 'GeoIP2 database exists:', 'invoicing' ) . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>'; |
|
| 474 | + $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>'; |
|
| 475 | 475 | } else { |
| 476 | - $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __( 'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' ); |
|
| 476 | + $desc .= __('GeoIP2 database does not exist:', 'invoicing') . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing'); |
|
| 477 | 477 | } |
| 478 | 478 | } else { |
| 479 | 479 | $desc .= $geoip2_message; |
| 480 | 480 | } |
| 481 | - $desc .= '</p><p>'. __( 'geoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
| 481 | + $desc .= '</p><p>' . __('geoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
| 482 | 482 | $desc .= '</label>'; |
| 483 | 483 | |
| 484 | 484 | $html .= $desc; |
@@ -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(); |
@@ -31,31 +31,31 @@ discard block |
||
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | public function define_constants() { |
| 34 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 35 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 34 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 35 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | private function actions() { |
| 39 | 39 | /* Internationalize the text strings used. */ |
| 40 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 40 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 41 | 41 | |
| 42 | 42 | /* Perform actions on admin initialization. */ |
| 43 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
| 44 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
| 45 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
| 46 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 43 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
| 44 | + add_action('init', array(&$this, 'init'), 3); |
|
| 45 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
| 46 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
| 47 | 47 | |
| 48 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 49 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 48 | + if (class_exists('BuddyPress')) { |
|
| 49 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 52 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
| 53 | 53 | |
| 54 | - if ( is_admin() ) { |
|
| 55 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
| 56 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
| 54 | + if (is_admin()) { |
|
| 55 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
| 56 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
| 57 | 57 | } else { |
| 58 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 58 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -65,16 +65,16 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
| 67 | 67 | */ |
| 68 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
| 68 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
| 69 | 69 | |
| 70 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
| 70 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | public function plugins_loaded() { |
| 74 | 74 | /* Internationalize the text strings used. */ |
| 75 | 75 | $this->load_textdomain(); |
| 76 | 76 | |
| 77 | - do_action( 'wpinv_loaded' ); |
|
| 77 | + do_action('wpinv_loaded'); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -82,217 +82,217 @@ discard block |
||
| 82 | 82 | * |
| 83 | 83 | * @since 1.0 |
| 84 | 84 | */ |
| 85 | - public function load_textdomain( $locale = NULL ) { |
|
| 86 | - if ( empty( $locale ) ) { |
|
| 87 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 85 | + public function load_textdomain($locale = NULL) { |
|
| 86 | + if (empty($locale)) { |
|
| 87 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 90 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
| 91 | 91 | |
| 92 | - unload_textdomain( 'invoicing' ); |
|
| 93 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 94 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 92 | + unload_textdomain('invoicing'); |
|
| 93 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
| 94 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
| 95 | 95 | |
| 96 | 96 | /** |
| 97 | 97 | * Define language constants. |
| 98 | 98 | */ |
| 99 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 99 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public function includes() { |
| 103 | 103 | global $wpinv_options; |
| 104 | 104 | |
| 105 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 105 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
| 106 | 106 | $wpinv_options = wpinv_get_settings(); |
| 107 | 107 | |
| 108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
| 109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
| 116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 118 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 119 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 120 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 121 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
| 122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
| 123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
| 124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
| 125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' ); |
|
| 126 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 127 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 128 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 129 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
| 130 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 131 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 132 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 133 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 134 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
| 135 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 136 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
| 137 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstract-wpinv-privacy.php' ); |
|
| 138 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 139 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
| 140 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
| 109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
| 110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
| 111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
| 112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
| 113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
| 114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
| 115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
| 116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
| 117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
| 118 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
| 119 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
| 120 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
| 121 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
| 122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
| 123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
| 124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
| 125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php'); |
|
| 126 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
| 127 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
| 128 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
| 129 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
| 130 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
| 131 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
| 132 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
| 133 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
| 134 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
| 135 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
| 136 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
| 137 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstract-wpinv-privacy.php'); |
|
| 138 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
| 139 | + if (!class_exists('WPInv_EUVat')) { |
|
| 140 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 144 | - if ( !empty( $gateways ) ) { |
|
| 145 | - foreach ( $gateways as $gateway ) { |
|
| 146 | - if ( $gateway == 'manual' ) { |
|
| 143 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 144 | + if (!empty($gateways)) { |
|
| 145 | + foreach ($gateways as $gateway) { |
|
| 146 | + if ($gateway == 'manual') { |
|
| 147 | 147 | continue; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
| 151 | 151 | |
| 152 | - if ( file_exists( $gateway_file ) ) { |
|
| 153 | - require_once( $gateway_file ); |
|
| 152 | + if (file_exists($gateway_file)) { |
|
| 153 | + require_once($gateway_file); |
|
| 154 | 154 | } |
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
| 157 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
| 158 | 158 | |
| 159 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 160 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 161 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 162 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
| 159 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 160 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
| 161 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
| 162 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
| 163 | 163 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
| 164 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
| 165 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
| 166 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 167 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
| 168 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 169 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 164 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
| 165 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
| 166 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
| 167 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
| 168 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
| 169 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
| 170 | 170 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
| 171 | 171 | // load the user class only on the users.php page |
| 172 | 172 | global $pagenow; |
| 173 | - if($pagenow=='users.php'){ |
|
| 173 | + if ($pagenow == 'users.php') { |
|
| 174 | 174 | new WPInv_Admin_Users(); |
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // include css inliner |
| 179 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 180 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 179 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
| 180 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 183 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | public function init() { |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | public function admin_init() { |
| 190 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
| 190 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
| 193 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | public function activation_redirect() { |
| 197 | 197 | // Bail if no activation redirect |
| 198 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
| 198 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
| 199 | 199 | return; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // Delete the redirect transient |
| 203 | - delete_transient( '_wpinv_activation_redirect' ); |
|
| 203 | + delete_transient('_wpinv_activation_redirect'); |
|
| 204 | 204 | |
| 205 | 205 | // Bail if activating from network, or bulk |
| 206 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 206 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
| 207 | 207 | return; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 210 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
| 211 | 211 | exit; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | public function enqueue_scripts() { |
| 215 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 215 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 216 | 216 | |
| 217 | - wp_deregister_style( 'font-awesome' ); |
|
| 218 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
| 219 | - wp_enqueue_style( 'font-awesome' ); |
|
| 217 | + wp_deregister_style('font-awesome'); |
|
| 218 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
| 219 | + wp_enqueue_style('font-awesome'); |
|
| 220 | 220 | |
| 221 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
| 222 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 221 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
| 222 | + wp_enqueue_style('wpinv_front_style'); |
|
| 223 | 223 | |
| 224 | 224 | // Register scripts |
| 225 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 226 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ), WPINV_VERSION ); |
|
| 225 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 226 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION); |
|
| 227 | 227 | |
| 228 | 228 | $localize = array(); |
| 229 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 230 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 229 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 230 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 231 | 231 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
| 232 | 232 | $localize['currency_pos'] = wpinv_currency_position(); |
| 233 | 233 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 234 | 234 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 235 | 235 | $localize['decimals'] = wpinv_decimals(); |
| 236 | - $localize['txtComplete'] = __( 'Complete', 'invoicing' ); |
|
| 236 | + $localize['txtComplete'] = __('Complete', 'invoicing'); |
|
| 237 | 237 | |
| 238 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 238 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 239 | 239 | |
| 240 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 240 | + wp_enqueue_script('jquery-blockui'); |
|
| 241 | 241 | $autofill_api = wpinv_get_option('address_autofill_api'); |
| 242 | 242 | $autofill_active = wpinv_get_option('address_autofill_active'); |
| 243 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 244 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 245 | - wp_dequeue_script( 'google-maps-api' ); |
|
| 243 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
| 244 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
| 245 | + wp_dequeue_script('google-maps-api'); |
|
| 246 | 246 | } |
| 247 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 248 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 247 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
| 248 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
| 249 | 249 | } |
| 250 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 251 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 250 | + wp_enqueue_script('wpinv-front-script'); |
|
| 251 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | public function admin_enqueue_scripts() { |
| 255 | 255 | global $post, $pagenow; |
| 256 | 256 | |
| 257 | 257 | $post_type = wpinv_admin_post_type(); |
| 258 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 259 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
| 258 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 259 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
| 260 | 260 | |
| 261 | - wp_deregister_style( 'font-awesome' ); |
|
| 262 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
| 263 | - wp_enqueue_style( 'font-awesome' ); |
|
| 261 | + wp_deregister_style('font-awesome'); |
|
| 262 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
| 263 | + wp_enqueue_style('font-awesome'); |
|
| 264 | 264 | |
| 265 | 265 | $jquery_ui_css = false; |
| 266 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
| 266 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
| 267 | 267 | $jquery_ui_css = true; |
| 268 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
| 268 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
| 269 | 269 | $jquery_ui_css = true; |
| 270 | 270 | } |
| 271 | - if ( $jquery_ui_css ) { |
|
| 272 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
| 273 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
| 271 | + if ($jquery_ui_css) { |
|
| 272 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
| 273 | + wp_enqueue_style('jquery-ui-css'); |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
| 277 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
| 276 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
| 277 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
| 278 | 278 | |
| 279 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
| 280 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
| 279 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
| 280 | + wp_enqueue_style('wpinv_admin_style'); |
|
| 281 | 281 | |
| 282 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
| 283 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 284 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 282 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
| 283 | + if ($page == 'wpinv-subscriptions') { |
|
| 284 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 285 | 285 | } |
| 286 | - $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ); |
|
| 286 | + $enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue); |
|
| 287 | 287 | |
| 288 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
| 289 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 288 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
| 289 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 293 | - wp_enqueue_script( 'wp-color-picker' ); |
|
| 292 | + wp_enqueue_style('wp-color-picker'); |
|
| 293 | + wp_enqueue_script('wp-color-picker'); |
|
| 294 | 294 | |
| 295 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 295 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 296 | 296 | |
| 297 | 297 | if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
| 298 | 298 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -303,17 +303,17 @@ discard block |
||
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | |
| 306 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), WPINV_VERSION ); |
|
| 307 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
| 306 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION); |
|
| 307 | + wp_enqueue_script('wpinv-admin-script'); |
|
| 308 | 308 | |
| 309 | 309 | $localize = array(); |
| 310 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 311 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
| 312 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 313 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
| 314 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
| 315 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
| 316 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
| 310 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 311 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
| 312 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 313 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
| 314 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
| 315 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
| 316 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
| 317 | 317 | $localize['tax'] = wpinv_tax_amount(); |
| 318 | 318 | $localize['discount'] = wpinv_discount_amount(); |
| 319 | 319 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -321,69 +321,69 @@ discard block |
||
| 321 | 321 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 322 | 322 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 323 | 323 | $localize['decimals'] = wpinv_decimals(); |
| 324 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
| 325 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
| 326 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
| 327 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
| 328 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
| 329 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
| 330 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
| 331 | - $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' ); |
|
| 332 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
| 333 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
| 334 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
| 335 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
| 336 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
| 337 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
| 324 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
| 325 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
| 326 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
| 327 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
| 328 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
| 329 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
| 330 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
| 331 | + $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'); |
|
| 332 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
| 333 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
| 334 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
| 335 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
| 336 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
| 337 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
| 338 | 338 | |
| 339 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
| 339 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
| 340 | 340 | |
| 341 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
| 341 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
| 342 | 342 | |
| 343 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 344 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions' . $suffix . '.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
| 345 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
| 343 | + if ($page == 'wpinv-subscriptions') { |
|
| 344 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions' . $suffix . '.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
| 345 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - public function admin_body_class( $classes ) { |
|
| 349 | + public function admin_body_class($classes) { |
|
| 350 | 350 | global $pagenow, $post, $current_screen; |
| 351 | 351 | |
| 352 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
| 352 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) { |
|
| 353 | 353 | $classes .= ' wpinv-cpt'; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
| 356 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
| 357 | 357 | |
| 358 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
| 359 | - if ( $add_class ) { |
|
| 360 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
| 358 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
| 359 | + if ($add_class) { |
|
| 360 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | $settings_class = array(); |
| 364 | - if ( $page == 'wpinv-settings' ) { |
|
| 365 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
| 366 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
| 364 | + if ($page == 'wpinv-settings') { |
|
| 365 | + if (!empty($_REQUEST['tab'])) { |
|
| 366 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
| 370 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
| 369 | + if (!empty($_REQUEST['section'])) { |
|
| 370 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
| 373 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - if ( !empty( $settings_class ) ) { |
|
| 377 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
| 376 | + if (!empty($settings_class)) { |
|
| 377 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | $post_type = wpinv_admin_post_type(); |
| 381 | 381 | |
| 382 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
| 382 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
| 383 | 383 | return $classes .= ' wpinv'; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
| 386 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
| 387 | 387 | $classes .= ' wpi-editable-n'; |
| 388 | 388 | } |
| 389 | 389 | |
@@ -395,20 +395,20 @@ discard block |
||
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | public function wpinv_actions() { |
| 398 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 399 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 398 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 399 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 400 | 400 | } |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - public function pre_get_posts( $wp_query ) { |
|
| 404 | - 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() ) { |
|
| 405 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 403 | + public function pre_get_posts($wp_query) { |
|
| 404 | + 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()) { |
|
| 405 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | return $wp_query; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | public function bp_invoicing_init() { |
| 412 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 412 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
| 413 | 413 | } |
| 414 | 414 | } |
| 415 | 415 | \ No newline at end of file |
@@ -7,245 +7,245 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | -function wpinv_columns( $columns ) { |
|
| 14 | +function wpinv_columns($columns) { |
|
| 15 | 15 | $columns = array( |
| 16 | 16 | 'cb' => $columns['cb'], |
| 17 | - 'number' => __( 'Number', 'invoicing' ), |
|
| 18 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
| 19 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
| 20 | - 'invoice_date' => __( 'Created Date', 'invoicing' ), |
|
| 21 | - 'payment_date' => __( 'Payment Date', 'invoicing' ), |
|
| 22 | - 'status' => __( 'Status', 'invoicing' ), |
|
| 23 | - 'ID' => __( 'ID', 'invoicing' ), |
|
| 24 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
| 17 | + 'number' => __('Number', 'invoicing'), |
|
| 18 | + 'customer' => __('Customer', 'invoicing'), |
|
| 19 | + 'amount' => __('Amount', 'invoicing'), |
|
| 20 | + 'invoice_date' => __('Created Date', 'invoicing'), |
|
| 21 | + 'payment_date' => __('Payment Date', 'invoicing'), |
|
| 22 | + 'status' => __('Status', 'invoicing'), |
|
| 23 | + 'ID' => __('ID', 'invoicing'), |
|
| 24 | + 'wpi_actions' => __('Actions', 'invoicing'), |
|
| 25 | 25 | ); |
| 26 | 26 | |
| 27 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
| 27 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
| 28 | 28 | } |
| 29 | -add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' ); |
|
| 29 | +add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns'); |
|
| 30 | 30 | |
| 31 | -function wpinv_bulk_actions( $actions ) { |
|
| 32 | - if ( isset( $actions['edit'] ) ) { |
|
| 33 | - unset( $actions['edit'] ); |
|
| 31 | +function wpinv_bulk_actions($actions) { |
|
| 32 | + if (isset($actions['edit'])) { |
|
| 33 | + unset($actions['edit']); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | return $actions; |
| 37 | 37 | } |
| 38 | -add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' ); |
|
| 39 | -add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' ); |
|
| 38 | +add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions'); |
|
| 39 | +add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions'); |
|
| 40 | 40 | |
| 41 | -function wpinv_sortable_columns( $columns ) { |
|
| 41 | +function wpinv_sortable_columns($columns) { |
|
| 42 | 42 | $columns = array( |
| 43 | - 'ID' => array( 'ID', true ), |
|
| 44 | - 'number' => array( 'number', false ), |
|
| 45 | - 'amount' => array( 'amount', false ), |
|
| 46 | - 'invoice_date' => array( 'date', false ), |
|
| 47 | - 'payment_date' => array( 'payment_date', true ), |
|
| 48 | - 'customer' => array( 'customer', false ), |
|
| 49 | - 'status' => array( 'status', false ), |
|
| 43 | + 'ID' => array('ID', true), |
|
| 44 | + 'number' => array('number', false), |
|
| 45 | + 'amount' => array('amount', false), |
|
| 46 | + 'invoice_date' => array('date', false), |
|
| 47 | + 'payment_date' => array('payment_date', true), |
|
| 48 | + 'customer' => array('customer', false), |
|
| 49 | + 'status' => array('status', false), |
|
| 50 | 50 | ); |
| 51 | 51 | |
| 52 | - return apply_filters( 'wpi_invoice_table_sortable_columns', $columns ); |
|
| 52 | + return apply_filters('wpi_invoice_table_sortable_columns', $columns); |
|
| 53 | 53 | } |
| 54 | -add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' ); |
|
| 54 | +add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns'); |
|
| 55 | 55 | |
| 56 | -add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
| 57 | -function wpinv_posts_custom_column( $column_name, $post_id = 0 ) { |
|
| 56 | +add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
| 57 | +function wpinv_posts_custom_column($column_name, $post_id = 0) { |
|
| 58 | 58 | global $post, $wpi_invoice; |
| 59 | 59 | |
| 60 | - if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) { |
|
| 61 | - $wpi_invoice = new WPInv_Invoice( $post->ID ); |
|
| 60 | + if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) { |
|
| 61 | + $wpi_invoice = new WPInv_Invoice($post->ID); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $value = NULL; |
| 65 | 65 | |
| 66 | - switch ( $column_name ) { |
|
| 66 | + switch ($column_name) { |
|
| 67 | 67 | case 'email' : |
| 68 | - $value = $wpi_invoice->get_email(); |
|
| 68 | + $value = $wpi_invoice->get_email(); |
|
| 69 | 69 | break; |
| 70 | 70 | case 'customer' : |
| 71 | 71 | $customer_name = $wpi_invoice->get_user_full_name(); |
| 72 | - $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' ); |
|
| 73 | - $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>'; |
|
| 74 | - if ( $email = $wpi_invoice->get_email() ) { |
|
| 72 | + $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing'); |
|
| 73 | + $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>'; |
|
| 74 | + if ($email = $wpi_invoice->get_email()) { |
|
| 75 | 75 | $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>'; |
| 76 | 76 | } |
| 77 | 77 | break; |
| 78 | 78 | case 'amount' : |
| 79 | - echo $wpi_invoice->get_total( true ); |
|
| 79 | + echo $wpi_invoice->get_total(true); |
|
| 80 | 80 | break; |
| 81 | 81 | case 'invoice_date' : |
| 82 | - $date_format = get_option( 'date_format' ); |
|
| 83 | - $time_format = get_option( 'time_format' ); |
|
| 84 | - $date_time_format = $date_format . ' '. $time_format; |
|
| 82 | + $date_format = get_option('date_format'); |
|
| 83 | + $time_format = get_option('time_format'); |
|
| 84 | + $date_time_format = $date_format . ' ' . $time_format; |
|
| 85 | 85 | |
| 86 | 86 | $m_time = $post->post_date; |
| 87 | - $h_time = mysql2date( $date_format, $m_time ); |
|
| 87 | + $h_time = mysql2date($date_format, $m_time); |
|
| 88 | 88 | |
| 89 | - $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
| 89 | + $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
| 90 | 90 | break; |
| 91 | 91 | case 'payment_date' : |
| 92 | - if ( $date_completed = $wpi_invoice->get_meta( '_wpinv_completed_date', true ) ) { |
|
| 93 | - $date_format = get_option( 'date_format' ); |
|
| 94 | - $time_format = get_option( 'time_format' ); |
|
| 95 | - $date_time_format = $date_format . ' '. $time_format; |
|
| 92 | + if ($date_completed = $wpi_invoice->get_meta('_wpinv_completed_date', true)) { |
|
| 93 | + $date_format = get_option('date_format'); |
|
| 94 | + $time_format = get_option('time_format'); |
|
| 95 | + $date_time_format = $date_format . ' ' . $time_format; |
|
| 96 | 96 | |
| 97 | 97 | $m_time = $date_completed; |
| 98 | - $h_time = mysql2date( $date_format, $m_time ); |
|
| 98 | + $h_time = mysql2date($date_format, $m_time); |
|
| 99 | 99 | |
| 100 | - $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
| 100 | + $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>'; |
|
| 101 | 101 | } else { |
| 102 | 102 | $value = '-'; |
| 103 | 103 | } |
| 104 | 104 | break; |
| 105 | 105 | case 'status' : |
| 106 | - $value = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' ); |
|
| 107 | - $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID ); |
|
| 108 | - if ( 1 == $is_viewed ) { |
|
| 109 | - $value .= ' <i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
| 106 | + $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''); |
|
| 107 | + $is_viewed = wpinv_is_invoice_viewed($wpi_invoice->ID); |
|
| 108 | + if (1 == $is_viewed) { |
|
| 109 | + $value .= ' <i class="fa fa-eye" title="' . __('Viewed by Customer', 'invoicing') . '"></i>'; |
|
| 110 | 110 | } |
| 111 | - if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() ) && ( $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() ) ) ) { |
|
| 112 | - $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>'; |
|
| 111 | + if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded()) && ($gateway_title = wpinv_get_gateway_admin_label($wpi_invoice->get_gateway()))) { |
|
| 112 | + $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>'; |
|
| 113 | 113 | } |
| 114 | 114 | break; |
| 115 | 115 | case 'number' : |
| 116 | - $edit_link = get_edit_post_link( $post->ID ); |
|
| 117 | - $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>'; |
|
| 116 | + $edit_link = get_edit_post_link($post->ID); |
|
| 117 | + $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>'; |
|
| 118 | 118 | break; |
| 119 | 119 | case 'wpi_actions' : |
| 120 | 120 | $value = ''; |
| 121 | - if ( !empty( $post->post_name ) ) { |
|
| 122 | - $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>'; |
|
| 121 | + if (!empty($post->post_name)) { |
|
| 122 | + $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if ( $email = $wpi_invoice->get_email() ) { |
|
| 126 | - $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>'; |
|
| 125 | + if ($email = $wpi_invoice->get_email()) { |
|
| 126 | + $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>'; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | break; |
| 130 | 130 | default: |
| 131 | - $value = isset( $post->$column_name ) ? $post->$column_name : ''; |
|
| 131 | + $value = isset($post->$column_name) ? $post->$column_name : ''; |
|
| 132 | 132 | break; |
| 133 | 133 | |
| 134 | 134 | } |
| 135 | - $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name ); |
|
| 135 | + $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name); |
|
| 136 | 136 | |
| 137 | - if ( $value !== NULL ) { |
|
| 137 | + if ($value !== NULL) { |
|
| 138 | 138 | echo $value; |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | -function wpinv_admin_post_id( $id = 0 ) { |
|
| 142 | +function wpinv_admin_post_id($id = 0) { |
|
| 143 | 143 | global $post; |
| 144 | 144 | |
| 145 | - if ( isset( $id ) && ! empty( $id ) ) { |
|
| 145 | + if (isset($id) && !empty($id)) { |
|
| 146 | 146 | return (int)$id; |
| 147 | - } else if ( get_the_ID() ) { |
|
| 148 | - return (int) get_the_ID(); |
|
| 149 | - } else if ( isset( $post->ID ) && !empty( $post->ID ) ) { |
|
| 150 | - return (int) $post->ID; |
|
| 151 | - } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) { |
|
| 152 | - return (int) $_GET['post']; |
|
| 153 | - } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) { |
|
| 154 | - return (int) $_GET['id']; |
|
| 155 | - } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) { |
|
| 156 | - return (int) $_POST['id']; |
|
| 147 | + } else if (get_the_ID()) { |
|
| 148 | + return (int)get_the_ID(); |
|
| 149 | + } else if (isset($post->ID) && !empty($post->ID)) { |
|
| 150 | + return (int)$post->ID; |
|
| 151 | + } else if (isset($_GET['post']) && !empty($_GET['post'])) { |
|
| 152 | + return (int)$_GET['post']; |
|
| 153 | + } else if (isset($_GET['id']) && !empty($_GET['id'])) { |
|
| 154 | + return (int)$_GET['id']; |
|
| 155 | + } else if (isset($_POST['id']) && !empty($_POST['id'])) { |
|
| 156 | + return (int)$_POST['id']; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | return null; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | -function wpinv_admin_post_type( $id = 0 ) { |
|
| 163 | - if ( !$id ) { |
|
| 162 | +function wpinv_admin_post_type($id = 0) { |
|
| 163 | + if (!$id) { |
|
| 164 | 164 | $id = wpinv_admin_post_id(); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - $type = get_post_type( $id ); |
|
| 167 | + $type = get_post_type($id); |
|
| 168 | 168 | |
| 169 | - if ( !$type ) { |
|
| 170 | - $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null; |
|
| 169 | + if (!$type) { |
|
| 170 | + $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - return apply_filters( 'wpinv_admin_post_type', $type, $id ); |
|
| 173 | + return apply_filters('wpinv_admin_post_type', $type, $id); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | function wpinv_admin_messages() { |
| 177 | 177 | global $wpinv_options, $pagenow, $post; |
| 178 | 178 | |
| 179 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 180 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
| 179 | + if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 180 | + add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated'); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 184 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
| 183 | + if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 184 | + add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error'); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 188 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
| 187 | + if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 188 | + add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error'); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 192 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
| 191 | + if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 192 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated'); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 196 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
| 195 | + if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 196 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error'); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 200 | - add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
| 199 | + if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 200 | + add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated'); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 204 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' ); |
|
| 203 | + if (isset($_GET['wpinv-message']) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 204 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Email notification is disabled. Please check settings.', 'invoicing'), 'error'); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 208 | - add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
| 207 | + if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 208 | + add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated'); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 212 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
| 211 | + if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 212 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error'); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 216 | - add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
|
| 215 | + if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 216 | + add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated'); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 220 | - add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
| 219 | + if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 220 | + add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated'); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 224 | - add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
| 223 | + if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 224 | + add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated'); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
| 228 | - add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
| 227 | + if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
| 228 | + add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated'); |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) { |
|
| 232 | - $message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID ); |
|
| 231 | + if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) { |
|
| 232 | + $message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID); |
|
| 233 | 233 | |
| 234 | - if ( !empty( $message ) ) { |
|
| 235 | - add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' ); |
|
| 234 | + if (!empty($message)) { |
|
| 235 | + add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated'); |
|
| 236 | 236 | } |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - settings_errors( 'wpinv-notices' ); |
|
| 239 | + settings_errors('wpinv-notices'); |
|
| 240 | 240 | } |
| 241 | -add_action( 'admin_notices', 'wpinv_admin_messages' ); |
|
| 241 | +add_action('admin_notices', 'wpinv_admin_messages'); |
|
| 242 | 242 | |
| 243 | -add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' ); |
|
| 244 | -function wpinv_show_test_payment_gateway_notice(){ |
|
| 245 | - add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' ); |
|
| 243 | +add_action('admin_init', 'wpinv_show_test_payment_gateway_notice'); |
|
| 244 | +function wpinv_show_test_payment_gateway_notice() { |
|
| 245 | + add_action('admin_notices', 'wpinv_test_payment_gateway_messages'); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | -function wpinv_test_payment_gateway_messages(){ |
|
| 248 | +function wpinv_test_payment_gateway_messages() { |
|
| 249 | 249 | $gateways = wpinv_get_enabled_payment_gateways(); |
| 250 | 250 | $name = array(); $test_gateways = ''; |
| 251 | 251 | if ($gateways) { |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | $test_gateways = implode(', ', $name); |
| 258 | 258 | } |
| 259 | - if(isset($test_gateways) && !empty($test_gateways)){ |
|
| 259 | + if (isset($test_gateways) && !empty($test_gateways)) { |
|
| 260 | 260 | $link = admin_url('admin.php?page=wpinv-settings&tab=gateways'); |
| 261 | - $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link ); |
|
| 261 | + $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link); |
|
| 262 | 262 | ?> |
| 263 | 263 | <div class="notice notice-warning is-dismissible"> |
| 264 | 264 | <p><?php echo $notice; ?></p> |
@@ -267,29 +267,29 @@ discard block |
||
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | -function wpinv_items_columns( $existing_columns ) { |
|
| 270 | +function wpinv_items_columns($existing_columns) { |
|
| 271 | 271 | global $wpinv_euvat; |
| 272 | 272 | |
| 273 | 273 | $columns = array(); |
| 274 | 274 | $columns['cb'] = $existing_columns['cb']; |
| 275 | - $columns['title'] = __( 'Title', 'invoicing' ); |
|
| 276 | - $columns['price'] = __( 'Price', 'invoicing' ); |
|
| 277 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
| 278 | - $columns['vat_rule'] = __( 'VAT rule type', 'invoicing' ); |
|
| 275 | + $columns['title'] = __('Title', 'invoicing'); |
|
| 276 | + $columns['price'] = __('Price', 'invoicing'); |
|
| 277 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
| 278 | + $columns['vat_rule'] = __('VAT rule type', 'invoicing'); |
|
| 279 | 279 | } |
| 280 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
| 281 | - $columns['vat_class'] = __( 'VAT class', 'invoicing' ); |
|
| 280 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
| 281 | + $columns['vat_class'] = __('VAT class', 'invoicing'); |
|
| 282 | 282 | } |
| 283 | - $columns['type'] = __( 'Type', 'invoicing' ); |
|
| 284 | - $columns['recurring'] = __( 'Recurring', 'invoicing' ); |
|
| 285 | - $columns['date'] = __( 'Date', 'invoicing' ); |
|
| 286 | - $columns['id'] = __( 'ID', 'invoicing' ); |
|
| 283 | + $columns['type'] = __('Type', 'invoicing'); |
|
| 284 | + $columns['recurring'] = __('Recurring', 'invoicing'); |
|
| 285 | + $columns['date'] = __('Date', 'invoicing'); |
|
| 286 | + $columns['id'] = __('ID', 'invoicing'); |
|
| 287 | 287 | |
| 288 | - return apply_filters( 'wpinv_items_columns', $columns ); |
|
| 288 | + return apply_filters('wpinv_items_columns', $columns); |
|
| 289 | 289 | } |
| 290 | -add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' ); |
|
| 290 | +add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns'); |
|
| 291 | 291 | |
| 292 | -function wpinv_items_sortable_columns( $columns ) { |
|
| 292 | +function wpinv_items_sortable_columns($columns) { |
|
| 293 | 293 | $columns['price'] = 'price'; |
| 294 | 294 | $columns['vat_rule'] = 'vat_rule'; |
| 295 | 295 | $columns['vat_class'] = 'vat_class'; |
@@ -299,151 +299,151 @@ discard block |
||
| 299 | 299 | |
| 300 | 300 | return $columns; |
| 301 | 301 | } |
| 302 | -add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' ); |
|
| 302 | +add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns'); |
|
| 303 | 303 | |
| 304 | -function wpinv_items_table_custom_column( $column ) { |
|
| 304 | +function wpinv_items_table_custom_column($column) { |
|
| 305 | 305 | global $wpinv_euvat, $post, $wpi_item; |
| 306 | 306 | |
| 307 | - if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) { |
|
| 308 | - $wpi_item = new WPInv_Item( $post->ID ); |
|
| 307 | + if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) { |
|
| 308 | + $wpi_item = new WPInv_Item($post->ID); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - switch ( $column ) { |
|
| 311 | + switch ($column) { |
|
| 312 | 312 | case 'price' : |
| 313 | - echo wpinv_item_price( $post->ID ); |
|
| 313 | + echo wpinv_item_price($post->ID); |
|
| 314 | 314 | break; |
| 315 | 315 | case 'vat_rule' : |
| 316 | - echo $wpinv_euvat->item_rule_label( $post->ID ); |
|
| 316 | + echo $wpinv_euvat->item_rule_label($post->ID); |
|
| 317 | 317 | break; |
| 318 | 318 | case 'vat_class' : |
| 319 | - echo $wpinv_euvat->item_class_label( $post->ID ); |
|
| 319 | + echo $wpinv_euvat->item_class_label($post->ID); |
|
| 320 | 320 | break; |
| 321 | 321 | case 'type' : |
| 322 | - echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>'; |
|
| 322 | + echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>'; |
|
| 323 | 323 | break; |
| 324 | 324 | case 'recurring' : |
| 325 | - echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' ); |
|
| 325 | + echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>'); |
|
| 326 | 326 | break; |
| 327 | 327 | case 'id' : |
| 328 | 328 | echo $post->ID; |
| 329 | 329 | echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
| 330 | - <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>'; |
|
| 331 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
| 332 | - echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>'; |
|
| 330 | + <div class="price">' . wpinv_get_item_price($post->ID) . '</div>'; |
|
| 331 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
| 332 | + echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>'; |
|
| 333 | 333 | } |
| 334 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
| 335 | - echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>'; |
|
| 334 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
| 335 | + echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>'; |
|
| 336 | 336 | } |
| 337 | - echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div> |
|
| 337 | + echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div> |
|
| 338 | 338 | </div>'; |
| 339 | 339 | break; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | - do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post ); |
|
| 342 | + do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post); |
|
| 343 | 343 | } |
| 344 | -add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' ); |
|
| 344 | +add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column'); |
|
| 345 | 345 | |
| 346 | 346 | function wpinv_add_items_filters() { |
| 347 | 347 | global $wpinv_euvat, $typenow; |
| 348 | 348 | |
| 349 | 349 | // Checks if the current post type is 'item' |
| 350 | - if ( $typenow == 'wpi_item') { |
|
| 351 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
| 352 | - echo wpinv_html_select( array( |
|
| 353 | - 'options' => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ), |
|
| 350 | + if ($typenow == 'wpi_item') { |
|
| 351 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
| 352 | + echo wpinv_html_select(array( |
|
| 353 | + 'options' => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()), |
|
| 354 | 354 | 'name' => 'vat_rule', |
| 355 | 355 | 'id' => 'vat_rule', |
| 356 | - 'selected' => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ), |
|
| 356 | + 'selected' => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''), |
|
| 357 | 357 | 'show_option_all' => false, |
| 358 | 358 | 'show_option_none' => false, |
| 359 | 359 | 'class' => 'gdmbx2-text-medium', |
| 360 | - ) ); |
|
| 360 | + )); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
| 364 | - echo wpinv_html_select( array( |
|
| 365 | - 'options' => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ), |
|
| 363 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
| 364 | + echo wpinv_html_select(array( |
|
| 365 | + 'options' => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()), |
|
| 366 | 366 | 'name' => 'vat_class', |
| 367 | 367 | 'id' => 'vat_class', |
| 368 | - 'selected' => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ), |
|
| 368 | + 'selected' => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''), |
|
| 369 | 369 | 'show_option_all' => false, |
| 370 | 370 | 'show_option_none' => false, |
| 371 | 371 | 'class' => 'gdmbx2-text-medium', |
| 372 | - ) ); |
|
| 372 | + )); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - echo wpinv_html_select( array( |
|
| 376 | - 'options' => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ), |
|
| 375 | + echo wpinv_html_select(array( |
|
| 376 | + 'options' => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()), |
|
| 377 | 377 | 'name' => 'type', |
| 378 | 378 | 'id' => 'type', |
| 379 | - 'selected' => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ), |
|
| 379 | + 'selected' => (isset($_GET['type']) ? $_GET['type'] : ''), |
|
| 380 | 380 | 'show_option_all' => false, |
| 381 | 381 | 'show_option_none' => false, |
| 382 | 382 | 'class' => 'gdmbx2-text-medium', |
| 383 | - ) ); |
|
| 383 | + )); |
|
| 384 | 384 | |
| 385 | - if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) { |
|
| 385 | + if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) { |
|
| 386 | 386 | echo '<input type="hidden" name="all_posts" value="1" />'; |
| 387 | 387 | } |
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | -add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 ); |
|
| 390 | +add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100); |
|
| 391 | 391 | |
| 392 | -function wpinv_send_invoice_after_save( $invoice ) { |
|
| 393 | - if ( empty( $_POST['wpi_save_send'] ) ) { |
|
| 392 | +function wpinv_send_invoice_after_save($invoice) { |
|
| 393 | + if (empty($_POST['wpi_save_send'])) { |
|
| 394 | 394 | return; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | - if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) { |
|
| 398 | - wpinv_user_invoice_notification( $invoice->ID ); |
|
| 397 | + if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) { |
|
| 398 | + wpinv_user_invoice_notification($invoice->ID); |
|
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | -add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 ); |
|
| 401 | +add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1); |
|
| 402 | 402 | |
| 403 | -function wpinv_send_register_new_user( $data, $postarr ) { |
|
| 404 | - if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) { |
|
| 405 | - $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false; |
|
| 406 | - $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL; |
|
| 403 | +function wpinv_send_register_new_user($data, $postarr) { |
|
| 404 | + if (current_user_can('manage_options') && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) { |
|
| 405 | + $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false; |
|
| 406 | + $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL; |
|
| 407 | 407 | |
| 408 | - if ( $is_new_user && $email && !email_exists( $email ) ) { |
|
| 409 | - $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : ''; |
|
| 410 | - $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : ''; |
|
| 411 | - $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : ''; |
|
| 412 | - $user_nicename = $display_name ? trim( $display_name ) : $email; |
|
| 413 | - $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : ''; |
|
| 408 | + if ($is_new_user && $email && !email_exists($email)) { |
|
| 409 | + $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : ''; |
|
| 410 | + $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : ''; |
|
| 411 | + $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : ''; |
|
| 412 | + $user_nicename = $display_name ? trim($display_name) : $email; |
|
| 413 | + $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : ''; |
|
| 414 | 414 | |
| 415 | - $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true ); |
|
| 416 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
| 415 | + $user_login = sanitize_user(str_replace(' ', '', $display_name), true); |
|
| 416 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
| 417 | 417 | $new_user_login = strstr($email, '@', true); |
| 418 | - if ( validate_username( $user_login ) && username_exists( $user_login ) ) { |
|
| 419 | - $user_login = sanitize_user($new_user_login, true ); |
|
| 418 | + if (validate_username($user_login) && username_exists($user_login)) { |
|
| 419 | + $user_login = sanitize_user($new_user_login, true); |
|
| 420 | 420 | } |
| 421 | - if ( validate_username( $user_login ) && username_exists( $user_login ) ) { |
|
| 422 | - $user_append_text = rand(10,1000); |
|
| 423 | - $user_login = sanitize_user($new_user_login.$user_append_text, true ); |
|
| 421 | + if (validate_username($user_login) && username_exists($user_login)) { |
|
| 422 | + $user_append_text = rand(10, 1000); |
|
| 423 | + $user_login = sanitize_user($new_user_login . $user_append_text, true); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
| 426 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
| 427 | 427 | $user_login = $email; |
| 428 | 428 | } |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | $userdata = array( |
| 432 | 432 | 'user_login' => $user_login, |
| 433 | - 'user_pass' => wp_generate_password( 12, false ), |
|
| 434 | - 'user_email' => sanitize_text_field( $email ), |
|
| 433 | + 'user_pass' => wp_generate_password(12, false), |
|
| 434 | + 'user_email' => sanitize_text_field($email), |
|
| 435 | 435 | 'first_name' => $first_name, |
| 436 | 436 | 'last_name' => $last_name, |
| 437 | - 'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ), |
|
| 437 | + 'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50), |
|
| 438 | 438 | 'nickname' => $display_name, |
| 439 | 439 | 'display_name' => $display_name, |
| 440 | 440 | ); |
| 441 | 441 | |
| 442 | - $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata ); |
|
| 442 | + $userdata = apply_filters('wpinv_register_new_user_data', $userdata); |
|
| 443 | 443 | |
| 444 | - $new_user_id = wp_insert_user( $userdata ); |
|
| 444 | + $new_user_id = wp_insert_user($userdata); |
|
| 445 | 445 | |
| 446 | - if ( !is_wp_error( $new_user_id ) ) { |
|
| 446 | + if (!is_wp_error($new_user_id)) { |
|
| 447 | 447 | $data['post_author'] = $new_user_id; |
| 448 | 448 | $_POST['post_author'] = $new_user_id; |
| 449 | 449 | $_POST['post_author_override'] = $new_user_id; |
@@ -464,72 +464,72 @@ discard block |
||
| 464 | 464 | |
| 465 | 465 | $meta = array(); |
| 466 | 466 | ///$meta['_wpinv_user_id'] = $new_user_id; |
| 467 | - foreach ( $meta_fields as $field ) { |
|
| 468 | - $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : ''; |
|
| 467 | + foreach ($meta_fields as $field) { |
|
| 468 | + $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : ''; |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id ); |
|
| 471 | + $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id); |
|
| 472 | 472 | |
| 473 | 473 | // Update user meta. |
| 474 | - foreach ( $meta as $key => $value ) { |
|
| 475 | - update_user_meta( $new_user_id, $key, $value ); |
|
| 474 | + foreach ($meta as $key => $value) { |
|
| 475 | + update_user_meta($new_user_id, $key, $value); |
|
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - if ( function_exists( 'wp_send_new_user_notifications' ) ) { |
|
| 478 | + if (function_exists('wp_send_new_user_notifications')) { |
|
| 479 | 479 | // Send email notifications related to the creation of new user. |
| 480 | - wp_send_new_user_notifications( $new_user_id, 'user' ); |
|
| 480 | + wp_send_new_user_notifications($new_user_id, 'user'); |
|
| 481 | 481 | } |
| 482 | 482 | } else { |
| 483 | - wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ ); |
|
| 483 | + wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__); |
|
| 484 | 484 | } |
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | return $data; |
| 489 | 489 | } |
| 490 | -add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 ); |
|
| 490 | +add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2); |
|
| 491 | 491 | |
| 492 | -function wpinv_show_recurring_supported_gateways( $item_ID ) { |
|
| 492 | +function wpinv_show_recurring_supported_gateways($item_ID) { |
|
| 493 | 493 | $all_gateways = wpinv_get_payment_gateways(); |
| 494 | 494 | |
| 495 | - if ( !empty( $all_gateways ) ) { |
|
| 495 | + if (!empty($all_gateways)) { |
|
| 496 | 496 | $gateways = array(); |
| 497 | 497 | |
| 498 | - foreach ( $all_gateways as $key => $gateway ) { |
|
| 499 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
| 498 | + foreach ($all_gateways as $key => $gateway) { |
|
| 499 | + if (wpinv_gateway_support_subscription($key)) { |
|
| 500 | 500 | $gateways[] = $gateway['admin_label']; |
| 501 | 501 | } |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - if ( !empty( $gateways ) ) { |
|
| 504 | + if (!empty($gateways)) { |
|
| 505 | 505 | ?> |
| 506 | - <span class="description"><?php echo wp_sprintf( __( 'Recurring payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ); ?></span> |
|
| 506 | + <span class="description"><?php echo wp_sprintf(__('Recurring payments only supported by: %s', 'invoicing'), implode(', ', $gateways)); ?></span> |
|
| 507 | 507 | <?php |
| 508 | 508 | } |
| 509 | 509 | } |
| 510 | 510 | } |
| 511 | -add_action( 'wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1 ); |
|
| 511 | +add_action('wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1); |
|
| 512 | 512 | |
| 513 | -function wpinv_post_updated_messages( $messages ) { |
|
| 513 | +function wpinv_post_updated_messages($messages) { |
|
| 514 | 514 | global $post, $post_ID; |
| 515 | 515 | |
| 516 | 516 | $messages['wpi_discount'] = array( |
| 517 | 517 | 0 => '', |
| 518 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
| 519 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
| 520 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
| 521 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
| 522 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
| 523 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
| 524 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
| 525 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
| 526 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
| 527 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
| 518 | + 1 => __('Discount updated.', 'invoicing'), |
|
| 519 | + 2 => __('Custom field updated.', 'invoicing'), |
|
| 520 | + 3 => __('Custom field deleted.', 'invoicing'), |
|
| 521 | + 4 => __('Discount updated.', 'invoicing'), |
|
| 522 | + 5 => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int)$_GET['revision'], false)) : false, |
|
| 523 | + 6 => __('Discount updated.', 'invoicing'), |
|
| 524 | + 7 => __('Discount saved.', 'invoicing'), |
|
| 525 | + 8 => __('Discount submitted.', 'invoicing'), |
|
| 526 | + 9 => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))), |
|
| 527 | + 10 => __('Discount draft updated.', 'invoicing'), |
|
| 528 | 528 | ); |
| 529 | 529 | |
| 530 | 530 | return $messages; |
| 531 | 531 | } |
| 532 | -add_filter( 'post_updated_messages', 'wpinv_post_updated_messages', 10, 1 ); |
|
| 532 | +add_filter('post_updated_messages', 'wpinv_post_updated_messages', 10, 1); |
|
| 533 | 533 | |
| 534 | 534 | add_action('admin_init', 'admin_init_example_type'); |
| 535 | 535 | |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | function admin_init_example_type() { |
| 540 | 540 | global $typenow; |
| 541 | 541 | |
| 542 | - if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) { |
|
| 542 | + if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') { |
|
| 543 | 543 | add_filter('posts_search', 'posts_search_example_type', 10, 2); |
| 544 | 544 | } |
| 545 | 545 | } |
@@ -554,9 +554,9 @@ discard block |
||
| 554 | 554 | global $wpdb; |
| 555 | 555 | |
| 556 | 556 | if ($query->is_main_query() && !empty($query->query['s'])) { |
| 557 | - $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )"; |
|
| 558 | - if ( ! empty( $search ) ) { |
|
| 559 | - $search = preg_replace( '/^ AND /', '', $search ); |
|
| 557 | + $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )"; |
|
| 558 | + if (!empty($search)) { |
|
| 559 | + $search = preg_replace('/^ AND /', '', $search); |
|
| 560 | 560 | $search = " AND ( {$search} OR ( {$conditions_str} ) )"; |
| 561 | 561 | } else { |
| 562 | 562 | $search = " AND ( {$conditions_str} )"; |
@@ -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_Admin_Users { |
| 15 | 15 | private static $instance; |
| 16 | 16 | |
| 17 | 17 | public static function run() { |
| 18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Admin_Users ) ) { |
|
| 18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Admin_Users)) { |
|
| 19 | 19 | self::$instance = new WPInv_Admin_Users; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public function __construct() { |
| 26 | - add_filter( 'manage_users_columns', array( $this, 'wpinv_add_user_column') ); |
|
| 27 | - add_filter( 'manage_users_custom_column', array( $this, 'wpinv_user_column_content') , 10, 3 ); |
|
| 26 | + add_filter('manage_users_columns', array($this, 'wpinv_add_user_column')); |
|
| 27 | + add_filter('manage_users_custom_column', array($this, 'wpinv_user_column_content'), 10, 3); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | /** |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | * |
| 35 | 35 | * @return mixed |
| 36 | 36 | */ |
| 37 | - public function wpinv_add_user_column( $column ) { |
|
| 38 | - $column['wpinvoicing'] = __('Invoicing','invoicing'); |
|
| 37 | + public function wpinv_add_user_column($column) { |
|
| 38 | + $column['wpinvoicing'] = __('Invoicing', 'invoicing'); |
|
| 39 | 39 | return $column; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -48,10 +48,10 @@ discard block |
||
| 48 | 48 | * |
| 49 | 49 | * @return string |
| 50 | 50 | */ |
| 51 | - function wpinv_user_column_content( $val, $column_name, $user_id ) { |
|
| 51 | + function wpinv_user_column_content($val, $column_name, $user_id) { |
|
| 52 | 52 | switch ($column_name) { |
| 53 | 53 | case 'wpinvoicing' : |
| 54 | - return $this->get_user_invoices( $user_id ); |
|
| 54 | + return $this->get_user_invoices($user_id); |
|
| 55 | 55 | break; |
| 56 | 56 | default: |
| 57 | 57 | } |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @return string |
| 67 | 67 | */ |
| 68 | - public function get_user_invoices($user_id){ |
|
| 68 | + public function get_user_invoices($user_id) { |
|
| 69 | 69 | $output = ''; |
| 70 | 70 | $wp_query_args = array( |
| 71 | 71 | 'post_type' => 'wpi_invoice', |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | 'fields' => 'ids', |
| 75 | 75 | 'author' => $user_id, |
| 76 | 76 | ); |
| 77 | - $invoices = new WP_Query( $wp_query_args ); |
|
| 78 | - $count = absint( $invoices->found_posts ); |
|
| 77 | + $invoices = new WP_Query($wp_query_args); |
|
| 78 | + $count = absint($invoices->found_posts); |
|
| 79 | 79 | |
| 80 | - if(empty($count)){ |
|
| 81 | - $output .= __('No Invoice(s)','invoicing'); |
|
| 82 | - }else{ |
|
| 83 | - $link_url = admin_url( "edit.php?post_type=wpi_invoice&author=".absint($user_id) ); |
|
| 84 | - $link_text = sprintf( __('Invoices ( %d )', 'invoicing'), $count ); |
|
| 80 | + if (empty($count)) { |
|
| 81 | + $output .= __('No Invoice(s)', 'invoicing'); |
|
| 82 | + } else { |
|
| 83 | + $link_url = admin_url("edit.php?post_type=wpi_invoice&author=" . absint($user_id)); |
|
| 84 | + $link_text = sprintf(__('Invoices ( %d )', 'invoicing'), $count); |
|
| 85 | 85 | $output .= "<a href='$link_url' >$link_text</a>"; |
| 86 | 86 | } |
| 87 | 87 | |