@@ -1355,10 +1355,10 @@ |
||
| 1355 | 1355 | $data['cart_details'][$key]['price'] = wpinv_round_amount( $item_total ); |
| 1356 | 1356 | } |
| 1357 | 1357 | |
| 1358 | - $total = $data['subtotal'] - $data['discount'] + $data['tax']; |
|
| 1359 | - if ( $total < 0 ) { |
|
| 1360 | - $total = 0; |
|
| 1361 | - } |
|
| 1358 | + $total = $data['subtotal'] - $data['discount'] + $data['tax']; |
|
| 1359 | + if ( $total < 0 ) { |
|
| 1360 | + $total = 0; |
|
| 1361 | + } |
|
| 1362 | 1362 | |
| 1363 | 1363 | $data['subtotal'] = wpinv_round_amount( $cart_subtotal ); |
| 1364 | 1364 | $data['discount'] = wpinv_round_amount( $cart_discount ); |
@@ -974,8 +974,9 @@ |
||
| 974 | 974 | return false; |
| 975 | 975 | } |
| 976 | 976 | |
| 977 | - if ( empty( $this->ID ) ) |
|
| 978 | - return false; |
|
| 977 | + if ( empty( $this->ID ) ) { |
|
| 978 | + return false; |
|
| 979 | + } |
|
| 979 | 980 | |
| 980 | 981 | if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) { |
| 981 | 982 | $user = get_user_by( 'id', get_current_user_id() ); |
@@ -7,12 +7,12 @@ 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 | final class WPInv_Invoice { |
| 15 | - public $ID = 0; |
|
| 15 | + public $ID = 0; |
|
| 16 | 16 | public $title; |
| 17 | 17 | public $post_type; |
| 18 | 18 | |
@@ -66,17 +66,17 @@ discard block |
||
| 66 | 66 | public $full_name = ''; |
| 67 | 67 | public $parent_invoice = 0; |
| 68 | 68 | |
| 69 | - public function __construct( $invoice_id = false ) { |
|
| 70 | - if( empty( $invoice_id ) ) { |
|
| 69 | + public function __construct($invoice_id = false) { |
|
| 70 | + if (empty($invoice_id)) { |
|
| 71 | 71 | return false; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $this->setup_invoice( $invoice_id ); |
|
| 74 | + $this->setup_invoice($invoice_id); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function get( $key ) { |
|
| 78 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
| 79 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
| 77 | + public function get($key) { |
|
| 78 | + if (method_exists($this, 'get_' . $key)) { |
|
| 79 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
| 80 | 80 | } else { |
| 81 | 81 | $value = $this->$key; |
| 82 | 82 | } |
@@ -84,51 +84,51 @@ discard block |
||
| 84 | 84 | return $value; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - public function set( $key, $value ) { |
|
| 88 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
| 87 | + public function set($key, $value) { |
|
| 88 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
| 89 | 89 | |
| 90 | - if ( $key === 'status' ) { |
|
| 90 | + if ($key === 'status') { |
|
| 91 | 91 | $this->old_status = $this->status; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | - if ( ! in_array( $key, $ignore ) ) { |
|
| 95 | - $this->pending[ $key ] = $value; |
|
| 94 | + if (!in_array($key, $ignore)) { |
|
| 95 | + $this->pending[$key] = $value; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if( '_ID' !== $key ) { |
|
| 98 | + if ('_ID' !== $key) { |
|
| 99 | 99 | $this->$key = $value; |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - public function _isset( $name ) { |
|
| 104 | - if ( property_exists( $this, $name) ) { |
|
| 105 | - return false === empty( $this->$name ); |
|
| 103 | + public function _isset($name) { |
|
| 104 | + if (property_exists($this, $name)) { |
|
| 105 | + return false === empty($this->$name); |
|
| 106 | 106 | } else { |
| 107 | 107 | return null; |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - private function setup_invoice( $invoice_id ) { |
|
| 111 | + private function setup_invoice($invoice_id) { |
|
| 112 | 112 | $this->pending = array(); |
| 113 | 113 | |
| 114 | - if ( empty( $invoice_id ) ) { |
|
| 114 | + if (empty($invoice_id)) { |
|
| 115 | 115 | return false; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - $invoice = get_post( $invoice_id ); |
|
| 118 | + $invoice = get_post($invoice_id); |
|
| 119 | 119 | |
| 120 | - if( !$invoice || is_wp_error( $invoice ) ) { |
|
| 120 | + if (!$invoice || is_wp_error($invoice)) { |
|
| 121 | 121 | return false; |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | - if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) { |
|
| 124 | + if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) { |
|
| 125 | 125 | return false; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id ); |
|
| 128 | + do_action('wpinv_pre_setup_invoice', $this, $invoice_id); |
|
| 129 | 129 | |
| 130 | 130 | // Primary Identifier |
| 131 | - $this->ID = absint( $invoice_id ); |
|
| 131 | + $this->ID = absint($invoice_id); |
|
| 132 | 132 | $this->post_type = $invoice->post_type; |
| 133 | 133 | |
| 134 | 134 | // We have a payment, get the generic payment_meta item to reduce calls to it |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | $this->post_status = $this->status; |
| 141 | 141 | $this->mode = $this->setup_mode(); |
| 142 | 142 | $this->parent_invoice = $invoice->post_parent; |
| 143 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
| 143 | + $this->post_name = $this->setup_post_name($invoice); |
|
| 144 | 144 | $this->status_nicename = $this->setup_status_nicename($invoice->post_status); |
| 145 | 145 | |
| 146 | 146 | // Items |
@@ -163,8 +163,8 @@ discard block |
||
| 163 | 163 | |
| 164 | 164 | // User based |
| 165 | 165 | $this->ip = $this->setup_ip(); |
| 166 | - $this->user_id = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id(); |
|
| 167 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
| 166 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id(); |
|
| 167 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
| 168 | 168 | |
| 169 | 169 | $this->user_info = $this->setup_user_info(); |
| 170 | 170 | |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | $this->company = $this->user_info['company']; |
| 174 | 174 | $this->vat_number = $this->user_info['vat_number']; |
| 175 | 175 | $this->vat_rate = $this->user_info['vat_rate']; |
| 176 | - $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
| 176 | + $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
| 177 | 177 | $this->address = $this->user_info['address']; |
| 178 | 178 | $this->city = $this->user_info['city']; |
| 179 | 179 | $this->country = $this->user_info['country']; |
@@ -188,39 +188,39 @@ discard block |
||
| 188 | 188 | // Other Identifiers |
| 189 | 189 | $this->key = $this->setup_invoice_key(); |
| 190 | 190 | $this->number = $this->setup_invoice_number(); |
| 191 | - $this->title = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
| 191 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
| 192 | 192 | |
| 193 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name ); |
|
| 193 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
| 194 | 194 | |
| 195 | 195 | // Allow extensions to add items to this object via hook |
| 196 | - do_action( 'wpinv_setup_invoice', $this, $invoice_id ); |
|
| 196 | + do_action('wpinv_setup_invoice', $this, $invoice_id); |
|
| 197 | 197 | |
| 198 | 198 | return true; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - private function setup_status_nicename( $status ) { |
|
| 202 | - $all_invoice_statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
| 201 | + private function setup_status_nicename($status) { |
|
| 202 | + $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this); |
|
| 203 | 203 | |
| 204 | - if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
| 205 | - $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
| 204 | + if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) { |
|
| 205 | + $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
| 206 | 206 | } |
| 207 | - $status = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' ); |
|
| 207 | + $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing'); |
|
| 208 | 208 | |
| 209 | - return apply_filters( 'setup_status_nicename', $status ); |
|
| 209 | + return apply_filters('setup_status_nicename', $status); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - private function setup_post_name( $post = NULL ) { |
|
| 212 | + private function setup_post_name($post = NULL) { |
|
| 213 | 213 | global $wpdb; |
| 214 | 214 | |
| 215 | 215 | $post_name = ''; |
| 216 | 216 | |
| 217 | - if ( !empty( $post ) ) { |
|
| 218 | - if( !empty( $post->post_name ) ) { |
|
| 217 | + if (!empty($post)) { |
|
| 218 | + if (!empty($post->post_name)) { |
|
| 219 | 219 | $post_name = $post->post_name; |
| 220 | - } else if ( !empty( $post->ID ) ) { |
|
| 221 | - $post_name = wpinv_generate_post_name( $post->ID ); |
|
| 220 | + } else if (!empty($post->ID)) { |
|
| 221 | + $post_name = wpinv_generate_post_name($post->ID); |
|
| 222 | 222 | |
| 223 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
| 223 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
| 224 | 224 | } |
| 225 | 225 | } |
| 226 | 226 | |
@@ -228,12 +228,12 @@ discard block |
||
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | private function setup_due_date() { |
| 231 | - $due_date = $this->get_meta( '_wpinv_due_date' ); |
|
| 231 | + $due_date = $this->get_meta('_wpinv_due_date'); |
|
| 232 | 232 | |
| 233 | - if ( empty( $due_date ) ) { |
|
| 234 | - $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) ); |
|
| 235 | - $due_date = date_i18n( 'Y-m-d', $overdue_time ); |
|
| 236 | - } else if ( $due_date == 'none' ) { |
|
| 233 | + if (empty($due_date)) { |
|
| 234 | + $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days'))); |
|
| 235 | + $due_date = date_i18n('Y-m-d', $overdue_time); |
|
| 236 | + } else if ($due_date == 'none') { |
|
| 237 | 237 | $due_date = ''; |
| 238 | 238 | } |
| 239 | 239 | |
@@ -241,67 +241,67 @@ discard block |
||
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | private function setup_completed_date() { |
| 244 | - $invoice = get_post( $this->ID ); |
|
| 244 | + $invoice = get_post($this->ID); |
|
| 245 | 245 | |
| 246 | - if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) { |
|
| 246 | + if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) { |
|
| 247 | 247 | return false; // This invoice was never paid |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date; |
|
| 250 | + $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date; |
|
| 251 | 251 | |
| 252 | 252 | return $date; |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | private function setup_cart_details() { |
| 256 | - $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array(); |
|
| 256 | + $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array(); |
|
| 257 | 257 | return $cart_details; |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | public function array_convert() { |
| 261 | - return get_object_vars( $this ); |
|
| 261 | + return get_object_vars($this); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | private function setup_items() { |
| 265 | - $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array(); |
|
| 265 | + $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array(); |
|
| 266 | 266 | return $items; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | private function setup_fees() { |
| 270 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
| 270 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
| 271 | 271 | return $payment_fees; |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | private function setup_currency() { |
| 275 | - $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this ); |
|
| 275 | + $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this); |
|
| 276 | 276 | return $currency; |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | private function setup_discount() { |
| 280 | 280 | //$discount = $this->get_meta( '_wpinv_discount', true ); |
| 281 | - $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total ); |
|
| 282 | - if ( $discount < 0 ) { |
|
| 281 | + $discount = (float) $this->subtotal - ((float) $this->total - (float) $this->tax - (float) $this->fees_total); |
|
| 282 | + if ($discount < 0) { |
|
| 283 | 283 | $discount = 0; |
| 284 | 284 | } |
| 285 | - $discount = wpinv_round_amount( $discount ); |
|
| 285 | + $discount = wpinv_round_amount($discount); |
|
| 286 | 286 | |
| 287 | 287 | return $discount; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | private function setup_discount_code() { |
| 291 | - $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true ); |
|
| 291 | + $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true); |
|
| 292 | 292 | return $discount_code; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | private function setup_tax() { |
| 296 | 296 | |
| 297 | - $tax = $this->get_meta( '_wpinv_tax', true ); |
|
| 297 | + $tax = $this->get_meta('_wpinv_tax', true); |
|
| 298 | 298 | |
| 299 | 299 | // We don't have tax as it's own meta and no meta was passed |
| 300 | - if ( '' === $tax ) { |
|
| 301 | - $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0; |
|
| 300 | + if ('' === $tax) { |
|
| 301 | + $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - if ( $tax < 0 || ! $this->is_taxable() ) { |
|
| 304 | + if ($tax < 0 || !$this->is_taxable()) { |
|
| 305 | 305 | $tax = 0; |
| 306 | 306 | } |
| 307 | 307 | |
@@ -312,16 +312,16 @@ discard block |
||
| 312 | 312 | * If taxes are enabled, allow users to enable/disable taxes per invoice. |
| 313 | 313 | */ |
| 314 | 314 | private function setup_is_taxable() { |
| 315 | - return (int) $this->get_meta( '_wpinv_disable_taxes', true ); |
|
| 315 | + return (int) $this->get_meta('_wpinv_disable_taxes', true); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | private function setup_subtotal() { |
| 319 | 319 | $subtotal = 0; |
| 320 | 320 | $cart_details = $this->cart_details; |
| 321 | 321 | |
| 322 | - if ( is_array( $cart_details ) ) { |
|
| 323 | - foreach ( $cart_details as $item ) { |
|
| 324 | - if ( isset( $item['subtotal'] ) ) { |
|
| 322 | + if (is_array($cart_details)) { |
|
| 323 | + foreach ($cart_details as $item) { |
|
| 324 | + if (isset($item['subtotal'])) { |
|
| 325 | 325 | $subtotal += $item['subtotal']; |
| 326 | 326 | } |
| 327 | 327 | } |
@@ -335,23 +335,23 @@ discard block |
||
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | private function setup_discounts() { |
| 338 | - $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array(); |
|
| 338 | + $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array(); |
|
| 339 | 339 | return $discounts; |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | private function setup_total() { |
| 343 | - $amount = $this->get_meta( '_wpinv_total', true ); |
|
| 343 | + $amount = $this->get_meta('_wpinv_total', true); |
|
| 344 | 344 | |
| 345 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
| 346 | - $meta = $this->get_meta( '_wpinv_payment_meta', true ); |
|
| 347 | - $meta = maybe_unserialize( $meta ); |
|
| 345 | + if (empty($amount) && '0.00' != $amount) { |
|
| 346 | + $meta = $this->get_meta('_wpinv_payment_meta', true); |
|
| 347 | + $meta = maybe_unserialize($meta); |
|
| 348 | 348 | |
| 349 | - if ( isset( $meta['amount'] ) ) { |
|
| 349 | + if (isset($meta['amount'])) { |
|
| 350 | 350 | $amount = $meta['amount']; |
| 351 | 351 | } |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - if($amount < 0){ |
|
| 354 | + if ($amount < 0) { |
|
| 355 | 355 | $amount = 0; |
| 356 | 356 | } |
| 357 | 357 | |
@@ -359,13 +359,13 @@ discard block |
||
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | private function setup_mode() { |
| 362 | - return $this->get_meta( '_wpinv_mode' ); |
|
| 362 | + return $this->get_meta('_wpinv_mode'); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | private function setup_gateway() { |
| 366 | - $gateway = $this->get_meta( '_wpinv_gateway' ); |
|
| 366 | + $gateway = $this->get_meta('_wpinv_gateway'); |
|
| 367 | 367 | |
| 368 | - if ( empty( $gateway ) && 'publish' === $this->status ) { |
|
| 368 | + if (empty($gateway) && 'publish' === $this->status) { |
|
| 369 | 369 | $gateway = 'manual'; |
| 370 | 370 | } |
| 371 | 371 | |
@@ -373,23 +373,23 @@ discard block |
||
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | private function setup_gateway_title() { |
| 376 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
| 376 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
| 377 | 377 | return $gateway_title; |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | private function setup_transaction_id() { |
| 381 | - $transaction_id = $this->get_meta( '_wpinv_transaction_id' ); |
|
| 381 | + $transaction_id = $this->get_meta('_wpinv_transaction_id'); |
|
| 382 | 382 | |
| 383 | - if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) { |
|
| 383 | + if (empty($transaction_id) || (int) $transaction_id === (int) $this->ID) { |
|
| 384 | 384 | $gateway = $this->gateway; |
| 385 | - $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID ); |
|
| 385 | + $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID); |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | return $transaction_id; |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | private function setup_ip() { |
| 392 | - $ip = $this->get_meta( '_wpinv_user_ip' ); |
|
| 392 | + $ip = $this->get_meta('_wpinv_user_ip'); |
|
| 393 | 393 | return $ip; |
| 394 | 394 | } |
| 395 | 395 | |
@@ -399,62 +399,62 @@ discard block |
||
| 399 | 399 | ///} |
| 400 | 400 | |
| 401 | 401 | private function setup_first_name() { |
| 402 | - $first_name = $this->get_meta( '_wpinv_first_name' ); |
|
| 402 | + $first_name = $this->get_meta('_wpinv_first_name'); |
|
| 403 | 403 | return $first_name; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | private function setup_last_name() { |
| 407 | - $last_name = $this->get_meta( '_wpinv_last_name' ); |
|
| 407 | + $last_name = $this->get_meta('_wpinv_last_name'); |
|
| 408 | 408 | return $last_name; |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | private function setup_company() { |
| 412 | - $company = $this->get_meta( '_wpinv_company' ); |
|
| 412 | + $company = $this->get_meta('_wpinv_company'); |
|
| 413 | 413 | return $company; |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | private function setup_vat_number() { |
| 417 | - $vat_number = $this->get_meta( '_wpinv_vat_number' ); |
|
| 417 | + $vat_number = $this->get_meta('_wpinv_vat_number'); |
|
| 418 | 418 | return $vat_number; |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | private function setup_vat_rate() { |
| 422 | - $vat_rate = $this->get_meta( '_wpinv_vat_rate' ); |
|
| 422 | + $vat_rate = $this->get_meta('_wpinv_vat_rate'); |
|
| 423 | 423 | return $vat_rate; |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | private function setup_adddress_confirmed() { |
| 427 | - $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' ); |
|
| 427 | + $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed'); |
|
| 428 | 428 | return $adddress_confirmed; |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | private function setup_phone() { |
| 432 | - $phone = $this->get_meta( '_wpinv_phone' ); |
|
| 432 | + $phone = $this->get_meta('_wpinv_phone'); |
|
| 433 | 433 | return $phone; |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | private function setup_address() { |
| 437 | - $address = $this->get_meta( '_wpinv_address', true ); |
|
| 437 | + $address = $this->get_meta('_wpinv_address', true); |
|
| 438 | 438 | return $address; |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | private function setup_city() { |
| 442 | - $city = $this->get_meta( '_wpinv_city', true ); |
|
| 442 | + $city = $this->get_meta('_wpinv_city', true); |
|
| 443 | 443 | return $city; |
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | private function setup_country() { |
| 447 | - $country = $this->get_meta( '_wpinv_country', true ); |
|
| 447 | + $country = $this->get_meta('_wpinv_country', true); |
|
| 448 | 448 | return $country; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | private function setup_state() { |
| 452 | - $state = $this->get_meta( '_wpinv_state', true ); |
|
| 452 | + $state = $this->get_meta('_wpinv_state', true); |
|
| 453 | 453 | return $state; |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | private function setup_zip() { |
| 457 | - $zip = $this->get_meta( '_wpinv_zip', true ); |
|
| 457 | + $zip = $this->get_meta('_wpinv_zip', true); |
|
| 458 | 458 | return $zip; |
| 459 | 459 | } |
| 460 | 460 | |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | 'user_id' => $this->user_id, |
| 464 | 464 | 'first_name' => $this->first_name, |
| 465 | 465 | 'last_name' => $this->last_name, |
| 466 | - 'email' => get_the_author_meta( 'email', $this->user_id ), |
|
| 466 | + 'email' => get_the_author_meta('email', $this->user_id), |
|
| 467 | 467 | 'phone' => $this->phone, |
| 468 | 468 | 'address' => $this->address, |
| 469 | 469 | 'city' => $this->city, |
@@ -478,12 +478,12 @@ discard block |
||
| 478 | 478 | ); |
| 479 | 479 | |
| 480 | 480 | $user_info = array(); |
| 481 | - if ( isset( $this->payment_meta['user_info'] ) ) { |
|
| 482 | - $user_info = maybe_unserialize( $this->payment_meta['user_info'] ); |
|
| 481 | + if (isset($this->payment_meta['user_info'])) { |
|
| 482 | + $user_info = maybe_unserialize($this->payment_meta['user_info']); |
|
| 483 | 483 | |
| 484 | - if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) { |
|
| 484 | + if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) { |
|
| 485 | 485 | $this->user_id = $post->post_author; |
| 486 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
| 486 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
| 487 | 487 | |
| 488 | 488 | $user_info['user_id'] = $this->user_id; |
| 489 | 489 | $user_info['email'] = $this->email; |
@@ -492,13 +492,13 @@ discard block |
||
| 492 | 492 | } |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - $user_info = wp_parse_args( $user_info, $defaults ); |
|
| 495 | + $user_info = wp_parse_args($user_info, $defaults); |
|
| 496 | 496 | |
| 497 | 497 | // Get the user, but only if it's been created |
| 498 | - $user = get_userdata( $this->user_id ); |
|
| 498 | + $user = get_userdata($this->user_id); |
|
| 499 | 499 | |
| 500 | - if ( !empty( $user ) && $user->ID > 0 ) { |
|
| 501 | - if ( empty( $user_info ) ) { |
|
| 500 | + if (!empty($user) && $user->ID > 0) { |
|
| 501 | + if (empty($user_info)) { |
|
| 502 | 502 | $user_info = array( |
| 503 | 503 | 'user_id' => $user->ID, |
| 504 | 504 | 'first_name' => $user->first_name, |
@@ -507,23 +507,23 @@ discard block |
||
| 507 | 507 | 'discount' => '', |
| 508 | 508 | ); |
| 509 | 509 | } else { |
| 510 | - foreach ( $user_info as $key => $value ) { |
|
| 511 | - if ( ! empty( $value ) ) { |
|
| 510 | + foreach ($user_info as $key => $value) { |
|
| 511 | + if (!empty($value)) { |
|
| 512 | 512 | continue; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - switch( $key ) { |
|
| 515 | + switch ($key) { |
|
| 516 | 516 | case 'user_id': |
| 517 | - $user_info[ $key ] = $user->ID; |
|
| 517 | + $user_info[$key] = $user->ID; |
|
| 518 | 518 | break; |
| 519 | 519 | case 'first_name': |
| 520 | - $user_info[ $key ] = $user->first_name; |
|
| 520 | + $user_info[$key] = $user->first_name; |
|
| 521 | 521 | break; |
| 522 | 522 | case 'last_name': |
| 523 | - $user_info[ $key ] = $user->last_name; |
|
| 523 | + $user_info[$key] = $user->last_name; |
|
| 524 | 524 | break; |
| 525 | 525 | case 'email': |
| 526 | - $user_info[ $key ] = $user->user_email; |
|
| 526 | + $user_info[$key] = $user->user_email; |
|
| 527 | 527 | break; |
| 528 | 528 | } |
| 529 | 529 | } |
@@ -534,25 +534,25 @@ discard block |
||
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | private function setup_invoice_key() { |
| 537 | - $key = $this->get_meta( '_wpinv_key', true ); |
|
| 537 | + $key = $this->get_meta('_wpinv_key', true); |
|
| 538 | 538 | |
| 539 | 539 | return $key; |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | private function setup_invoice_number() { |
| 543 | - $number = $this->get_meta( '_wpinv_number', true ); |
|
| 543 | + $number = $this->get_meta('_wpinv_number', true); |
|
| 544 | 544 | |
| 545 | - if ( !$number ) { |
|
| 545 | + if (!$number) { |
|
| 546 | 546 | $number = $this->ID; |
| 547 | 547 | |
| 548 | - if ( $this->status == 'auto-draft' ) { |
|
| 549 | - if ( wpinv_sequential_number_active( $this->post_type ) ) { |
|
| 550 | - $next_number = wpinv_get_next_invoice_number( $this->post_type ); |
|
| 548 | + if ($this->status == 'auto-draft') { |
|
| 549 | + if (wpinv_sequential_number_active($this->post_type)) { |
|
| 550 | + $next_number = wpinv_get_next_invoice_number($this->post_type); |
|
| 551 | 551 | $number = $next_number; |
| 552 | 552 | } |
| 553 | 553 | } |
| 554 | 554 | |
| 555 | - $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
| 555 | + $number = wpinv_format_invoice_number($number, $this->post_type); |
|
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | return $number; |
@@ -561,10 +561,10 @@ discard block |
||
| 561 | 561 | private function insert_invoice() { |
| 562 | 562 | global $wpdb; |
| 563 | 563 | |
| 564 | - if ( empty( $this->post_type ) ) { |
|
| 565 | - if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) { |
|
| 564 | + if (empty($this->post_type)) { |
|
| 565 | + if (!empty($this->ID) && $post_type = get_post_type($this->ID)) { |
|
| 566 | 566 | $this->post_type = $post_type; |
| 567 | - } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) { |
|
| 567 | + } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) { |
|
| 568 | 568 | $this->post_type = $post_type; |
| 569 | 569 | } else { |
| 570 | 570 | $this->post_type = 'wpi_invoice'; |
@@ -572,16 +572,16 @@ discard block |
||
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | $invoice_number = $this->ID; |
| 575 | - if ( $number = $this->get_meta( '_wpinv_number', true ) ) { |
|
| 575 | + if ($number = $this->get_meta('_wpinv_number', true)) { |
|
| 576 | 576 | $invoice_number = $number; |
| 577 | 577 | } |
| 578 | 578 | |
| 579 | - if ( empty( $this->key ) ) { |
|
| 579 | + if (empty($this->key)) { |
|
| 580 | 580 | $this->key = self::generate_key(); |
| 581 | 581 | $this->pending['key'] = $this->key; |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | - if ( empty( $this->ip ) ) { |
|
| 584 | + if (empty($this->ip)) { |
|
| 585 | 585 | $this->ip = wpinv_get_ip(); |
| 586 | 586 | $this->pending['ip'] = $this->ip; |
| 587 | 587 | } |
@@ -618,61 +618,61 @@ discard block |
||
| 618 | 618 | 'post_status' => $this->status, |
| 619 | 619 | 'post_author' => $this->user_id, |
| 620 | 620 | 'post_type' => $this->post_type, |
| 621 | - 'post_date' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ), |
|
| 622 | - 'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ), |
|
| 621 | + 'post_date' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'), |
|
| 622 | + 'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1), |
|
| 623 | 623 | 'post_parent' => $this->parent_invoice, |
| 624 | 624 | ); |
| 625 | - $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this ); |
|
| 625 | + $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this); |
|
| 626 | 626 | |
| 627 | 627 | // Create a blank invoice |
| 628 | - if ( !empty( $this->ID ) ) { |
|
| 629 | - $args['ID'] = $this->ID; |
|
| 628 | + if (!empty($this->ID)) { |
|
| 629 | + $args['ID'] = $this->ID; |
|
| 630 | 630 | |
| 631 | - $invoice_id = wp_update_post( $args, true ); |
|
| 631 | + $invoice_id = wp_update_post($args, true); |
|
| 632 | 632 | } else { |
| 633 | - $invoice_id = wp_insert_post( $args, true ); |
|
| 633 | + $invoice_id = wp_insert_post($args, true); |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | - if ( is_wp_error( $invoice_id ) ) { |
|
| 636 | + if (is_wp_error($invoice_id)) { |
|
| 637 | 637 | return false; |
| 638 | 638 | } |
| 639 | 639 | |
| 640 | - if ( !empty( $invoice_id ) ) { |
|
| 640 | + if (!empty($invoice_id)) { |
|
| 641 | 641 | $this->ID = $invoice_id; |
| 642 | 642 | $this->_ID = $invoice_id; |
| 643 | 643 | |
| 644 | - $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data ); |
|
| 645 | - if ( ! empty( $this->payment_meta['fees'] ) ) { |
|
| 646 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] ); |
|
| 647 | - foreach( $this->fees as $fee ) { |
|
| 648 | - $this->increase_fees( $fee['amount'] ); |
|
| 644 | + $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data); |
|
| 645 | + if (!empty($this->payment_meta['fees'])) { |
|
| 646 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']); |
|
| 647 | + foreach ($this->fees as $fee) { |
|
| 648 | + $this->increase_fees($fee['amount']); |
|
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | - $this->update_meta( '_wpinv_payment_meta', $this->payment_meta ); |
|
| 652 | + $this->update_meta('_wpinv_payment_meta', $this->payment_meta); |
|
| 653 | 653 | $this->new = true; |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | return $this->ID; |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | - public function save( $setup = false ) { |
|
| 659 | + public function save($setup = false) { |
|
| 660 | 660 | global $wpi_session; |
| 661 | 661 | |
| 662 | 662 | $saved = false; |
| 663 | - if ( empty( $this->items ) ) { |
|
| 663 | + if (empty($this->items)) { |
|
| 664 | 664 | return $saved; // Don't save empty invoice. |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | - if ( empty( $this->key ) ) { |
|
| 667 | + if (empty($this->key)) { |
|
| 668 | 668 | $this->key = self::generate_key(); |
| 669 | 669 | $this->pending['key'] = $this->key; |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - if ( empty( $this->ID ) ) { |
|
| 672 | + if (empty($this->ID)) { |
|
| 673 | 673 | $invoice_id = $this->insert_invoice(); |
| 674 | 674 | |
| 675 | - if ( false === $invoice_id ) { |
|
| 675 | + if (false === $invoice_id) { |
|
| 676 | 676 | $saved = false; |
| 677 | 677 | } else { |
| 678 | 678 | $this->ID = $invoice_id; |
@@ -680,27 +680,27 @@ discard block |
||
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | // If we have something pending, let's save it |
| 683 | - if ( !empty( $this->pending ) ) { |
|
| 683 | + if (!empty($this->pending)) { |
|
| 684 | 684 | $total_increase = 0; |
| 685 | 685 | $total_decrease = 0; |
| 686 | 686 | |
| 687 | - foreach ( $this->pending as $key => $value ) { |
|
| 688 | - switch( $key ) { |
|
| 687 | + foreach ($this->pending as $key => $value) { |
|
| 688 | + switch ($key) { |
|
| 689 | 689 | case 'items': |
| 690 | 690 | // Update totals for pending items |
| 691 | - foreach ( $this->pending[ $key ] as $item ) { |
|
| 692 | - switch( $item['action'] ) { |
|
| 691 | + foreach ($this->pending[$key] as $item) { |
|
| 692 | + switch ($item['action']) { |
|
| 693 | 693 | case 'add': |
| 694 | 694 | $price = $item['price']; |
| 695 | 695 | $taxes = $item['tax']; |
| 696 | 696 | |
| 697 | - if ( 'publish' === $this->status ) { |
|
| 697 | + if ('publish' === $this->status) { |
|
| 698 | 698 | $total_increase += $price; |
| 699 | 699 | } |
| 700 | 700 | break; |
| 701 | 701 | |
| 702 | 702 | case 'remove': |
| 703 | - if ( 'publish' === $this->status ) { |
|
| 703 | + if ('publish' === $this->status) { |
|
| 704 | 704 | $total_decrease += $item['price']; |
| 705 | 705 | } |
| 706 | 706 | break; |
@@ -708,16 +708,16 @@ discard block |
||
| 708 | 708 | } |
| 709 | 709 | break; |
| 710 | 710 | case 'fees': |
| 711 | - if ( 'publish' !== $this->status ) { |
|
| 711 | + if ('publish' !== $this->status) { |
|
| 712 | 712 | break; |
| 713 | 713 | } |
| 714 | 714 | |
| 715 | - if ( empty( $this->pending[ $key ] ) ) { |
|
| 715 | + if (empty($this->pending[$key])) { |
|
| 716 | 716 | break; |
| 717 | 717 | } |
| 718 | 718 | |
| 719 | - foreach ( $this->pending[ $key ] as $fee ) { |
|
| 720 | - switch( $fee['action'] ) { |
|
| 719 | + foreach ($this->pending[$key] as $fee) { |
|
| 720 | + switch ($fee['action']) { |
|
| 721 | 721 | case 'add': |
| 722 | 722 | $total_increase += $fee['amount']; |
| 723 | 723 | break; |
@@ -729,86 +729,86 @@ discard block |
||
| 729 | 729 | } |
| 730 | 730 | break; |
| 731 | 731 | case 'status': |
| 732 | - $this->update_status( $this->status ); |
|
| 732 | + $this->update_status($this->status); |
|
| 733 | 733 | break; |
| 734 | 734 | case 'gateway': |
| 735 | - $this->update_meta( '_wpinv_gateway', $this->gateway ); |
|
| 735 | + $this->update_meta('_wpinv_gateway', $this->gateway); |
|
| 736 | 736 | break; |
| 737 | 737 | case 'mode': |
| 738 | - $this->update_meta( '_wpinv_mode', $this->mode ); |
|
| 738 | + $this->update_meta('_wpinv_mode', $this->mode); |
|
| 739 | 739 | break; |
| 740 | 740 | case 'transaction_id': |
| 741 | - $this->update_meta( '_wpinv_transaction_id', $this->transaction_id ); |
|
| 741 | + $this->update_meta('_wpinv_transaction_id', $this->transaction_id); |
|
| 742 | 742 | break; |
| 743 | 743 | case 'ip': |
| 744 | - $this->update_meta( '_wpinv_user_ip', $this->ip ); |
|
| 744 | + $this->update_meta('_wpinv_user_ip', $this->ip); |
|
| 745 | 745 | break; |
| 746 | 746 | ///case 'user_id': |
| 747 | 747 | ///$this->update_meta( '_wpinv_user_id', $this->user_id ); |
| 748 | 748 | ///$this->user_info['user_id'] = $this->user_id; |
| 749 | 749 | ///break; |
| 750 | 750 | case 'first_name': |
| 751 | - $this->update_meta( '_wpinv_first_name', $this->first_name ); |
|
| 751 | + $this->update_meta('_wpinv_first_name', $this->first_name); |
|
| 752 | 752 | $this->user_info['first_name'] = $this->first_name; |
| 753 | 753 | break; |
| 754 | 754 | case 'last_name': |
| 755 | - $this->update_meta( '_wpinv_last_name', $this->last_name ); |
|
| 755 | + $this->update_meta('_wpinv_last_name', $this->last_name); |
|
| 756 | 756 | $this->user_info['last_name'] = $this->last_name; |
| 757 | 757 | break; |
| 758 | 758 | case 'phone': |
| 759 | - $this->update_meta( '_wpinv_phone', $this->phone ); |
|
| 759 | + $this->update_meta('_wpinv_phone', $this->phone); |
|
| 760 | 760 | $this->user_info['phone'] = $this->phone; |
| 761 | 761 | break; |
| 762 | 762 | case 'address': |
| 763 | - $this->update_meta( '_wpinv_address', $this->address ); |
|
| 763 | + $this->update_meta('_wpinv_address', $this->address); |
|
| 764 | 764 | $this->user_info['address'] = $this->address; |
| 765 | 765 | break; |
| 766 | 766 | case 'city': |
| 767 | - $this->update_meta( '_wpinv_city', $this->city ); |
|
| 767 | + $this->update_meta('_wpinv_city', $this->city); |
|
| 768 | 768 | $this->user_info['city'] = $this->city; |
| 769 | 769 | break; |
| 770 | 770 | case 'country': |
| 771 | - $this->update_meta( '_wpinv_country', $this->country ); |
|
| 771 | + $this->update_meta('_wpinv_country', $this->country); |
|
| 772 | 772 | $this->user_info['country'] = $this->country; |
| 773 | 773 | break; |
| 774 | 774 | case 'state': |
| 775 | - $this->update_meta( '_wpinv_state', $this->state ); |
|
| 775 | + $this->update_meta('_wpinv_state', $this->state); |
|
| 776 | 776 | $this->user_info['state'] = $this->state; |
| 777 | 777 | break; |
| 778 | 778 | case 'zip': |
| 779 | - $this->update_meta( '_wpinv_zip', $this->zip ); |
|
| 779 | + $this->update_meta('_wpinv_zip', $this->zip); |
|
| 780 | 780 | $this->user_info['zip'] = $this->zip; |
| 781 | 781 | break; |
| 782 | 782 | case 'company': |
| 783 | - $this->update_meta( '_wpinv_company', $this->company ); |
|
| 783 | + $this->update_meta('_wpinv_company', $this->company); |
|
| 784 | 784 | $this->user_info['company'] = $this->company; |
| 785 | 785 | break; |
| 786 | 786 | case 'vat_number': |
| 787 | - $this->update_meta( '_wpinv_vat_number', $this->vat_number ); |
|
| 787 | + $this->update_meta('_wpinv_vat_number', $this->vat_number); |
|
| 788 | 788 | $this->user_info['vat_number'] = $this->vat_number; |
| 789 | 789 | |
| 790 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
| 791 | - if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) { |
|
| 792 | - $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false; |
|
| 793 | - $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed ); |
|
| 794 | - $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed; |
|
| 790 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
| 791 | + if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) { |
|
| 792 | + $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 793 | + $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed); |
|
| 794 | + $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed; |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | break; |
| 798 | 798 | case 'vat_rate': |
| 799 | - $this->update_meta( '_wpinv_vat_rate', $this->vat_rate ); |
|
| 799 | + $this->update_meta('_wpinv_vat_rate', $this->vat_rate); |
|
| 800 | 800 | $this->user_info['vat_rate'] = $this->vat_rate; |
| 801 | 801 | break; |
| 802 | 802 | case 'adddress_confirmed': |
| 803 | - $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed ); |
|
| 803 | + $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed); |
|
| 804 | 804 | $this->user_info['adddress_confirmed'] = $this->adddress_confirmed; |
| 805 | 805 | break; |
| 806 | 806 | |
| 807 | 807 | case 'key': |
| 808 | - $this->update_meta( '_wpinv_key', $this->key ); |
|
| 808 | + $this->update_meta('_wpinv_key', $this->key); |
|
| 809 | 809 | break; |
| 810 | 810 | case 'disable_taxes': |
| 811 | - $this->update_meta( '_wpinv_disable_taxes', $this->disable_taxes ); |
|
| 811 | + $this->update_meta('_wpinv_disable_taxes', $this->disable_taxes); |
|
| 812 | 812 | break; |
| 813 | 813 | case 'date': |
| 814 | 814 | $args = array( |
@@ -817,49 +817,49 @@ discard block |
||
| 817 | 817 | 'edit_date' => true, |
| 818 | 818 | ); |
| 819 | 819 | |
| 820 | - wp_update_post( $args ); |
|
| 820 | + wp_update_post($args); |
|
| 821 | 821 | break; |
| 822 | 822 | case 'due_date': |
| 823 | - if ( empty( $this->due_date ) ) { |
|
| 823 | + if (empty($this->due_date)) { |
|
| 824 | 824 | $this->due_date = 'none'; |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | - $this->update_meta( '_wpinv_due_date', $this->due_date ); |
|
| 827 | + $this->update_meta('_wpinv_due_date', $this->due_date); |
|
| 828 | 828 | break; |
| 829 | 829 | case 'completed_date': |
| 830 | - $this->update_meta( '_wpinv_completed_date', $this->completed_date ); |
|
| 830 | + $this->update_meta('_wpinv_completed_date', $this->completed_date); |
|
| 831 | 831 | break; |
| 832 | 832 | case 'discounts': |
| 833 | - if ( ! is_array( $this->discounts ) ) { |
|
| 834 | - $this->discounts = explode( ',', $this->discounts ); |
|
| 833 | + if (!is_array($this->discounts)) { |
|
| 834 | + $this->discounts = explode(',', $this->discounts); |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | - $this->user_info['discount'] = implode( ',', $this->discounts ); |
|
| 837 | + $this->user_info['discount'] = implode(',', $this->discounts); |
|
| 838 | 838 | break; |
| 839 | 839 | case 'discount': |
| 840 | - $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) ); |
|
| 840 | + $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount)); |
|
| 841 | 841 | break; |
| 842 | 842 | case 'discount_code': |
| 843 | - $this->update_meta( '_wpinv_discount_code', $this->discount_code ); |
|
| 843 | + $this->update_meta('_wpinv_discount_code', $this->discount_code); |
|
| 844 | 844 | break; |
| 845 | 845 | case 'parent_invoice': |
| 846 | 846 | $args = array( |
| 847 | 847 | 'ID' => $this->ID, |
| 848 | 848 | 'post_parent' => $this->parent_invoice, |
| 849 | 849 | ); |
| 850 | - wp_update_post( $args ); |
|
| 850 | + wp_update_post($args); |
|
| 851 | 851 | break; |
| 852 | 852 | default: |
| 853 | - do_action( 'wpinv_save', $this, $key ); |
|
| 853 | + do_action('wpinv_save', $this, $key); |
|
| 854 | 854 | break; |
| 855 | 855 | } |
| 856 | 856 | } |
| 857 | 857 | |
| 858 | - $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) ); |
|
| 859 | - $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) ); |
|
| 860 | - $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) ); |
|
| 858 | + $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal)); |
|
| 859 | + $this->update_meta('_wpinv_total', wpinv_round_amount($this->total)); |
|
| 860 | + $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax)); |
|
| 861 | 861 | |
| 862 | - $this->items = array_values( $this->items ); |
|
| 862 | + $this->items = array_values($this->items); |
|
| 863 | 863 | |
| 864 | 864 | $new_meta = array( |
| 865 | 865 | 'items' => $this->items, |
@@ -870,12 +870,12 @@ discard block |
||
| 870 | 870 | ); |
| 871 | 871 | |
| 872 | 872 | $meta = $this->get_meta(); |
| 873 | - $merged_meta = array_merge( $meta, $new_meta ); |
|
| 873 | + $merged_meta = array_merge($meta, $new_meta); |
|
| 874 | 874 | |
| 875 | 875 | // Only save the payment meta if it's changed |
| 876 | - if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) { |
|
| 877 | - $updated = $this->update_meta( '_wpinv_payment_meta', $merged_meta ); |
|
| 878 | - if ( false !== $updated ) { |
|
| 876 | + if (md5(serialize($meta)) !== md5(serialize($merged_meta))) { |
|
| 877 | + $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta); |
|
| 878 | + if (false !== $updated) { |
|
| 879 | 879 | $saved = true; |
| 880 | 880 | } |
| 881 | 881 | } |
@@ -883,15 +883,15 @@ discard block |
||
| 883 | 883 | $this->pending = array(); |
| 884 | 884 | $saved = true; |
| 885 | 885 | } else { |
| 886 | - $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) ); |
|
| 887 | - $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) ); |
|
| 888 | - $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) ); |
|
| 886 | + $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal)); |
|
| 887 | + $this->update_meta('_wpinv_total', wpinv_round_amount($this->total)); |
|
| 888 | + $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax)); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | - do_action( 'wpinv_invoice_save', $this, $saved ); |
|
| 891 | + do_action('wpinv_invoice_save', $this, $saved); |
|
| 892 | 892 | |
| 893 | - if ( true === $saved || $setup ) { |
|
| 894 | - $this->setup_invoice( $this->ID ); |
|
| 893 | + if (true === $saved || $setup) { |
|
| 894 | + $this->setup_invoice($this->ID); |
|
| 895 | 895 | } |
| 896 | 896 | |
| 897 | 897 | $this->refresh_item_ids(); |
@@ -899,7 +899,7 @@ discard block |
||
| 899 | 899 | return $saved; |
| 900 | 900 | } |
| 901 | 901 | |
| 902 | - public function add_fee( $args, $global = true ) { |
|
| 902 | + public function add_fee($args, $global = true) { |
|
| 903 | 903 | $default_args = array( |
| 904 | 904 | 'label' => '', |
| 905 | 905 | 'amount' => 0, |
@@ -909,75 +909,75 @@ discard block |
||
| 909 | 909 | 'item_id' => 0, |
| 910 | 910 | ); |
| 911 | 911 | |
| 912 | - $fee = wp_parse_args( $args, $default_args ); |
|
| 912 | + $fee = wp_parse_args($args, $default_args); |
|
| 913 | 913 | |
| 914 | - if ( empty( $fee['label'] ) ) { |
|
| 914 | + if (empty($fee['label'])) { |
|
| 915 | 915 | return false; |
| 916 | 916 | } |
| 917 | 917 | |
| 918 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
| 918 | + $fee['id'] = sanitize_title($fee['label']); |
|
| 919 | 919 | |
| 920 | - $this->fees[] = $fee; |
|
| 920 | + $this->fees[] = $fee; |
|
| 921 | 921 | |
| 922 | 922 | $added_fee = $fee; |
| 923 | 923 | $added_fee['action'] = 'add'; |
| 924 | 924 | $this->pending['fees'][] = $added_fee; |
| 925 | - reset( $this->fees ); |
|
| 925 | + reset($this->fees); |
|
| 926 | 926 | |
| 927 | - $this->increase_fees( $fee['amount'] ); |
|
| 927 | + $this->increase_fees($fee['amount']); |
|
| 928 | 928 | return true; |
| 929 | 929 | } |
| 930 | 930 | |
| 931 | - public function remove_fee( $key ) { |
|
| 931 | + public function remove_fee($key) { |
|
| 932 | 932 | $removed = false; |
| 933 | 933 | |
| 934 | - if ( is_numeric( $key ) ) { |
|
| 935 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
| 934 | + if (is_numeric($key)) { |
|
| 935 | + $removed = $this->remove_fee_by('index', $key); |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | return $removed; |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
| 942 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
|
| 941 | + public function remove_fee_by($key, $value, $global = false) { |
|
| 942 | + $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( |
|
| 943 | 943 | 'index', 'label', 'amount', 'type', |
| 944 | - ) ); |
|
| 944 | + )); |
|
| 945 | 945 | |
| 946 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
| 946 | + if (!in_array($key, $allowed_fee_keys)) { |
|
| 947 | 947 | return false; |
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | $removed = false; |
| 951 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
| 952 | - $removed_fee = $this->fees[ $value ]; |
|
| 951 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
| 952 | + $removed_fee = $this->fees[$value]; |
|
| 953 | 953 | $removed_fee['action'] = 'remove'; |
| 954 | 954 | $this->pending['fees'][] = $removed_fee; |
| 955 | 955 | |
| 956 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
| 956 | + $this->decrease_fees($removed_fee['amount']); |
|
| 957 | 957 | |
| 958 | - unset( $this->fees[ $value ] ); |
|
| 958 | + unset($this->fees[$value]); |
|
| 959 | 959 | $removed = true; |
| 960 | - } else if ( 'index' !== $key ) { |
|
| 961 | - foreach ( $this->fees as $index => $fee ) { |
|
| 962 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
| 960 | + } else if ('index' !== $key) { |
|
| 961 | + foreach ($this->fees as $index => $fee) { |
|
| 962 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
| 963 | 963 | $removed_fee = $fee; |
| 964 | 964 | $removed_fee['action'] = 'remove'; |
| 965 | 965 | $this->pending['fees'][] = $removed_fee; |
| 966 | 966 | |
| 967 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
| 967 | + $this->decrease_fees($removed_fee['amount']); |
|
| 968 | 968 | |
| 969 | - unset( $this->fees[ $index ] ); |
|
| 969 | + unset($this->fees[$index]); |
|
| 970 | 970 | $removed = true; |
| 971 | 971 | |
| 972 | - if ( false === $global ) { |
|
| 972 | + if (false === $global) { |
|
| 973 | 973 | break; |
| 974 | 974 | } |
| 975 | 975 | } |
| 976 | 976 | } |
| 977 | 977 | } |
| 978 | 978 | |
| 979 | - if ( true === $removed ) { |
|
| 980 | - $this->fees = array_values( $this->fees ); |
|
| 979 | + if (true === $removed) { |
|
| 980 | + $this->fees = array_values($this->fees); |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | return $removed; |
@@ -985,35 +985,35 @@ discard block |
||
| 985 | 985 | |
| 986 | 986 | |
| 987 | 987 | |
| 988 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
| 988 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
| 989 | 989 | // Bail if no note specified |
| 990 | - if( !$note ) { |
|
| 990 | + if (!$note) { |
|
| 991 | 991 | return false; |
| 992 | 992 | } |
| 993 | 993 | |
| 994 | - if ( empty( $this->ID ) ) |
|
| 994 | + if (empty($this->ID)) |
|
| 995 | 995 | return false; |
| 996 | 996 | |
| 997 | - if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) { |
|
| 998 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
| 997 | + if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) { |
|
| 998 | + $user = get_user_by('id', get_current_user_id()); |
|
| 999 | 999 | $comment_author = $user->display_name; |
| 1000 | 1000 | $comment_author_email = $user->user_email; |
| 1001 | 1001 | } else { |
| 1002 | 1002 | $comment_author = 'System'; |
| 1003 | 1003 | $comment_author_email = 'system@'; |
| 1004 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
| 1005 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
| 1004 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
| 1005 | + $comment_author_email = sanitize_email($comment_author_email); |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
| 1008 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
| 1009 | 1009 | |
| 1010 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
| 1010 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
| 1011 | 1011 | 'comment_post_ID' => $this->ID, |
| 1012 | 1012 | 'comment_content' => $note, |
| 1013 | 1013 | 'comment_agent' => 'WPInvoicing', |
| 1014 | 1014 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
| 1015 | - 'comment_date' => current_time( 'mysql' ), |
|
| 1016 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
| 1015 | + 'comment_date' => current_time('mysql'), |
|
| 1016 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
| 1017 | 1017 | 'comment_approved' => 1, |
| 1018 | 1018 | 'comment_parent' => 0, |
| 1019 | 1019 | 'comment_author' => $comment_author, |
@@ -1021,53 +1021,53 @@ discard block |
||
| 1021 | 1021 | 'comment_author_url' => '', |
| 1022 | 1022 | 'comment_author_email' => $comment_author_email, |
| 1023 | 1023 | 'comment_type' => 'wpinv_note' |
| 1024 | - ) ) ); |
|
| 1024 | + ))); |
|
| 1025 | 1025 | |
| 1026 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
| 1026 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
| 1027 | 1027 | |
| 1028 | - if ( $customer_type ) { |
|
| 1029 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
| 1028 | + if ($customer_type) { |
|
| 1029 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
| 1030 | 1030 | |
| 1031 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) ); |
|
| 1031 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); |
|
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | return $note_id; |
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | - private function increase_subtotal( $amount = 0.00 ) { |
|
| 1037 | + private function increase_subtotal($amount = 0.00) { |
|
| 1038 | 1038 | $amount = (float) $amount; |
| 1039 | 1039 | $this->subtotal += $amount; |
| 1040 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
| 1040 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
| 1041 | 1041 | |
| 1042 | 1042 | $this->recalculate_total(); |
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
| 1045 | + private function decrease_subtotal($amount = 0.00) { |
|
| 1046 | 1046 | $amount = (float) $amount; |
| 1047 | 1047 | $this->subtotal -= $amount; |
| 1048 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
| 1048 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
| 1049 | 1049 | |
| 1050 | - if ( $this->subtotal < 0 ) { |
|
| 1050 | + if ($this->subtotal < 0) { |
|
| 1051 | 1051 | $this->subtotal = 0; |
| 1052 | 1052 | } |
| 1053 | 1053 | |
| 1054 | 1054 | $this->recalculate_total(); |
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | - private function increase_fees( $amount = 0.00 ) { |
|
| 1058 | - $amount = (float)$amount; |
|
| 1057 | + private function increase_fees($amount = 0.00) { |
|
| 1058 | + $amount = (float) $amount; |
|
| 1059 | 1059 | $this->fees_total += $amount; |
| 1060 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
| 1060 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
| 1061 | 1061 | |
| 1062 | 1062 | $this->recalculate_total(); |
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | - private function decrease_fees( $amount = 0.00 ) { |
|
| 1065 | + private function decrease_fees($amount = 0.00) { |
|
| 1066 | 1066 | $amount = (float) $amount; |
| 1067 | 1067 | $this->fees_total -= $amount; |
| 1068 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
| 1068 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
| 1069 | 1069 | |
| 1070 | - if ( $this->fees_total < 0 ) { |
|
| 1070 | + if ($this->fees_total < 0) { |
|
| 1071 | 1071 | $this->fees_total = 0; |
| 1072 | 1072 | } |
| 1073 | 1073 | |
@@ -1078,54 +1078,54 @@ discard block |
||
| 1078 | 1078 | global $wpi_nosave; |
| 1079 | 1079 | |
| 1080 | 1080 | $this->total = $this->subtotal + $this->tax + $this->fees_total; |
| 1081 | - $this->total = wpinv_round_amount( $this->total ); |
|
| 1081 | + $this->total = wpinv_round_amount($this->total); |
|
| 1082 | 1082 | |
| 1083 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
| 1083 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | - public function increase_tax( $amount = 0.00 ) { |
|
| 1086 | + public function increase_tax($amount = 0.00) { |
|
| 1087 | 1087 | $amount = (float) $amount; |
| 1088 | 1088 | $this->tax += $amount; |
| 1089 | 1089 | |
| 1090 | 1090 | $this->recalculate_total(); |
| 1091 | 1091 | } |
| 1092 | 1092 | |
| 1093 | - public function decrease_tax( $amount = 0.00 ) { |
|
| 1093 | + public function decrease_tax($amount = 0.00) { |
|
| 1094 | 1094 | $amount = (float) $amount; |
| 1095 | 1095 | $this->tax -= $amount; |
| 1096 | 1096 | |
| 1097 | - if ( $this->tax < 0 ) { |
|
| 1097 | + if ($this->tax < 0) { |
|
| 1098 | 1098 | $this->tax = 0; |
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | 1101 | $this->recalculate_total(); |
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
| 1105 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
| 1104 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
| 1105 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
| 1106 | 1106 | |
| 1107 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) { |
|
| 1107 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) { |
|
| 1108 | 1108 | return false; // Don't permit status changes that aren't changes |
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
| 1111 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
| 1112 | 1112 | $updated = false; |
| 1113 | 1113 | |
| 1114 | - if ( $do_change ) { |
|
| 1115 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
| 1114 | + if ($do_change) { |
|
| 1115 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
| 1116 | 1116 | |
| 1117 | 1117 | $update_post_data = array(); |
| 1118 | 1118 | $update_post_data['ID'] = $this->ID; |
| 1119 | 1119 | $update_post_data['post_status'] = $new_status; |
| 1120 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
| 1121 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
| 1120 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
| 1121 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
| 1122 | 1122 | |
| 1123 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
| 1123 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
| 1124 | 1124 | |
| 1125 | - $updated = wp_update_post( $update_post_data ); |
|
| 1125 | + $updated = wp_update_post($update_post_data); |
|
| 1126 | 1126 | |
| 1127 | 1127 | // Process any specific status functions |
| 1128 | - switch( $new_status ) { |
|
| 1128 | + switch ($new_status) { |
|
| 1129 | 1129 | case 'wpi-refunded': |
| 1130 | 1130 | $this->process_refund(); |
| 1131 | 1131 | break; |
@@ -1138,9 +1138,9 @@ discard block |
||
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | // Status was changed. |
| 1141 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
| 1142 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
| 1143 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
| 1141 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
| 1142 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
| 1143 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
| 1144 | 1144 | } |
| 1145 | 1145 | |
| 1146 | 1146 | return $updated; |
@@ -1154,20 +1154,20 @@ discard block |
||
| 1154 | 1154 | $this->save(); |
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 1158 | - if ( empty( $meta_key ) ) { |
|
| 1157 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 1158 | + if (empty($meta_key)) { |
|
| 1159 | 1159 | return false; |
| 1160 | 1160 | } |
| 1161 | 1161 | |
| 1162 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
| 1162 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
| 1163 | 1163 | $current_meta = $this->get_meta(); |
| 1164 | - $current_meta[ $meta_key ] = $meta_value; |
|
| 1164 | + $current_meta[$meta_key] = $meta_value; |
|
| 1165 | 1165 | |
| 1166 | 1166 | $meta_key = '_wpinv_payment_meta'; |
| 1167 | 1167 | $meta_value = $current_meta; |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID ); |
|
| 1170 | + $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); |
|
| 1171 | 1171 | |
| 1172 | 1172 | // Do not update created date on invoice marked as paid. |
| 1173 | 1173 | /*if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) { |
@@ -1182,45 +1182,45 @@ discard block |
||
| 1182 | 1182 | wp_update_post( $args ); |
| 1183 | 1183 | }*/ |
| 1184 | 1184 | |
| 1185 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
| 1185 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
| 1186 | 1186 | } |
| 1187 | 1187 | |
| 1188 | 1188 | private function process_refund() { |
| 1189 | 1189 | $process_refund = true; |
| 1190 | 1190 | |
| 1191 | 1191 | // If the payment was not in publish, don't decrement stats as they were never incremented |
| 1192 | - if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) { |
|
| 1192 | + if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) { |
|
| 1193 | 1193 | $process_refund = false; |
| 1194 | 1194 | } |
| 1195 | 1195 | |
| 1196 | 1196 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
| 1197 | - $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this ); |
|
| 1197 | + $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this); |
|
| 1198 | 1198 | |
| 1199 | - if ( false === $process_refund ) { |
|
| 1199 | + if (false === $process_refund) { |
|
| 1200 | 1200 | return; |
| 1201 | 1201 | } |
| 1202 | 1202 | |
| 1203 | - do_action( 'wpinv_pre_refund_invoice', $this ); |
|
| 1203 | + do_action('wpinv_pre_refund_invoice', $this); |
|
| 1204 | 1204 | |
| 1205 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this ); |
|
| 1206 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this ); |
|
| 1207 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this ); |
|
| 1205 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this); |
|
| 1206 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this); |
|
| 1207 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this); |
|
| 1208 | 1208 | |
| 1209 | - do_action( 'wpinv_post_refund_invoice', $this ); |
|
| 1209 | + do_action('wpinv_post_refund_invoice', $this); |
|
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | 1212 | private function process_failure() { |
| 1213 | 1213 | $discounts = $this->discounts; |
| 1214 | - if ( empty( $discounts ) ) { |
|
| 1214 | + if (empty($discounts)) { |
|
| 1215 | 1215 | return; |
| 1216 | 1216 | } |
| 1217 | 1217 | |
| 1218 | - if ( ! is_array( $discounts ) ) { |
|
| 1219 | - $discounts = array_map( 'trim', explode( ',', $discounts ) ); |
|
| 1218 | + if (!is_array($discounts)) { |
|
| 1219 | + $discounts = array_map('trim', explode(',', $discounts)); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | - foreach ( $discounts as $discount ) { |
|
| 1223 | - wpinv_decrease_discount_usage( $discount ); |
|
| 1222 | + foreach ($discounts as $discount) { |
|
| 1223 | + wpinv_decrease_discount_usage($discount); |
|
| 1224 | 1224 | } |
| 1225 | 1225 | } |
| 1226 | 1226 | |
@@ -1228,92 +1228,92 @@ discard block |
||
| 1228 | 1228 | $process_pending = true; |
| 1229 | 1229 | |
| 1230 | 1230 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
| 1231 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) { |
|
| 1231 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) { |
|
| 1232 | 1232 | $process_pending = false; |
| 1233 | 1233 | } |
| 1234 | 1234 | |
| 1235 | 1235 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
| 1236 | - $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this ); |
|
| 1236 | + $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this); |
|
| 1237 | 1237 | |
| 1238 | - if ( false === $process_pending ) { |
|
| 1238 | + if (false === $process_pending) { |
|
| 1239 | 1239 | return; |
| 1240 | 1240 | } |
| 1241 | 1241 | |
| 1242 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this ); |
|
| 1243 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this ); |
|
| 1244 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this ); |
|
| 1242 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this); |
|
| 1243 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this); |
|
| 1244 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this); |
|
| 1245 | 1245 | |
| 1246 | 1246 | $this->completed_date = ''; |
| 1247 | - $this->update_meta( '_wpinv_completed_date', '' ); |
|
| 1247 | + $this->update_meta('_wpinv_completed_date', ''); |
|
| 1248 | 1248 | } |
| 1249 | 1249 | |
| 1250 | 1250 | // get data |
| 1251 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
| 1252 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
| 1251 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
| 1252 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
| 1253 | 1253 | |
| 1254 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
| 1254 | + if ($meta_key === '_wpinv_payment_meta') { |
|
| 1255 | 1255 | |
| 1256 | - if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is. |
|
| 1256 | + if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is. |
|
| 1257 | 1257 | |
| 1258 | - if ( empty( $meta['key'] ) ) { |
|
| 1258 | + if (empty($meta['key'])) { |
|
| 1259 | 1259 | $meta['key'] = $this->setup_invoice_key(); |
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | - if ( empty( $meta['date'] ) ) { |
|
| 1263 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
| 1262 | + if (empty($meta['date'])) { |
|
| 1263 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
| 1264 | 1264 | } |
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
| 1267 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
| 1268 | 1268 | |
| 1269 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
| 1269 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
| 1270 | 1270 | } |
| 1271 | 1271 | |
| 1272 | 1272 | public function get_description() { |
| 1273 | - $post = get_post( $this->ID ); |
|
| 1273 | + $post = get_post($this->ID); |
|
| 1274 | 1274 | |
| 1275 | - $description = !empty( $post ) ? $post->post_content : ''; |
|
| 1276 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this ); |
|
| 1275 | + $description = !empty($post) ? $post->post_content : ''; |
|
| 1276 | + return apply_filters('wpinv_get_description', $description, $this->ID, $this); |
|
| 1277 | 1277 | } |
| 1278 | 1278 | |
| 1279 | - public function get_status( $nicename = false ) { |
|
| 1280 | - if ( !$nicename ) { |
|
| 1279 | + public function get_status($nicename = false) { |
|
| 1280 | + if (!$nicename) { |
|
| 1281 | 1281 | $status = $this->status; |
| 1282 | 1282 | } else { |
| 1283 | 1283 | $status = $this->status_nicename; |
| 1284 | 1284 | } |
| 1285 | 1285 | |
| 1286 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
| 1286 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | 1289 | public function get_cart_details() { |
| 1290 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
| 1290 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
| 1291 | 1291 | } |
| 1292 | 1292 | |
| 1293 | - public function get_subtotal( $currency = false ) { |
|
| 1294 | - $subtotal = wpinv_round_amount( $this->subtotal ); |
|
| 1293 | + public function get_subtotal($currency = false) { |
|
| 1294 | + $subtotal = wpinv_round_amount($this->subtotal); |
|
| 1295 | 1295 | |
| 1296 | - if ( $currency ) { |
|
| 1297 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() ); |
|
| 1296 | + if ($currency) { |
|
| 1297 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency()); |
|
| 1298 | 1298 | } |
| 1299 | 1299 | |
| 1300 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
| 1300 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
| 1301 | 1301 | } |
| 1302 | 1302 | |
| 1303 | - public function get_total( $currency = false ) { |
|
| 1304 | - if ( $this->is_free_trial() ) { |
|
| 1305 | - $total = wpinv_round_amount( 0 ); |
|
| 1303 | + public function get_total($currency = false) { |
|
| 1304 | + if ($this->is_free_trial()) { |
|
| 1305 | + $total = wpinv_round_amount(0); |
|
| 1306 | 1306 | } else { |
| 1307 | - $total = wpinv_round_amount( $this->total ); |
|
| 1307 | + $total = wpinv_round_amount($this->total); |
|
| 1308 | 1308 | } |
| 1309 | - if ( $currency ) { |
|
| 1310 | - $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() ); |
|
| 1309 | + if ($currency) { |
|
| 1310 | + $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency()); |
|
| 1311 | 1311 | } |
| 1312 | 1312 | |
| 1313 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
| 1313 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
| 1314 | 1314 | } |
| 1315 | 1315 | |
| 1316 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
| 1316 | + public function get_recurring_details($field = '', $currency = false) { |
|
| 1317 | 1317 | $data = array(); |
| 1318 | 1318 | $data['cart_details'] = $this->cart_details; |
| 1319 | 1319 | $data['subtotal'] = $this->get_subtotal(); |
@@ -1321,119 +1321,119 @@ discard block |
||
| 1321 | 1321 | $data['tax'] = $this->get_tax(); |
| 1322 | 1322 | $data['total'] = $this->get_total(); |
| 1323 | 1323 | |
| 1324 | - if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) { |
|
| 1324 | + if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) { |
|
| 1325 | 1325 | $is_free_trial = $this->is_free_trial(); |
| 1326 | - $discounts = $this->get_discounts( true ); |
|
| 1326 | + $discounts = $this->get_discounts(true); |
|
| 1327 | 1327 | |
| 1328 | - if ( $is_free_trial || !empty( $discounts ) ) { |
|
| 1328 | + if ($is_free_trial || !empty($discounts)) { |
|
| 1329 | 1329 | $first_use_only = false; |
| 1330 | 1330 | |
| 1331 | - if ( !empty( $discounts ) ) { |
|
| 1332 | - foreach ( $discounts as $key => $code ) { |
|
| 1333 | - if ( wpinv_discount_is_recurring( $code, true ) && !$this->is_renewal() ) { |
|
| 1331 | + if (!empty($discounts)) { |
|
| 1332 | + foreach ($discounts as $key => $code) { |
|
| 1333 | + if (wpinv_discount_is_recurring($code, true) && !$this->is_renewal()) { |
|
| 1334 | 1334 | $first_use_only = true; |
| 1335 | 1335 | break; |
| 1336 | 1336 | } |
| 1337 | 1337 | } |
| 1338 | 1338 | } |
| 1339 | 1339 | |
| 1340 | - if ( !$first_use_only ) { |
|
| 1341 | - $data['subtotal'] = wpinv_round_amount( $this->subtotal ); |
|
| 1342 | - $data['discount'] = wpinv_round_amount( $this->discount ); |
|
| 1343 | - $data['tax'] = wpinv_round_amount( $this->tax ); |
|
| 1344 | - $data['total'] = wpinv_round_amount( $this->total ); |
|
| 1340 | + if (!$first_use_only) { |
|
| 1341 | + $data['subtotal'] = wpinv_round_amount($this->subtotal); |
|
| 1342 | + $data['discount'] = wpinv_round_amount($this->discount); |
|
| 1343 | + $data['tax'] = wpinv_round_amount($this->tax); |
|
| 1344 | + $data['total'] = wpinv_round_amount($this->total); |
|
| 1345 | 1345 | } else { |
| 1346 | 1346 | $cart_subtotal = 0; |
| 1347 | 1347 | $cart_discount = $this->discount; |
| 1348 | 1348 | $cart_tax = 0; |
| 1349 | 1349 | |
| 1350 | - foreach ( $this->cart_details as $key => $item ) { |
|
| 1351 | - $item_quantity = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
| 1352 | - $item_subtotal = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
| 1350 | + foreach ($this->cart_details as $key => $item) { |
|
| 1351 | + $item_quantity = $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
| 1352 | + $item_subtotal = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
| 1353 | 1353 | $item_discount = 0; |
| 1354 | - $item_tax = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0; |
|
| 1354 | + $item_tax = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float) $item['vat_rate']) : 0; |
|
| 1355 | 1355 | |
| 1356 | - if ( wpinv_prices_include_tax() ) { |
|
| 1357 | - $item_subtotal -= wpinv_round_amount( $item_tax ); |
|
| 1356 | + if (wpinv_prices_include_tax()) { |
|
| 1357 | + $item_subtotal -= wpinv_round_amount($item_tax); |
|
| 1358 | 1358 | } |
| 1359 | 1359 | |
| 1360 | 1360 | $item_total = $item_subtotal - $item_discount + $item_tax; |
| 1361 | 1361 | // Do not allow totals to go negative |
| 1362 | - if ( $item_total < 0 ) { |
|
| 1362 | + if ($item_total < 0) { |
|
| 1363 | 1363 | $item_total = 0; |
| 1364 | 1364 | } |
| 1365 | 1365 | |
| 1366 | - $cart_subtotal += (float)($item_subtotal); |
|
| 1367 | - $cart_discount += (float)($item_discount); |
|
| 1368 | - $cart_tax += (float)($item_tax); |
|
| 1366 | + $cart_subtotal += (float) ($item_subtotal); |
|
| 1367 | + $cart_discount += (float) ($item_discount); |
|
| 1368 | + $cart_tax += (float) ($item_tax); |
|
| 1369 | 1369 | |
| 1370 | - $data['cart_details'][$key]['discount'] = wpinv_round_amount( $item_discount ); |
|
| 1371 | - $data['cart_details'][$key]['tax'] = wpinv_round_amount( $item_tax ); |
|
| 1372 | - $data['cart_details'][$key]['price'] = wpinv_round_amount( $item_total ); |
|
| 1370 | + $data['cart_details'][$key]['discount'] = wpinv_round_amount($item_discount); |
|
| 1371 | + $data['cart_details'][$key]['tax'] = wpinv_round_amount($item_tax); |
|
| 1372 | + $data['cart_details'][$key]['price'] = wpinv_round_amount($item_total); |
|
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | 1375 | $total = $data['subtotal'] - $data['discount'] + $data['tax']; |
| 1376 | - if ( $total < 0 ) { |
|
| 1376 | + if ($total < 0) { |
|
| 1377 | 1377 | $total = 0; |
| 1378 | 1378 | } |
| 1379 | 1379 | |
| 1380 | - $data['subtotal'] = wpinv_round_amount( $cart_subtotal ); |
|
| 1381 | - $data['discount'] = wpinv_round_amount( $cart_discount ); |
|
| 1382 | - $data['tax'] = wpinv_round_amount( $cart_tax ); |
|
| 1383 | - $data['total'] = wpinv_round_amount( $total ); |
|
| 1380 | + $data['subtotal'] = wpinv_round_amount($cart_subtotal); |
|
| 1381 | + $data['discount'] = wpinv_round_amount($cart_discount); |
|
| 1382 | + $data['tax'] = wpinv_round_amount($cart_tax); |
|
| 1383 | + $data['total'] = wpinv_round_amount($total); |
|
| 1384 | 1384 | } |
| 1385 | 1385 | } |
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency ); |
|
| 1388 | + $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); |
|
| 1389 | 1389 | |
| 1390 | - if ( isset( $data[$field] ) ) { |
|
| 1391 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
| 1390 | + if (isset($data[$field])) { |
|
| 1391 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
| 1392 | 1392 | } |
| 1393 | 1393 | |
| 1394 | 1394 | return $data; |
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | - public function get_final_tax( $currency = false ) { |
|
| 1398 | - $final_total = wpinv_round_amount( $this->tax ); |
|
| 1399 | - if ( $currency ) { |
|
| 1400 | - $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() ); |
|
| 1397 | + public function get_final_tax($currency = false) { |
|
| 1398 | + $final_total = wpinv_round_amount($this->tax); |
|
| 1399 | + if ($currency) { |
|
| 1400 | + $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency()); |
|
| 1401 | 1401 | } |
| 1402 | 1402 | |
| 1403 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
| 1403 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
| 1404 | 1404 | } |
| 1405 | 1405 | |
| 1406 | - public function get_discounts( $array = false ) { |
|
| 1406 | + public function get_discounts($array = false) { |
|
| 1407 | 1407 | $discounts = $this->discounts; |
| 1408 | - if ( $array && $discounts ) { |
|
| 1409 | - $discounts = explode( ',', $discounts ); |
|
| 1408 | + if ($array && $discounts) { |
|
| 1409 | + $discounts = explode(',', $discounts); |
|
| 1410 | 1410 | } |
| 1411 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
| 1411 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
| 1412 | 1412 | } |
| 1413 | 1413 | |
| 1414 | - public function get_discount( $currency = false, $dash = false ) { |
|
| 1415 | - if ( !empty( $this->discounts ) ) { |
|
| 1414 | + public function get_discount($currency = false, $dash = false) { |
|
| 1415 | + if (!empty($this->discounts)) { |
|
| 1416 | 1416 | global $ajax_cart_details; |
| 1417 | 1417 | $ajax_cart_details = $this->get_cart_details(); |
| 1418 | 1418 | |
| 1419 | - if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) { |
|
| 1419 | + if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) { |
|
| 1420 | 1420 | $cart_items = $ajax_cart_details; |
| 1421 | 1421 | } else { |
| 1422 | 1422 | $cart_items = $this->items; |
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | - $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts ); |
|
| 1425 | + $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts); |
|
| 1426 | 1426 | } |
| 1427 | - $discount = wpinv_round_amount( $this->discount ); |
|
| 1427 | + $discount = wpinv_round_amount($this->discount); |
|
| 1428 | 1428 | $dash = $dash && $discount > 0 ? '–' : ''; |
| 1429 | 1429 | |
| 1430 | - if ( $currency ) { |
|
| 1431 | - $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() ); |
|
| 1430 | + if ($currency) { |
|
| 1431 | + $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency()); |
|
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | - $discount = $dash . $discount; |
|
| 1434 | + $discount = $dash . $discount; |
|
| 1435 | 1435 | |
| 1436 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
| 1436 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
| 1437 | 1437 | } |
| 1438 | 1438 | |
| 1439 | 1439 | public function get_discount_code() { |
@@ -1445,49 +1445,49 @@ discard block |
||
| 1445 | 1445 | return (int) $this->disable_taxes === 0; |
| 1446 | 1446 | } |
| 1447 | 1447 | |
| 1448 | - public function get_tax( $currency = false ) { |
|
| 1449 | - $tax = wpinv_round_amount( $this->tax ); |
|
| 1448 | + public function get_tax($currency = false) { |
|
| 1449 | + $tax = wpinv_round_amount($this->tax); |
|
| 1450 | 1450 | |
| 1451 | - if ( $currency ) { |
|
| 1452 | - $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() ); |
|
| 1451 | + if ($currency) { |
|
| 1452 | + $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency()); |
|
| 1453 | 1453 | } |
| 1454 | 1454 | |
| 1455 | - if ( ! $this->is_taxable() ) { |
|
| 1456 | - $tax = wpinv_round_amount( 0.00 ); |
|
| 1455 | + if (!$this->is_taxable()) { |
|
| 1456 | + $tax = wpinv_round_amount(0.00); |
|
| 1457 | 1457 | } |
| 1458 | 1458 | |
| 1459 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
| 1459 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | - public function get_fees( $type = 'all' ) { |
|
| 1463 | - $fees = array(); |
|
| 1462 | + public function get_fees($type = 'all') { |
|
| 1463 | + $fees = array(); |
|
| 1464 | 1464 | |
| 1465 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
| 1466 | - foreach ( $this->fees as $fee ) { |
|
| 1467 | - if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
| 1465 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
| 1466 | + foreach ($this->fees as $fee) { |
|
| 1467 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
| 1468 | 1468 | continue; |
| 1469 | 1469 | } |
| 1470 | 1470 | |
| 1471 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
| 1472 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
| 1473 | - $fees[] = $fee; |
|
| 1471 | + $fee['label'] = stripslashes($fee['label']); |
|
| 1472 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
| 1473 | + $fees[] = $fee; |
|
| 1474 | 1474 | } |
| 1475 | 1475 | } |
| 1476 | 1476 | |
| 1477 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
| 1477 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
| 1478 | 1478 | } |
| 1479 | 1479 | |
| 1480 | - public function get_fees_total( $type = 'all' ) { |
|
| 1480 | + public function get_fees_total($type = 'all') { |
|
| 1481 | 1481 | $fees_total = (float) 0.00; |
| 1482 | 1482 | |
| 1483 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
| 1484 | - if ( ! empty( $payment_fees ) ) { |
|
| 1485 | - foreach ( $payment_fees as $fee ) { |
|
| 1483 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
| 1484 | + if (!empty($payment_fees)) { |
|
| 1485 | + foreach ($payment_fees as $fee) { |
|
| 1486 | 1486 | $fees_total += (float) $fee['amount']; |
| 1487 | 1487 | } |
| 1488 | 1488 | } |
| 1489 | 1489 | |
| 1490 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
| 1490 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
| 1491 | 1491 | /* |
| 1492 | 1492 | $fees = $this->get_fees( $type ); |
| 1493 | 1493 | |
@@ -1507,116 +1507,116 @@ discard block |
||
| 1507 | 1507 | } |
| 1508 | 1508 | |
| 1509 | 1509 | public function get_user_id() { |
| 1510 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
| 1510 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | public function get_first_name() { |
| 1514 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this ); |
|
| 1514 | + return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); |
|
| 1515 | 1515 | } |
| 1516 | 1516 | |
| 1517 | 1517 | public function get_last_name() { |
| 1518 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this ); |
|
| 1518 | + return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); |
|
| 1519 | 1519 | } |
| 1520 | 1520 | |
| 1521 | 1521 | public function get_user_full_name() { |
| 1522 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
| 1522 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
| 1523 | 1523 | } |
| 1524 | 1524 | |
| 1525 | 1525 | public function get_user_info() { |
| 1526 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
| 1526 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
| 1527 | 1527 | } |
| 1528 | 1528 | |
| 1529 | 1529 | public function get_email() { |
| 1530 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
|
| 1530 | + return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); |
|
| 1531 | 1531 | } |
| 1532 | 1532 | |
| 1533 | 1533 | public function get_address() { |
| 1534 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this ); |
|
| 1534 | + return apply_filters('wpinv_address', $this->address, $this->ID, $this); |
|
| 1535 | 1535 | } |
| 1536 | 1536 | |
| 1537 | 1537 | public function get_phone() { |
| 1538 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this ); |
|
| 1538 | + return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); |
|
| 1539 | 1539 | } |
| 1540 | 1540 | |
| 1541 | 1541 | public function get_number() { |
| 1542 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this ); |
|
| 1542 | + return apply_filters('wpinv_number', $this->number, $this->ID, $this); |
|
| 1543 | 1543 | } |
| 1544 | 1544 | |
| 1545 | 1545 | public function get_items() { |
| 1546 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
| 1546 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
| 1547 | 1547 | } |
| 1548 | 1548 | |
| 1549 | 1549 | public function get_key() { |
| 1550 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this ); |
|
| 1550 | + return apply_filters('wpinv_key', $this->key, $this->ID, $this); |
|
| 1551 | 1551 | } |
| 1552 | 1552 | |
| 1553 | 1553 | public function get_transaction_id() { |
| 1554 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
| 1554 | + return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); |
|
| 1555 | 1555 | } |
| 1556 | 1556 | |
| 1557 | 1557 | public function get_gateway() { |
| 1558 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
| 1558 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | public function get_gateway_title() { |
| 1562 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway ); |
|
| 1562 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway); |
|
| 1563 | 1563 | |
| 1564 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this ); |
|
| 1564 | + return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); |
|
| 1565 | 1565 | } |
| 1566 | 1566 | |
| 1567 | 1567 | public function get_currency() { |
| 1568 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
| 1568 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
| 1569 | 1569 | } |
| 1570 | 1570 | |
| 1571 | 1571 | public function get_created_date() { |
| 1572 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
|
| 1572 | + return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); |
|
| 1573 | 1573 | } |
| 1574 | 1574 | |
| 1575 | - public function get_due_date( $display = false ) { |
|
| 1576 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
| 1575 | + public function get_due_date($display = false) { |
|
| 1576 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
| 1577 | 1577 | |
| 1578 | - if ( !$display || empty( $due_date ) ) { |
|
| 1578 | + if (!$display || empty($due_date)) { |
|
| 1579 | 1579 | return $due_date; |
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | - return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) ); |
|
| 1582 | + return date_i18n(get_option('date_format'), strtotime($due_date)); |
|
| 1583 | 1583 | } |
| 1584 | 1584 | |
| 1585 | 1585 | public function get_completed_date() { |
| 1586 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
| 1586 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
| 1587 | 1587 | } |
| 1588 | 1588 | |
| 1589 | - public function get_invoice_date( $formatted = true ) { |
|
| 1589 | + public function get_invoice_date($formatted = true) { |
|
| 1590 | 1590 | $date_completed = $this->completed_date; |
| 1591 | 1591 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
| 1592 | 1592 | |
| 1593 | - if ( $invoice_date == '' ) { |
|
| 1593 | + if ($invoice_date == '') { |
|
| 1594 | 1594 | $date_created = $this->date; |
| 1595 | 1595 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
| 1596 | 1596 | } |
| 1597 | 1597 | |
| 1598 | - if ( $formatted && $invoice_date ) { |
|
| 1599 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) ); |
|
| 1598 | + if ($formatted && $invoice_date) { |
|
| 1599 | + $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); |
|
| 1600 | 1600 | } |
| 1601 | 1601 | |
| 1602 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
| 1602 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
| 1603 | 1603 | } |
| 1604 | 1604 | |
| 1605 | 1605 | public function get_ip() { |
| 1606 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
| 1606 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
| 1607 | 1607 | } |
| 1608 | 1608 | |
| 1609 | - public function has_status( $status ) { |
|
| 1610 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); |
|
| 1609 | + public function has_status($status) { |
|
| 1610 | + return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); |
|
| 1611 | 1611 | } |
| 1612 | 1612 | |
| 1613 | - public function add_item( $item_id = 0, $args = array() ) { |
|
| 1613 | + public function add_item($item_id = 0, $args = array()) { |
|
| 1614 | 1614 | global $wpi_current_id, $wpi_item_id; |
| 1615 | 1615 | |
| 1616 | - $item = new WPInv_Item( $item_id ); |
|
| 1616 | + $item = new WPInv_Item($item_id); |
|
| 1617 | 1617 | |
| 1618 | 1618 | // Bail if this post isn't a item |
| 1619 | - if( !$item || $item->post_type !== 'wpi_item' ) { |
|
| 1619 | + if (!$item || $item->post_type !== 'wpi_item') { |
|
| 1620 | 1620 | return false; |
| 1621 | 1621 | } |
| 1622 | 1622 | |
@@ -1635,8 +1635,8 @@ discard block |
||
| 1635 | 1635 | 'fees' => array() |
| 1636 | 1636 | ); |
| 1637 | 1637 | |
| 1638 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults ); |
|
| 1639 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1; |
|
| 1638 | + $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); |
|
| 1639 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1; |
|
| 1640 | 1640 | |
| 1641 | 1641 | $wpi_current_id = $this->ID; |
| 1642 | 1642 | $wpi_item_id = $item->ID; |
@@ -1648,19 +1648,19 @@ discard block |
||
| 1648 | 1648 | $found_cart_key = false; |
| 1649 | 1649 | |
| 1650 | 1650 | if ($has_quantities) { |
| 1651 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
| 1651 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
| 1652 | 1652 | |
| 1653 | - foreach ( $this->items as $key => $cart_item ) { |
|
| 1654 | - if ( (int)$item_id !== (int)$cart_item['id'] ) { |
|
| 1653 | + foreach ($this->items as $key => $cart_item) { |
|
| 1654 | + if ((int) $item_id !== (int) $cart_item['id']) { |
|
| 1655 | 1655 | continue; |
| 1656 | 1656 | } |
| 1657 | 1657 | |
| 1658 | - $this->items[ $key ]['quantity'] += $args['quantity']; |
|
| 1658 | + $this->items[$key]['quantity'] += $args['quantity']; |
|
| 1659 | 1659 | break; |
| 1660 | 1660 | } |
| 1661 | 1661 | |
| 1662 | - foreach ( $this->cart_details as $cart_key => $cart_item ) { |
|
| 1663 | - if ( $item_id != $cart_item['id'] ) { |
|
| 1662 | + foreach ($this->cart_details as $cart_key => $cart_item) { |
|
| 1663 | + if ($item_id != $cart_item['id']) { |
|
| 1664 | 1664 | continue; |
| 1665 | 1665 | } |
| 1666 | 1666 | |
@@ -1672,29 +1672,29 @@ discard block |
||
| 1672 | 1672 | if ($has_quantities && $found_cart_key !== false) { |
| 1673 | 1673 | $cart_item = $this->cart_details[$found_cart_key]; |
| 1674 | 1674 | $item_price = $cart_item['item_price']; |
| 1675 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
| 1676 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
| 1675 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
| 1676 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
| 1677 | 1677 | |
| 1678 | 1678 | $new_quantity = $quantity + $args['quantity']; |
| 1679 | 1679 | $subtotal = $item_price * $new_quantity; |
| 1680 | 1680 | |
| 1681 | 1681 | $args['quantity'] = $new_quantity; |
| 1682 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
| 1683 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1682 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
| 1683 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
| 1684 | 1684 | |
| 1685 | - $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0; |
|
| 1686 | - $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0; |
|
| 1685 | + $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0; |
|
| 1686 | + $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0; |
|
| 1687 | 1687 | // The total increase equals the number removed * the item_price |
| 1688 | - $total_increased = wpinv_round_amount( $item_price ); |
|
| 1688 | + $total_increased = wpinv_round_amount($item_price); |
|
| 1689 | 1689 | |
| 1690 | - if ( wpinv_prices_include_tax() ) { |
|
| 1691 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 1690 | + if (wpinv_prices_include_tax()) { |
|
| 1691 | + $subtotal -= wpinv_round_amount($tax); |
|
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | - $total = $subtotal - $discount + $tax; |
|
| 1694 | + $total = $subtotal - $discount + $tax; |
|
| 1695 | 1695 | |
| 1696 | 1696 | // Do not allow totals to go negative |
| 1697 | - if( $total < 0 ) { |
|
| 1697 | + if ($total < 0) { |
|
| 1698 | 1698 | $total = 0; |
| 1699 | 1699 | } |
| 1700 | 1700 | |
@@ -1710,25 +1710,25 @@ discard block |
||
| 1710 | 1710 | $this->cart_details[$found_cart_key] = $cart_item; |
| 1711 | 1711 | } else { |
| 1712 | 1712 | // Set custom price. |
| 1713 | - if ( $args['custom_price'] !== '' ) { |
|
| 1713 | + if ($args['custom_price'] !== '') { |
|
| 1714 | 1714 | $item_price = $args['custom_price']; |
| 1715 | 1715 | } else { |
| 1716 | 1716 | // Allow overriding the price |
| 1717 | - if ( false !== $args['item_price'] ) { |
|
| 1717 | + if (false !== $args['item_price']) { |
|
| 1718 | 1718 | $item_price = $args['item_price']; |
| 1719 | 1719 | } else { |
| 1720 | - $item_price = wpinv_get_item_price( $item->ID ); |
|
| 1720 | + $item_price = wpinv_get_item_price($item->ID); |
|
| 1721 | 1721 | } |
| 1722 | 1722 | } |
| 1723 | 1723 | |
| 1724 | 1724 | // Sanitizing the price here so we don't have a dozen calls later |
| 1725 | - $item_price = wpinv_sanitize_amount( $item_price ); |
|
| 1726 | - $subtotal = wpinv_round_amount( $item_price * $args['quantity'] ); |
|
| 1725 | + $item_price = wpinv_sanitize_amount($item_price); |
|
| 1726 | + $subtotal = wpinv_round_amount($item_price * $args['quantity']); |
|
| 1727 | 1727 | |
| 1728 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
| 1729 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : ''; |
|
| 1730 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0; |
|
| 1731 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1728 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
| 1729 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : ''; |
|
| 1730 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0; |
|
| 1731 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
| 1732 | 1732 | |
| 1733 | 1733 | // Setup the items meta item |
| 1734 | 1734 | $new_item = array( |
@@ -1736,29 +1736,29 @@ discard block |
||
| 1736 | 1736 | 'quantity' => $args['quantity'], |
| 1737 | 1737 | ); |
| 1738 | 1738 | |
| 1739 | - $this->items[] = $new_item; |
|
| 1739 | + $this->items[] = $new_item; |
|
| 1740 | 1740 | |
| 1741 | - if ( wpinv_prices_include_tax() ) { |
|
| 1742 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 1741 | + if (wpinv_prices_include_tax()) { |
|
| 1742 | + $subtotal -= wpinv_round_amount($tax); |
|
| 1743 | 1743 | } |
| 1744 | 1744 | |
| 1745 | - $total = $subtotal - $discount + $tax; |
|
| 1745 | + $total = $subtotal - $discount + $tax; |
|
| 1746 | 1746 | |
| 1747 | 1747 | // Do not allow totals to go negative |
| 1748 | - if( $total < 0 ) { |
|
| 1748 | + if ($total < 0) { |
|
| 1749 | 1749 | $total = 0; |
| 1750 | 1750 | } |
| 1751 | 1751 | |
| 1752 | 1752 | $this->cart_details[] = array( |
| 1753 | 1753 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(), |
| 1754 | 1754 | 'id' => $item->ID, |
| 1755 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
| 1756 | - 'custom_price' => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ), |
|
| 1755 | + 'item_price' => wpinv_round_amount($item_price), |
|
| 1756 | + 'custom_price' => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''), |
|
| 1757 | 1757 | 'quantity' => $args['quantity'], |
| 1758 | 1758 | 'discount' => $discount, |
| 1759 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
| 1760 | - 'tax' => wpinv_round_amount( $tax ), |
|
| 1761 | - 'price' => wpinv_round_amount( $total ), |
|
| 1759 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
| 1760 | + 'tax' => wpinv_round_amount($tax), |
|
| 1761 | + 'price' => wpinv_round_amount($total), |
|
| 1762 | 1762 | 'vat_rate' => $tax_rate, |
| 1763 | 1763 | 'vat_class' => $tax_class, |
| 1764 | 1764 | 'meta' => $args['meta'], |
@@ -1768,18 +1768,18 @@ discard block |
||
| 1768 | 1768 | $subtotal = $subtotal - $discount; |
| 1769 | 1769 | } |
| 1770 | 1770 | |
| 1771 | - $added_item = end( $this->cart_details ); |
|
| 1772 | - $added_item['action'] = 'add'; |
|
| 1771 | + $added_item = end($this->cart_details); |
|
| 1772 | + $added_item['action'] = 'add'; |
|
| 1773 | 1773 | |
| 1774 | 1774 | $this->pending['items'][] = $added_item; |
| 1775 | 1775 | |
| 1776 | - $this->increase_subtotal( $subtotal ); |
|
| 1777 | - $this->increase_tax( $tax ); |
|
| 1776 | + $this->increase_subtotal($subtotal); |
|
| 1777 | + $this->increase_tax($tax); |
|
| 1778 | 1778 | |
| 1779 | 1779 | return true; |
| 1780 | 1780 | } |
| 1781 | 1781 | |
| 1782 | - public function remove_item( $item_id, $args = array() ) { |
|
| 1782 | + public function remove_item($item_id, $args = array()) { |
|
| 1783 | 1783 | // Set some defaults |
| 1784 | 1784 | $defaults = array( |
| 1785 | 1785 | 'quantity' => 1, |
@@ -1787,51 +1787,51 @@ discard block |
||
| 1787 | 1787 | 'custom_price' => '', |
| 1788 | 1788 | 'cart_index' => false, |
| 1789 | 1789 | ); |
| 1790 | - $args = wp_parse_args( $args, $defaults ); |
|
| 1790 | + $args = wp_parse_args($args, $defaults); |
|
| 1791 | 1791 | |
| 1792 | 1792 | // Bail if this post isn't a item |
| 1793 | - if ( get_post_type( $item_id ) !== 'wpi_item' ) { |
|
| 1793 | + if (get_post_type($item_id) !== 'wpi_item') { |
|
| 1794 | 1794 | return false; |
| 1795 | 1795 | } |
| 1796 | 1796 | |
| 1797 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
| 1797 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
| 1798 | 1798 | |
| 1799 | - foreach ( $this->items as $key => $item ) { |
|
| 1800 | - if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { |
|
| 1799 | + foreach ($this->items as $key => $item) { |
|
| 1800 | + if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) { |
|
| 1801 | 1801 | continue; |
| 1802 | 1802 | } |
| 1803 | 1803 | |
| 1804 | - if ( false !== $args['cart_index'] ) { |
|
| 1805 | - $cart_index = absint( $args['cart_index'] ); |
|
| 1806 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false; |
|
| 1804 | + if (false !== $args['cart_index']) { |
|
| 1805 | + $cart_index = absint($args['cart_index']); |
|
| 1806 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false; |
|
| 1807 | 1807 | |
| 1808 | - if ( ! empty( $cart_item ) ) { |
|
| 1808 | + if (!empty($cart_item)) { |
|
| 1809 | 1809 | // If the cart index item isn't the same item ID, don't remove it |
| 1810 | - if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { |
|
| 1810 | + if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { |
|
| 1811 | 1811 | continue; |
| 1812 | 1812 | } |
| 1813 | 1813 | } |
| 1814 | 1814 | } |
| 1815 | 1815 | |
| 1816 | - $item_quantity = $this->items[ $key ]['quantity']; |
|
| 1817 | - if ( $item_quantity > $args['quantity'] ) { |
|
| 1818 | - $this->items[ $key ]['quantity'] -= $args['quantity']; |
|
| 1816 | + $item_quantity = $this->items[$key]['quantity']; |
|
| 1817 | + if ($item_quantity > $args['quantity']) { |
|
| 1818 | + $this->items[$key]['quantity'] -= $args['quantity']; |
|
| 1819 | 1819 | break; |
| 1820 | 1820 | } else { |
| 1821 | - unset( $this->items[ $key ] ); |
|
| 1821 | + unset($this->items[$key]); |
|
| 1822 | 1822 | break; |
| 1823 | 1823 | } |
| 1824 | 1824 | } |
| 1825 | 1825 | |
| 1826 | 1826 | $found_cart_key = false; |
| 1827 | - if ( false === $args['cart_index'] ) { |
|
| 1828 | - foreach ( $this->cart_details as $cart_key => $item ) { |
|
| 1829 | - if ( $item_id != $item['id'] ) { |
|
| 1827 | + if (false === $args['cart_index']) { |
|
| 1828 | + foreach ($this->cart_details as $cart_key => $item) { |
|
| 1829 | + if ($item_id != $item['id']) { |
|
| 1830 | 1830 | continue; |
| 1831 | 1831 | } |
| 1832 | 1832 | |
| 1833 | - if ( false !== $args['item_price'] ) { |
|
| 1834 | - if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { |
|
| 1833 | + if (false !== $args['item_price']) { |
|
| 1834 | + if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) { |
|
| 1835 | 1835 | continue; |
| 1836 | 1836 | } |
| 1837 | 1837 | } |
@@ -1840,13 +1840,13 @@ discard block |
||
| 1840 | 1840 | break; |
| 1841 | 1841 | } |
| 1842 | 1842 | } else { |
| 1843 | - $cart_index = absint( $args['cart_index'] ); |
|
| 1843 | + $cart_index = absint($args['cart_index']); |
|
| 1844 | 1844 | |
| 1845 | - if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { |
|
| 1845 | + if (!array_key_exists($cart_index, $this->cart_details)) { |
|
| 1846 | 1846 | return false; // Invalid cart index passed. |
| 1847 | 1847 | } |
| 1848 | 1848 | |
| 1849 | - if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { |
|
| 1849 | + if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) { |
|
| 1850 | 1850 | return false; // We still need the proper Item ID to be sure. |
| 1851 | 1851 | } |
| 1852 | 1852 | |
@@ -1854,41 +1854,41 @@ discard block |
||
| 1854 | 1854 | } |
| 1855 | 1855 | |
| 1856 | 1856 | $cart_item = $this->cart_details[$found_cart_key]; |
| 1857 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
| 1857 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
| 1858 | 1858 | |
| 1859 | - if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { |
|
| 1859 | + if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { |
|
| 1860 | 1860 | //return false; // Invoice must contain at least one item. |
| 1861 | 1861 | } |
| 1862 | 1862 | |
| 1863 | - $discounts = $this->get_discounts(); |
|
| 1863 | + $discounts = $this->get_discounts(); |
|
| 1864 | 1864 | |
| 1865 | - if ( $quantity > $args['quantity'] ) { |
|
| 1865 | + if ($quantity > $args['quantity']) { |
|
| 1866 | 1866 | $item_price = $cart_item['item_price']; |
| 1867 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
| 1867 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
| 1868 | 1868 | |
| 1869 | - $new_quantity = max( $quantity - $args['quantity'], 1); |
|
| 1869 | + $new_quantity = max($quantity - $args['quantity'], 1); |
|
| 1870 | 1870 | $subtotal = $item_price * $new_quantity; |
| 1871 | 1871 | |
| 1872 | 1872 | $args['quantity'] = $new_quantity; |
| 1873 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
| 1874 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1873 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
| 1874 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
| 1875 | 1875 | |
| 1876 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0; |
|
| 1877 | - $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; |
|
| 1878 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0; |
|
| 1879 | - $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease; |
|
| 1876 | + $discount_decrease = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0; |
|
| 1877 | + $discount_decrease = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; |
|
| 1878 | + $tax_decrease = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0; |
|
| 1879 | + $tax_decrease = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease; |
|
| 1880 | 1880 | |
| 1881 | 1881 | // The total increase equals the number removed * the item_price |
| 1882 | - $total_decrease = wpinv_round_amount( $item_price ); |
|
| 1882 | + $total_decrease = wpinv_round_amount($item_price); |
|
| 1883 | 1883 | |
| 1884 | - if ( wpinv_prices_include_tax() ) { |
|
| 1885 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 1884 | + if (wpinv_prices_include_tax()) { |
|
| 1885 | + $subtotal -= wpinv_round_amount($tax); |
|
| 1886 | 1886 | } |
| 1887 | 1887 | |
| 1888 | - $total = $subtotal - $discount + $tax; |
|
| 1888 | + $total = $subtotal - $discount + $tax; |
|
| 1889 | 1889 | |
| 1890 | 1890 | // Do not allow totals to go negative |
| 1891 | - if( $total < 0 ) { |
|
| 1891 | + if ($total < 0) { |
|
| 1892 | 1892 | $total = 0; |
| 1893 | 1893 | } |
| 1894 | 1894 | |
@@ -1907,16 +1907,16 @@ discard block |
||
| 1907 | 1907 | |
| 1908 | 1908 | $this->cart_details[$found_cart_key] = $cart_item; |
| 1909 | 1909 | |
| 1910 | - $remove_item = end( $this->cart_details ); |
|
| 1910 | + $remove_item = end($this->cart_details); |
|
| 1911 | 1911 | } else { |
| 1912 | 1912 | $item_price = $cart_item['item_price']; |
| 1913 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
| 1914 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0; |
|
| 1913 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
| 1914 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0; |
|
| 1915 | 1915 | |
| 1916 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount; |
|
| 1916 | + $subtotal_decrease = ($item_price * $quantity) - $discount; |
|
| 1917 | 1917 | $tax_decrease = $tax; |
| 1918 | 1918 | |
| 1919 | - unset( $this->cart_details[$found_cart_key] ); |
|
| 1919 | + unset($this->cart_details[$found_cart_key]); |
|
| 1920 | 1920 | |
| 1921 | 1921 | $remove_item = $args; |
| 1922 | 1922 | $remove_item['id'] = $item_id; |
@@ -1927,8 +1927,8 @@ discard block |
||
| 1927 | 1927 | $remove_item['action'] = 'remove'; |
| 1928 | 1928 | $this->pending['items'][] = $remove_item; |
| 1929 | 1929 | |
| 1930 | - $this->decrease_subtotal( $subtotal_decrease ); |
|
| 1931 | - $this->decrease_tax( $tax_decrease ); |
|
| 1930 | + $this->decrease_subtotal($subtotal_decrease); |
|
| 1931 | + $this->decrease_tax($tax_decrease); |
|
| 1932 | 1932 | |
| 1933 | 1933 | return true; |
| 1934 | 1934 | } |
@@ -1936,7 +1936,7 @@ discard block |
||
| 1936 | 1936 | public function update_items($temp = false) { |
| 1937 | 1937 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave; |
| 1938 | 1938 | |
| 1939 | - if ( !empty( $this->cart_details ) ) { |
|
| 1939 | + if (!empty($this->cart_details)) { |
|
| 1940 | 1940 | $wpi_nosave = $temp; |
| 1941 | 1941 | $cart_subtotal = 0; |
| 1942 | 1942 | $cart_discount = 0; |
@@ -1946,65 +1946,65 @@ discard block |
||
| 1946 | 1946 | $_POST['wpinv_country'] = $this->country; |
| 1947 | 1947 | $_POST['wpinv_state'] = $this->state; |
| 1948 | 1948 | |
| 1949 | - foreach ( $this->cart_details as $key => $item ) { |
|
| 1949 | + foreach ($this->cart_details as $key => $item) { |
|
| 1950 | 1950 | $item_price = $item['item_price']; |
| 1951 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
| 1952 | - $amount = wpinv_round_amount( $item_price * $quantity ); |
|
| 1951 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
| 1952 | + $amount = wpinv_round_amount($item_price * $quantity); |
|
| 1953 | 1953 | $subtotal = $item_price * $quantity; |
| 1954 | 1954 | |
| 1955 | 1955 | $wpi_current_id = $this->ID; |
| 1956 | 1956 | $wpi_item_id = $item['id']; |
| 1957 | 1957 | |
| 1958 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() ); |
|
| 1958 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts()); |
|
| 1959 | 1959 | |
| 1960 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id ); |
|
| 1961 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id ); |
|
| 1962 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
| 1960 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id); |
|
| 1961 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id); |
|
| 1962 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
| 1963 | 1963 | |
| 1964 | - if ( ! $this->is_taxable() ) { |
|
| 1964 | + if (!$this->is_taxable()) { |
|
| 1965 | 1965 | $tax = 0; |
| 1966 | 1966 | } |
| 1967 | 1967 | |
| 1968 | - if ( wpinv_prices_include_tax() ) { |
|
| 1969 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 1968 | + if (wpinv_prices_include_tax()) { |
|
| 1969 | + $subtotal -= wpinv_round_amount($tax); |
|
| 1970 | 1970 | } |
| 1971 | 1971 | |
| 1972 | - $total = $subtotal - $discount + $tax; |
|
| 1972 | + $total = $subtotal - $discount + $tax; |
|
| 1973 | 1973 | |
| 1974 | 1974 | // Do not allow totals to go negative |
| 1975 | - if( $total < 0 ) { |
|
| 1975 | + if ($total < 0) { |
|
| 1976 | 1976 | $total = 0; |
| 1977 | 1977 | } |
| 1978 | 1978 | |
| 1979 | 1979 | $cart_details[] = array( |
| 1980 | 1980 | 'id' => $item['id'], |
| 1981 | 1981 | 'name' => $item['name'], |
| 1982 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
| 1983 | - 'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ), |
|
| 1982 | + 'item_price' => wpinv_round_amount($item_price), |
|
| 1983 | + 'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''), |
|
| 1984 | 1984 | 'quantity' => $quantity, |
| 1985 | 1985 | 'discount' => $discount, |
| 1986 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
| 1987 | - 'tax' => wpinv_round_amount( $tax ), |
|
| 1988 | - 'price' => wpinv_round_amount( $total ), |
|
| 1986 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
| 1987 | + 'tax' => wpinv_round_amount($tax), |
|
| 1988 | + 'price' => wpinv_round_amount($total), |
|
| 1989 | 1989 | 'vat_rate' => $tax_rate, |
| 1990 | 1990 | 'vat_class' => $tax_class, |
| 1991 | 1991 | 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
| 1992 | 1992 | 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
| 1993 | 1993 | ); |
| 1994 | 1994 | |
| 1995 | - $cart_subtotal += (float)($subtotal - $discount); // TODO |
|
| 1996 | - $cart_discount += (float)($discount); |
|
| 1997 | - $cart_tax += (float)($tax); |
|
| 1995 | + $cart_subtotal += (float) ($subtotal - $discount); // TODO |
|
| 1996 | + $cart_discount += (float) ($discount); |
|
| 1997 | + $cart_tax += (float) ($tax); |
|
| 1998 | 1998 | } |
| 1999 | - if ( $cart_subtotal < 0 ) { |
|
| 1999 | + if ($cart_subtotal < 0) { |
|
| 2000 | 2000 | $cart_subtotal = 0; |
| 2001 | 2001 | } |
| 2002 | - if ( $cart_tax < 0 ) { |
|
| 2002 | + if ($cart_tax < 0) { |
|
| 2003 | 2003 | $cart_tax = 0; |
| 2004 | 2004 | } |
| 2005 | - $this->subtotal = wpinv_round_amount( $cart_subtotal ); |
|
| 2006 | - $this->tax = wpinv_round_amount( $cart_tax ); |
|
| 2007 | - $this->discount = wpinv_round_amount( $cart_discount ); |
|
| 2005 | + $this->subtotal = wpinv_round_amount($cart_subtotal); |
|
| 2006 | + $this->tax = wpinv_round_amount($cart_tax); |
|
| 2007 | + $this->discount = wpinv_round_amount($cart_discount); |
|
| 2008 | 2008 | |
| 2009 | 2009 | $this->recalculate_total(); |
| 2010 | 2010 | |
@@ -2016,177 +2016,177 @@ discard block |
||
| 2016 | 2016 | |
| 2017 | 2017 | public function recalculate_totals($temp = false) { |
| 2018 | 2018 | $this->update_items($temp); |
| 2019 | - $this->save( true ); |
|
| 2019 | + $this->save(true); |
|
| 2020 | 2020 | |
| 2021 | 2021 | return $this; |
| 2022 | 2022 | } |
| 2023 | 2023 | |
| 2024 | 2024 | public function needs_payment() { |
| 2025 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this ); |
|
| 2025 | + $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this); |
|
| 2026 | 2026 | |
| 2027 | - if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) { |
|
| 2027 | + if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) { |
|
| 2028 | 2028 | $needs_payment = true; |
| 2029 | 2029 | } else { |
| 2030 | 2030 | $needs_payment = false; |
| 2031 | 2031 | } |
| 2032 | 2032 | |
| 2033 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses ); |
|
| 2033 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); |
|
| 2034 | 2034 | } |
| 2035 | 2035 | |
| 2036 | - public function get_checkout_payment_url( $with_key = false, $secret = false ) { |
|
| 2036 | + public function get_checkout_payment_url($with_key = false, $secret = false) { |
|
| 2037 | 2037 | $pay_url = wpinv_get_checkout_uri(); |
| 2038 | 2038 | |
| 2039 | - if ( is_ssl() ) { |
|
| 2040 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
| 2039 | + if (is_ssl()) { |
|
| 2040 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
| 2041 | 2041 | } |
| 2042 | 2042 | |
| 2043 | 2043 | $key = $this->get_key(); |
| 2044 | 2044 | |
| 2045 | - if ( $with_key ) { |
|
| 2046 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url ); |
|
| 2045 | + if ($with_key) { |
|
| 2046 | + $pay_url = add_query_arg('invoice_key', $key, $pay_url); |
|
| 2047 | 2047 | } else { |
| 2048 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url ); |
|
| 2048 | + $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); |
|
| 2049 | 2049 | } |
| 2050 | 2050 | |
| 2051 | - if ( $secret ) { |
|
| 2052 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url ); |
|
| 2051 | + if ($secret) { |
|
| 2052 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); |
|
| 2053 | 2053 | } |
| 2054 | 2054 | |
| 2055 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret ); |
|
| 2055 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret); |
|
| 2056 | 2056 | } |
| 2057 | 2057 | |
| 2058 | - public function get_view_url( $with_key = false ) { |
|
| 2059 | - $invoice_url = get_permalink( $this->ID ); |
|
| 2058 | + public function get_view_url($with_key = false) { |
|
| 2059 | + $invoice_url = get_permalink($this->ID); |
|
| 2060 | 2060 | |
| 2061 | - if ( $with_key ) { |
|
| 2062 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
| 2061 | + if ($with_key) { |
|
| 2062 | + $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url); |
|
| 2063 | 2063 | } |
| 2064 | 2064 | |
| 2065 | - return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key ); |
|
| 2065 | + return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key); |
|
| 2066 | 2066 | } |
| 2067 | 2067 | |
| 2068 | - public function generate_key( $string = '' ) { |
|
| 2069 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
| 2070 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key |
|
| 2068 | + public function generate_key($string = '') { |
|
| 2069 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
| 2070 | + return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key |
|
| 2071 | 2071 | } |
| 2072 | 2072 | |
| 2073 | 2073 | public function is_recurring() { |
| 2074 | - if ( empty( $this->cart_details ) ) { |
|
| 2074 | + if (empty($this->cart_details)) { |
|
| 2075 | 2075 | return false; |
| 2076 | 2076 | } |
| 2077 | 2077 | |
| 2078 | 2078 | $has_subscription = false; |
| 2079 | - foreach( $this->cart_details as $cart_item ) { |
|
| 2080 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 2079 | + foreach ($this->cart_details as $cart_item) { |
|
| 2080 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 2081 | 2081 | $has_subscription = true; |
| 2082 | 2082 | break; |
| 2083 | 2083 | } |
| 2084 | 2084 | } |
| 2085 | 2085 | |
| 2086 | - if ( count( $this->cart_details ) > 1 ) { |
|
| 2086 | + if (count($this->cart_details) > 1) { |
|
| 2087 | 2087 | $has_subscription = false; |
| 2088 | 2088 | } |
| 2089 | 2089 | |
| 2090 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
| 2090 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
| 2091 | 2091 | } |
| 2092 | 2092 | |
| 2093 | 2093 | public function is_free_trial() { |
| 2094 | 2094 | $is_free_trial = false; |
| 2095 | 2095 | |
| 2096 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
| 2097 | - if ( !empty( $item ) && $item->has_free_trial() ) { |
|
| 2096 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
| 2097 | + if (!empty($item) && $item->has_free_trial()) { |
|
| 2098 | 2098 | $is_free_trial = true; |
| 2099 | 2099 | } |
| 2100 | 2100 | } |
| 2101 | 2101 | |
| 2102 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this ); |
|
| 2102 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this); |
|
| 2103 | 2103 | } |
| 2104 | 2104 | |
| 2105 | 2105 | public function is_initial_free() { |
| 2106 | 2106 | $is_initial_free = false; |
| 2107 | 2107 | |
| 2108 | - if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) { |
|
| 2108 | + if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) { |
|
| 2109 | 2109 | $is_initial_free = true; |
| 2110 | 2110 | } |
| 2111 | 2111 | |
| 2112 | - return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details ); |
|
| 2112 | + return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details); |
|
| 2113 | 2113 | } |
| 2114 | 2114 | |
| 2115 | - public function get_recurring( $object = false ) { |
|
| 2115 | + public function get_recurring($object = false) { |
|
| 2116 | 2116 | $item = NULL; |
| 2117 | 2117 | |
| 2118 | - if ( empty( $this->cart_details ) ) { |
|
| 2118 | + if (empty($this->cart_details)) { |
|
| 2119 | 2119 | return $item; |
| 2120 | 2120 | } |
| 2121 | 2121 | |
| 2122 | - foreach( $this->cart_details as $cart_item ) { |
|
| 2123 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 2122 | + foreach ($this->cart_details as $cart_item) { |
|
| 2123 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 2124 | 2124 | $item = $cart_item['id']; |
| 2125 | 2125 | break; |
| 2126 | 2126 | } |
| 2127 | 2127 | } |
| 2128 | 2128 | |
| 2129 | - if ( $object ) { |
|
| 2130 | - $item = $item ? new WPInv_Item( $item ) : NULL; |
|
| 2129 | + if ($object) { |
|
| 2130 | + $item = $item ? new WPInv_Item($item) : NULL; |
|
| 2131 | 2131 | |
| 2132 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
| 2132 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
| 2133 | 2133 | } |
| 2134 | 2134 | |
| 2135 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
| 2135 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
| 2136 | 2136 | } |
| 2137 | 2137 | |
| 2138 | 2138 | public function get_subscription_name() { |
| 2139 | - $item = $this->get_recurring( true ); |
|
| 2139 | + $item = $this->get_recurring(true); |
|
| 2140 | 2140 | |
| 2141 | - if ( empty( $item ) ) { |
|
| 2141 | + if (empty($item)) { |
|
| 2142 | 2142 | return NULL; |
| 2143 | 2143 | } |
| 2144 | 2144 | |
| 2145 | - if ( !($name = $item->get_name()) ) { |
|
| 2145 | + if (!($name = $item->get_name())) { |
|
| 2146 | 2146 | $name = $item->post_name; |
| 2147 | 2147 | } |
| 2148 | 2148 | |
| 2149 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
|
| 2149 | + return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); |
|
| 2150 | 2150 | } |
| 2151 | 2151 | |
| 2152 | 2152 | public function get_subscription_id() { |
| 2153 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true ); |
|
| 2153 | + $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); |
|
| 2154 | 2154 | |
| 2155 | - if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { |
|
| 2156 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice ); |
|
| 2155 | + if (empty($subscription_id) && !empty($this->parent_invoice)) { |
|
| 2156 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice); |
|
| 2157 | 2157 | |
| 2158 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true ); |
|
| 2158 | + $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); |
|
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | 2161 | return $subscription_id; |
| 2162 | 2162 | } |
| 2163 | 2163 | |
| 2164 | 2164 | public function is_parent() { |
| 2165 | - $is_parent = empty( $this->parent_invoice ) ? true : false; |
|
| 2165 | + $is_parent = empty($this->parent_invoice) ? true : false; |
|
| 2166 | 2166 | |
| 2167 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this ); |
|
| 2167 | + return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); |
|
| 2168 | 2168 | } |
| 2169 | 2169 | |
| 2170 | 2170 | public function is_renewal() { |
| 2171 | 2171 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false; |
| 2172 | 2172 | |
| 2173 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this ); |
|
| 2173 | + return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); |
|
| 2174 | 2174 | } |
| 2175 | 2175 | |
| 2176 | 2176 | public function get_parent_payment() { |
| 2177 | 2177 | $parent_payment = NULL; |
| 2178 | 2178 | |
| 2179 | - if ( $this->is_renewal() ) { |
|
| 2180 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice ); |
|
| 2179 | + if ($this->is_renewal()) { |
|
| 2180 | + $parent_payment = wpinv_get_invoice($this->parent_invoice); |
|
| 2181 | 2181 | } |
| 2182 | 2182 | |
| 2183 | 2183 | return $parent_payment; |
| 2184 | 2184 | } |
| 2185 | 2185 | |
| 2186 | 2186 | public function is_paid() { |
| 2187 | - $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
|
| 2187 | + $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal')); |
|
| 2188 | 2188 | |
| 2189 | - return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
|
| 2189 | + return apply_filters('wpinv_invoice_is_paid', $is_paid, $this); |
|
| 2190 | 2190 | } |
| 2191 | 2191 | |
| 2192 | 2192 | /** |
@@ -2199,23 +2199,23 @@ discard block |
||
| 2199 | 2199 | } |
| 2200 | 2200 | |
| 2201 | 2201 | public function is_refunded() { |
| 2202 | - $is_refunded = $this->has_status( array( 'wpi-refunded' ) ); |
|
| 2202 | + $is_refunded = $this->has_status(array('wpi-refunded')); |
|
| 2203 | 2203 | |
| 2204 | - return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
|
| 2204 | + return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this); |
|
| 2205 | 2205 | } |
| 2206 | 2206 | |
| 2207 | 2207 | public function is_free() { |
| 2208 | 2208 | $is_free = false; |
| 2209 | 2209 | |
| 2210 | - if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) { |
|
| 2211 | - if ( $this->is_parent() && $this->is_recurring() ) { |
|
| 2212 | - $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true; |
|
| 2210 | + if (!((float) wpinv_round_amount($this->get_total()) > 0)) { |
|
| 2211 | + if ($this->is_parent() && $this->is_recurring()) { |
|
| 2212 | + $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true; |
|
| 2213 | 2213 | } else { |
| 2214 | 2214 | $is_free = true; |
| 2215 | 2215 | } |
| 2216 | 2216 | } |
| 2217 | 2217 | |
| 2218 | - return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
|
| 2218 | + return apply_filters('wpinv_invoice_is_free', $is_free, $this); |
|
| 2219 | 2219 | } |
| 2220 | 2220 | |
| 2221 | 2221 | public function has_vat() { |
@@ -2223,41 +2223,41 @@ discard block |
||
| 2223 | 2223 | |
| 2224 | 2224 | $requires_vat = false; |
| 2225 | 2225 | |
| 2226 | - if ( $this->country ) { |
|
| 2226 | + if ($this->country) { |
|
| 2227 | 2227 | $wpi_country = $this->country; |
| 2228 | 2228 | |
| 2229 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
| 2229 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
| 2230 | 2230 | } |
| 2231 | 2231 | |
| 2232 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
| 2232 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
| 2233 | 2233 | } |
| 2234 | 2234 | |
| 2235 | 2235 | public function refresh_item_ids() { |
| 2236 | 2236 | $item_ids = array(); |
| 2237 | 2237 | |
| 2238 | - if ( !empty( $this->cart_details ) ) { |
|
| 2239 | - foreach ( $this->cart_details as $key => $item ) { |
|
| 2240 | - if ( !empty( $item['id'] ) ) { |
|
| 2238 | + if (!empty($this->cart_details)) { |
|
| 2239 | + foreach ($this->cart_details as $key => $item) { |
|
| 2240 | + if (!empty($item['id'])) { |
|
| 2241 | 2241 | $item_ids[] = $item['id']; |
| 2242 | 2242 | } |
| 2243 | 2243 | } |
| 2244 | 2244 | } |
| 2245 | 2245 | |
| 2246 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : ''; |
|
| 2246 | + $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; |
|
| 2247 | 2247 | |
| 2248 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids ); |
|
| 2248 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids); |
|
| 2249 | 2249 | } |
| 2250 | 2250 | |
| 2251 | - public function get_invoice_quote_type( $post_id ) { |
|
| 2252 | - if ( empty( $post_id ) ) { |
|
| 2251 | + public function get_invoice_quote_type($post_id) { |
|
| 2252 | + if (empty($post_id)) { |
|
| 2253 | 2253 | return ''; |
| 2254 | 2254 | } |
| 2255 | 2255 | |
| 2256 | - $type = get_post_type( $post_id ); |
|
| 2256 | + $type = get_post_type($post_id); |
|
| 2257 | 2257 | |
| 2258 | - if ( 'wpi_invoice' === $type ) { |
|
| 2258 | + if ('wpi_invoice' === $type) { |
|
| 2259 | 2259 | $post_type = __('Invoice', 'invoicing'); |
| 2260 | - } else{ |
|
| 2260 | + } else { |
|
| 2261 | 2261 | $post_type = __('Quote', 'invoicing'); |
| 2262 | 2262 | } |
| 2263 | 2263 | |
@@ -12,124 +12,124 @@ discard block |
||
| 12 | 12 | */ |
| 13 | 13 | class WPInv_Session_Handler extends WPInv_Session { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Cookie name used for the session. |
|
| 17 | - * |
|
| 18 | - * @var string cookie name |
|
| 19 | - */ |
|
| 20 | - protected $_cookie; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Stores session expiry. |
|
| 24 | - * |
|
| 25 | - * @var int session due to expire timestamp |
|
| 26 | - */ |
|
| 27 | - protected $_session_expiring; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Stores session due to expire timestamp. |
|
| 31 | - * |
|
| 32 | - * @var string session expiration timestamp |
|
| 33 | - */ |
|
| 34 | - protected $_session_expiration; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * True when the cookie exists. |
|
| 38 | - * |
|
| 39 | - * @var bool Based on whether a cookie exists. |
|
| 40 | - */ |
|
| 41 | - protected $_has_cookie = false; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Table name for session data. |
|
| 45 | - * |
|
| 46 | - * @var string Custom session table name |
|
| 47 | - */ |
|
| 48 | - protected $_table; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Constructor for the session class. |
|
| 52 | - */ |
|
| 53 | - public function __construct() { |
|
| 54 | - |
|
| 55 | - $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
| 15 | + /** |
|
| 16 | + * Cookie name used for the session. |
|
| 17 | + * |
|
| 18 | + * @var string cookie name |
|
| 19 | + */ |
|
| 20 | + protected $_cookie; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Stores session expiry. |
|
| 24 | + * |
|
| 25 | + * @var int session due to expire timestamp |
|
| 26 | + */ |
|
| 27 | + protected $_session_expiring; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Stores session due to expire timestamp. |
|
| 31 | + * |
|
| 32 | + * @var string session expiration timestamp |
|
| 33 | + */ |
|
| 34 | + protected $_session_expiration; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * True when the cookie exists. |
|
| 38 | + * |
|
| 39 | + * @var bool Based on whether a cookie exists. |
|
| 40 | + */ |
|
| 41 | + protected $_has_cookie = false; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Table name for session data. |
|
| 45 | + * |
|
| 46 | + * @var string Custom session table name |
|
| 47 | + */ |
|
| 48 | + protected $_table; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Constructor for the session class. |
|
| 52 | + */ |
|
| 53 | + public function __construct() { |
|
| 54 | + |
|
| 55 | + $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
| 56 | 56 | add_action( 'init', array( $this, 'init' ), -1 ); |
| 57 | - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
| 58 | - add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
| 59 | - add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Init hooks and session data. |
|
| 64 | - * |
|
| 65 | - * @since 3.3.0 |
|
| 66 | - */ |
|
| 67 | - public function init() { |
|
| 68 | - $this->init_session_cookie(); |
|
| 69 | - |
|
| 70 | - if ( ! is_user_logged_in() ) { |
|
| 71 | - add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Setup cookie and customer ID. |
|
| 77 | - * |
|
| 78 | - * @since 3.6.0 |
|
| 79 | - */ |
|
| 80 | - public function init_session_cookie() { |
|
| 81 | - $cookie = $this->get_session_cookie(); |
|
| 82 | - |
|
| 83 | - if ( $cookie ) { |
|
| 84 | - $this->_customer_id = $cookie[0]; |
|
| 85 | - $this->_session_expiration = $cookie[1]; |
|
| 86 | - $this->_session_expiring = $cookie[2]; |
|
| 87 | - $this->_has_cookie = true; |
|
| 88 | - $this->_data = $this->get_session_data(); |
|
| 89 | - |
|
| 90 | - // If the user logs in, update session. |
|
| 91 | - if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
| 92 | - $this->_customer_id = get_current_user_id(); |
|
| 93 | - $this->_dirty = true; |
|
| 94 | - $this->save_data(); |
|
| 95 | - $this->set_customer_session_cookie( true ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // Update session if its close to expiring. |
|
| 99 | - if ( time() > $this->_session_expiring ) { |
|
| 100 | - $this->set_session_expiration(); |
|
| 101 | - $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
| 102 | - } |
|
| 103 | - } else { |
|
| 104 | - $this->set_session_expiration(); |
|
| 105 | - $this->_customer_id = $this->generate_customer_id(); |
|
| 106 | - $this->_data = $this->get_session_data(); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
| 112 | - * |
|
| 113 | - * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
| 114 | - * |
|
| 115 | - * Warning: Cookies will only be set if this is called before the headers are sent. |
|
| 116 | - * |
|
| 117 | - * @param bool $set Should the session cookie be set. |
|
| 118 | - */ |
|
| 119 | - public function set_customer_session_cookie( $set ) { |
|
| 120 | - if ( $set ) { |
|
| 121 | - $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
| 122 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 123 | - $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
| 124 | - $this->_has_cookie = true; |
|
| 125 | - |
|
| 126 | - if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
| 127 | - $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
| 57 | + add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
| 58 | + add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
| 59 | + add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Init hooks and session data. |
|
| 64 | + * |
|
| 65 | + * @since 3.3.0 |
|
| 66 | + */ |
|
| 67 | + public function init() { |
|
| 68 | + $this->init_session_cookie(); |
|
| 69 | + |
|
| 70 | + if ( ! is_user_logged_in() ) { |
|
| 71 | + add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Setup cookie and customer ID. |
|
| 77 | + * |
|
| 78 | + * @since 3.6.0 |
|
| 79 | + */ |
|
| 80 | + public function init_session_cookie() { |
|
| 81 | + $cookie = $this->get_session_cookie(); |
|
| 82 | + |
|
| 83 | + if ( $cookie ) { |
|
| 84 | + $this->_customer_id = $cookie[0]; |
|
| 85 | + $this->_session_expiration = $cookie[1]; |
|
| 86 | + $this->_session_expiring = $cookie[2]; |
|
| 87 | + $this->_has_cookie = true; |
|
| 88 | + $this->_data = $this->get_session_data(); |
|
| 89 | + |
|
| 90 | + // If the user logs in, update session. |
|
| 91 | + if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
| 92 | + $this->_customer_id = get_current_user_id(); |
|
| 93 | + $this->_dirty = true; |
|
| 94 | + $this->save_data(); |
|
| 95 | + $this->set_customer_session_cookie( true ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // Update session if its close to expiring. |
|
| 99 | + if ( time() > $this->_session_expiring ) { |
|
| 100 | + $this->set_session_expiration(); |
|
| 101 | + $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
| 102 | + } |
|
| 103 | + } else { |
|
| 104 | + $this->set_session_expiration(); |
|
| 105 | + $this->_customer_id = $this->generate_customer_id(); |
|
| 106 | + $this->_data = $this->get_session_data(); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Sets the session cookie on-demand (usually after adding an item to the cart). |
|
| 112 | + * |
|
| 113 | + * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set. |
|
| 114 | + * |
|
| 115 | + * Warning: Cookies will only be set if this is called before the headers are sent. |
|
| 116 | + * |
|
| 117 | + * @param bool $set Should the session cookie be set. |
|
| 118 | + */ |
|
| 119 | + public function set_customer_session_cookie( $set ) { |
|
| 120 | + if ( $set ) { |
|
| 121 | + $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
|
| 122 | + $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 123 | + $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
|
| 124 | + $this->_has_cookie = true; |
|
| 125 | + |
|
| 126 | + if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
| 127 | + $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
| 133 | 133 | if ( ! headers_sent() ) { |
| 134 | 134 | setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
| 135 | 135 | } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
@@ -138,96 +138,96 @@ discard block |
||
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Should the session cookie be secure? |
|
| 143 | - * |
|
| 144 | - * @since 3.6.0 |
|
| 145 | - * @return bool |
|
| 146 | - */ |
|
| 147 | - protected function use_secure_cookie() { |
|
| 141 | + /** |
|
| 142 | + * Should the session cookie be secure? |
|
| 143 | + * |
|
| 144 | + * @since 3.6.0 |
|
| 145 | + * @return bool |
|
| 146 | + */ |
|
| 147 | + protected function use_secure_cookie() { |
|
| 148 | 148 | $is_https = false !== strstr( get_option( 'home' ), 'https:' ); |
| 149 | - return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
| 154 | - * |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - public function has_session() { |
|
| 158 | - return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * Set session expiration. |
|
| 163 | - */ |
|
| 164 | - public function set_session_expiration() { |
|
| 165 | - $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
| 166 | - $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Generate a unique customer ID for guests, or return user ID if logged in. |
|
| 171 | - * |
|
| 172 | - * Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID. |
|
| 173 | - * |
|
| 174 | - * @return string |
|
| 175 | - */ |
|
| 176 | - public function generate_customer_id() { |
|
| 177 | - $customer_id = ''; |
|
| 178 | - |
|
| 179 | - if ( is_user_logged_in() ) { |
|
| 180 | - $customer_id = get_current_user_id(); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - if ( empty( $customer_id ) ) { |
|
| 149 | + return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Return true if the current user has an active session, i.e. a cookie to retrieve values. |
|
| 154 | + * |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + public function has_session() { |
|
| 158 | + return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * Set session expiration. |
|
| 163 | + */ |
|
| 164 | + public function set_session_expiration() { |
|
| 165 | + $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
| 166 | + $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Generate a unique customer ID for guests, or return user ID if logged in. |
|
| 171 | + * |
|
| 172 | + * Uses Portable PHP password hashing framework to generate a unique cryptographically strong ID. |
|
| 173 | + * |
|
| 174 | + * @return string |
|
| 175 | + */ |
|
| 176 | + public function generate_customer_id() { |
|
| 177 | + $customer_id = ''; |
|
| 178 | + |
|
| 179 | + if ( is_user_logged_in() ) { |
|
| 180 | + $customer_id = get_current_user_id(); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + if ( empty( $customer_id ) ) { |
|
| 184 | 184 | $customer_id = wp_create_nonce('wpinv-session-customer-id'); |
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $customer_id; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Get the session cookie, if set. Otherwise return false. |
|
| 192 | - * |
|
| 193 | - * Session cookies without a customer ID are invalid. |
|
| 194 | - * |
|
| 195 | - * @return bool|array |
|
| 196 | - */ |
|
| 197 | - public function get_session_cookie() { |
|
| 198 | - $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
| 199 | - |
|
| 200 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
| 201 | - return false; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
| 205 | - |
|
| 206 | - if ( empty( $customer_id ) ) { |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // Validate hash. |
|
| 211 | - $to_hash = $customer_id . '|' . $session_expiration; |
|
| 212 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 213 | - |
|
| 214 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
| 215 | - return false; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Get session data. |
|
| 223 | - * |
|
| 224 | - * @return array |
|
| 225 | - */ |
|
| 226 | - public function get_session_data() { |
|
| 227 | - return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - public function generate_key($customer_id){ |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $customer_id; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Get the session cookie, if set. Otherwise return false. |
|
| 192 | + * |
|
| 193 | + * Session cookies without a customer ID are invalid. |
|
| 194 | + * |
|
| 195 | + * @return bool|array |
|
| 196 | + */ |
|
| 197 | + public function get_session_cookie() { |
|
| 198 | + $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
| 199 | + |
|
| 200 | + if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
| 201 | + return false; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
| 205 | + |
|
| 206 | + if ( empty( $customer_id ) ) { |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // Validate hash. |
|
| 211 | + $to_hash = $customer_id . '|' . $session_expiration; |
|
| 212 | + $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 213 | + |
|
| 214 | + if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Get session data. |
|
| 223 | + * |
|
| 224 | + * @return array |
|
| 225 | + */ |
|
| 226 | + public function get_session_data() { |
|
| 227 | + return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + public function generate_key($customer_id){ |
|
| 231 | 231 | if(!$customer_id){ |
| 232 | 232 | return; |
| 233 | 233 | } |
@@ -235,62 +235,62 @@ discard block |
||
| 235 | 235 | return 'wpi_trans_'.$customer_id; |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * Save data. |
|
| 240 | - */ |
|
| 241 | - public function save_data() { |
|
| 242 | - // Dirty if something changed - prevents saving nothing new. |
|
| 243 | - if ( $this->_dirty && $this->has_session() ) { |
|
| 238 | + /** |
|
| 239 | + * Save data. |
|
| 240 | + */ |
|
| 241 | + public function save_data() { |
|
| 242 | + // Dirty if something changed - prevents saving nothing new. |
|
| 243 | + if ( $this->_dirty && $this->has_session() ) { |
|
| 244 | 244 | |
| 245 | 245 | set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
| 246 | 246 | |
| 247 | - $this->_dirty = false; |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Destroy all session data. |
|
| 253 | - */ |
|
| 254 | - public function destroy_session() { |
|
| 255 | - $this->delete_session( $this->_customer_id ); |
|
| 256 | - $this->forget_session(); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Forget all session data without destroying it. |
|
| 261 | - */ |
|
| 262 | - public function forget_session() { |
|
| 263 | - $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
| 264 | - |
|
| 265 | - wpinv_empty_cart(); |
|
| 266 | - |
|
| 267 | - $this->_data = array(); |
|
| 268 | - $this->_dirty = false; |
|
| 269 | - $this->_customer_id = $this->generate_customer_id(); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
| 274 | - * |
|
| 275 | - * @param int $uid User ID. |
|
| 276 | - * @return string |
|
| 277 | - */ |
|
| 278 | - public function nonce_user_logged_out( $uid ) { |
|
| 279 | - return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Returns the session. |
|
| 284 | - * |
|
| 285 | - * @param string $customer_id Customer ID. |
|
| 286 | - * @param mixed $default Default session value. |
|
| 287 | - * @return string|array |
|
| 288 | - */ |
|
| 289 | - public function get_session( $customer_id, $default = false ) { |
|
| 290 | - |
|
| 291 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
| 292 | - return array(); |
|
| 293 | - } |
|
| 247 | + $this->_dirty = false; |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Destroy all session data. |
|
| 253 | + */ |
|
| 254 | + public function destroy_session() { |
|
| 255 | + $this->delete_session( $this->_customer_id ); |
|
| 256 | + $this->forget_session(); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Forget all session data without destroying it. |
|
| 261 | + */ |
|
| 262 | + public function forget_session() { |
|
| 263 | + $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
| 264 | + |
|
| 265 | + wpinv_empty_cart(); |
|
| 266 | + |
|
| 267 | + $this->_data = array(); |
|
| 268 | + $this->_dirty = false; |
|
| 269 | + $this->_customer_id = $this->generate_customer_id(); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * When a user is logged out, ensure they have a unique nonce by using the customer/session ID. |
|
| 274 | + * |
|
| 275 | + * @param int $uid User ID. |
|
| 276 | + * @return string |
|
| 277 | + */ |
|
| 278 | + public function nonce_user_logged_out( $uid ) { |
|
| 279 | + return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Returns the session. |
|
| 284 | + * |
|
| 285 | + * @param string $customer_id Customer ID. |
|
| 286 | + * @param mixed $default Default session value. |
|
| 287 | + * @return string|array |
|
| 288 | + */ |
|
| 289 | + public function get_session( $customer_id, $default = false ) { |
|
| 290 | + |
|
| 291 | + if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
| 292 | + return array(); |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | 295 | if ( !is_user_logged_in() ) { |
| 296 | 296 | if(!wp_verify_nonce( $customer_id, 'wpinv-session-customer-id' )){ |
@@ -305,32 +305,32 @@ discard block |
||
| 305 | 305 | $value = $default; |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - return maybe_unserialize( $value ); |
|
| 309 | - } |
|
| 308 | + return maybe_unserialize( $value ); |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - /** |
|
| 312 | - * Delete the session from the cache and database. |
|
| 313 | - * |
|
| 314 | - * @param int $customer_id Customer ID. |
|
| 315 | - */ |
|
| 316 | - public function delete_session( $customer_id ) { |
|
| 311 | + /** |
|
| 312 | + * Delete the session from the cache and database. |
|
| 313 | + * |
|
| 314 | + * @param int $customer_id Customer ID. |
|
| 315 | + */ |
|
| 316 | + public function delete_session( $customer_id ) { |
|
| 317 | 317 | |
| 318 | 318 | $key = $this->generate_key($customer_id); |
| 319 | 319 | |
| 320 | - delete_transient($key); |
|
| 321 | - } |
|
| 320 | + delete_transient($key); |
|
| 321 | + } |
|
| 322 | 322 | |
| 323 | - /** |
|
| 324 | - * Update the session expiry timestamp. |
|
| 325 | - * |
|
| 326 | - * @param string $customer_id Customer ID. |
|
| 327 | - * @param int $timestamp Timestamp to expire the cookie. |
|
| 328 | - */ |
|
| 329 | - public function update_session_timestamp( $customer_id, $timestamp ) { |
|
| 323 | + /** |
|
| 324 | + * Update the session expiry timestamp. |
|
| 325 | + * |
|
| 326 | + * @param string $customer_id Customer ID. |
|
| 327 | + * @param int $timestamp Timestamp to expire the cookie. |
|
| 328 | + */ |
|
| 329 | + public function update_session_timestamp( $customer_id, $timestamp ) { |
|
| 330 | 330 | |
| 331 | 331 | set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp); |
| 332 | 332 | |
| 333 | - } |
|
| 333 | + } |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | global $wpi_session; |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | * |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Session handler class. |
@@ -52,11 +52,11 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function __construct() { |
| 54 | 54 | |
| 55 | - $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH ); |
|
| 56 | - add_action( 'init', array( $this, 'init' ), -1 ); |
|
| 57 | - add_action( 'wp_logout', array( $this, 'destroy_session' ) ); |
|
| 58 | - add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 ); |
|
| 59 | - add_action( 'shutdown', array( $this, 'save_data' ), 20 ); |
|
| 55 | + $this->_cookie = apply_filters('wpinv_cookie', 'wpinv_session_' . COOKIEHASH); |
|
| 56 | + add_action('init', array($this, 'init'), -1); |
|
| 57 | + add_action('wp_logout', array($this, 'destroy_session')); |
|
| 58 | + add_action('wp', array($this, 'set_customer_session_cookie'), 10); |
|
| 59 | + add_action('shutdown', array($this, 'save_data'), 20); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -67,8 +67,8 @@ discard block |
||
| 67 | 67 | public function init() { |
| 68 | 68 | $this->init_session_cookie(); |
| 69 | 69 | |
| 70 | - if ( ! is_user_logged_in() ) { |
|
| 71 | - add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) ); |
|
| 70 | + if (!is_user_logged_in()) { |
|
| 71 | + add_filter('nonce_user_logged_out', array($this, 'nonce_user_logged_out')); |
|
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | public function init_session_cookie() { |
| 81 | 81 | $cookie = $this->get_session_cookie(); |
| 82 | 82 | |
| 83 | - if ( $cookie ) { |
|
| 83 | + if ($cookie) { |
|
| 84 | 84 | $this->_customer_id = $cookie[0]; |
| 85 | 85 | $this->_session_expiration = $cookie[1]; |
| 86 | 86 | $this->_session_expiring = $cookie[2]; |
@@ -88,17 +88,17 @@ discard block |
||
| 88 | 88 | $this->_data = $this->get_session_data(); |
| 89 | 89 | |
| 90 | 90 | // If the user logs in, update session. |
| 91 | - if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) { |
|
| 91 | + if (is_user_logged_in() && get_current_user_id() != $this->_customer_id) { |
|
| 92 | 92 | $this->_customer_id = get_current_user_id(); |
| 93 | 93 | $this->_dirty = true; |
| 94 | 94 | $this->save_data(); |
| 95 | - $this->set_customer_session_cookie( true ); |
|
| 95 | + $this->set_customer_session_cookie(true); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Update session if its close to expiring. |
| 99 | - if ( time() > $this->_session_expiring ) { |
|
| 99 | + if (time() > $this->_session_expiring) { |
|
| 100 | 100 | $this->set_session_expiration(); |
| 101 | - $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration ); |
|
| 101 | + $this->update_session_timestamp($this->_customer_id, $this->_session_expiration); |
|
| 102 | 102 | } |
| 103 | 103 | } else { |
| 104 | 104 | $this->set_session_expiration(); |
@@ -116,25 +116,25 @@ discard block |
||
| 116 | 116 | * |
| 117 | 117 | * @param bool $set Should the session cookie be set. |
| 118 | 118 | */ |
| 119 | - public function set_customer_session_cookie( $set ) { |
|
| 120 | - if ( $set ) { |
|
| 119 | + public function set_customer_session_cookie($set) { |
|
| 120 | + if ($set) { |
|
| 121 | 121 | $to_hash = $this->_customer_id . '|' . $this->_session_expiration; |
| 122 | - $cookie_hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 122 | + $cookie_hash = hash_hmac('md5', $to_hash, wp_hash($to_hash)); |
|
| 123 | 123 | $cookie_value = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash; |
| 124 | 124 | $this->_has_cookie = true; |
| 125 | 125 | |
| 126 | - if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) { |
|
| 127 | - $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true ); |
|
| 126 | + if (!isset($_COOKIE[$this->_cookie]) || $_COOKIE[$this->_cookie] !== $cookie_value) { |
|
| 127 | + $this->setcookie($this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true); |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){ |
|
| 133 | - if ( ! headers_sent() ) { |
|
| 134 | - setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) ); |
|
| 135 | - } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
|
| 136 | - headers_sent( $file, $line ); |
|
| 137 | - trigger_error( "{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine |
|
| 132 | + public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false) { |
|
| 133 | + if (!headers_sent()) { |
|
| 134 | + setcookie($name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters('wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure)); |
|
| 135 | + } elseif (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 136 | + headers_sent($file, $line); |
|
| 137 | + trigger_error("{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE); // @codingStandardsIgnoreLine |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
@@ -145,8 +145,8 @@ discard block |
||
| 145 | 145 | * @return bool |
| 146 | 146 | */ |
| 147 | 147 | protected function use_secure_cookie() { |
| 148 | - $is_https = false !== strstr( get_option( 'home' ), 'https:' ); |
|
| 149 | - return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() ); |
|
| 148 | + $is_https = false !== strstr(get_option('home'), 'https:'); |
|
| 149 | + return apply_filters('wpinv_session_use_secure_cookie', $is_https && is_ssl()); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -155,15 +155,15 @@ discard block |
||
| 155 | 155 | * @return bool |
| 156 | 156 | */ |
| 157 | 157 | public function has_session() { |
| 158 | - return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
| 158 | + return isset($_COOKIE[$this->_cookie]) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine. |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * Set session expiration. |
| 163 | 163 | */ |
| 164 | 164 | public function set_session_expiration() { |
| 165 | - $this->_session_expiring = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours. |
|
| 166 | - $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours. |
|
| 165 | + $this->_session_expiring = time() + intval(apply_filters('wpinv_session_expiring', 60 * 60 * 47)); // 47 Hours. |
|
| 166 | + $this->_session_expiration = time() + intval(apply_filters('wpinv_session_expiration', 60 * 60 * 48)); // 48 Hours. |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | public function generate_customer_id() { |
| 177 | 177 | $customer_id = ''; |
| 178 | 178 | |
| 179 | - if ( is_user_logged_in() ) { |
|
| 179 | + if (is_user_logged_in()) { |
|
| 180 | 180 | $customer_id = get_current_user_id(); |
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if ( empty( $customer_id ) ) { |
|
| 183 | + if (empty($customer_id)) { |
|
| 184 | 184 | $customer_id = wp_create_nonce('wpinv-session-customer-id'); |
| 185 | 185 | } |
| 186 | 186 | |
@@ -195,27 +195,27 @@ discard block |
||
| 195 | 195 | * @return bool|array |
| 196 | 196 | */ |
| 197 | 197 | public function get_session_cookie() { |
| 198 | - $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine. |
|
| 198 | + $cookie_value = isset($_COOKIE[$this->_cookie]) ? wp_unslash($_COOKIE[$this->_cookie]) : false; // @codingStandardsIgnoreLine. |
|
| 199 | 199 | |
| 200 | - if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) { |
|
| 200 | + if (empty($cookie_value) || !is_string($cookie_value)) { |
|
| 201 | 201 | return false; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value ); |
|
| 204 | + list($customer_id, $session_expiration, $session_expiring, $cookie_hash) = explode('||', $cookie_value); |
|
| 205 | 205 | |
| 206 | - if ( empty( $customer_id ) ) { |
|
| 206 | + if (empty($customer_id)) { |
|
| 207 | 207 | return false; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // Validate hash. |
| 211 | 211 | $to_hash = $customer_id . '|' . $session_expiration; |
| 212 | - $hash = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) ); |
|
| 212 | + $hash = hash_hmac('md5', $to_hash, wp_hash($to_hash)); |
|
| 213 | 213 | |
| 214 | - if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) { |
|
| 214 | + if (empty($cookie_hash) || !hash_equals($hash, $cookie_hash)) { |
|
| 215 | 215 | return false; |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash ); |
|
| 218 | + return array($customer_id, $session_expiration, $session_expiring, $cookie_hash); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -224,15 +224,15 @@ discard block |
||
| 224 | 224 | * @return array |
| 225 | 225 | */ |
| 226 | 226 | public function get_session_data() { |
| 227 | - return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array(); |
|
| 227 | + return $this->has_session() ? (array) $this->get_session($this->_customer_id) : array(); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - public function generate_key($customer_id){ |
|
| 231 | - if(!$customer_id){ |
|
| 230 | + public function generate_key($customer_id) { |
|
| 231 | + if (!$customer_id) { |
|
| 232 | 232 | return; |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - return 'wpi_trans_'.$customer_id; |
|
| 235 | + return 'wpi_trans_' . $customer_id; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -240,9 +240,9 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | public function save_data() { |
| 242 | 242 | // Dirty if something changed - prevents saving nothing new. |
| 243 | - if ( $this->_dirty && $this->has_session() ) { |
|
| 243 | + if ($this->_dirty && $this->has_session()) { |
|
| 244 | 244 | |
| 245 | - set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
|
| 245 | + set_transient($this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration); |
|
| 246 | 246 | |
| 247 | 247 | $this->_dirty = false; |
| 248 | 248 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * Destroy all session data. |
| 253 | 253 | */ |
| 254 | 254 | public function destroy_session() { |
| 255 | - $this->delete_session( $this->_customer_id ); |
|
| 255 | + $this->delete_session($this->_customer_id); |
|
| 256 | 256 | $this->forget_session(); |
| 257 | 257 | } |
| 258 | 258 | |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | * Forget all session data without destroying it. |
| 261 | 261 | */ |
| 262 | 262 | public function forget_session() { |
| 263 | - $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true ); |
|
| 263 | + $this->setcookie($this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true); |
|
| 264 | 264 | |
| 265 | 265 | wpinv_empty_cart(); |
| 266 | 266 | |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | * @param int $uid User ID. |
| 276 | 276 | * @return string |
| 277 | 277 | */ |
| 278 | - public function nonce_user_logged_out( $uid ) { |
|
| 278 | + public function nonce_user_logged_out($uid) { |
|
| 279 | 279 | return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid; |
| 280 | 280 | } |
| 281 | 281 | |
@@ -286,14 +286,14 @@ discard block |
||
| 286 | 286 | * @param mixed $default Default session value. |
| 287 | 287 | * @return string|array |
| 288 | 288 | */ |
| 289 | - public function get_session( $customer_id, $default = false ) { |
|
| 289 | + public function get_session($customer_id, $default = false) { |
|
| 290 | 290 | |
| 291 | - if ( defined( 'WP_SETUP_CONFIG' ) ) { |
|
| 291 | + if (defined('WP_SETUP_CONFIG')) { |
|
| 292 | 292 | return array(); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - if ( !is_user_logged_in() ) { |
|
| 296 | - if(!wp_verify_nonce( $customer_id, 'wpinv-session-customer-id' )){ |
|
| 295 | + if (!is_user_logged_in()) { |
|
| 296 | + if (!wp_verify_nonce($customer_id, 'wpinv-session-customer-id')) { |
|
| 297 | 297 | return array(); |
| 298 | 298 | } |
| 299 | 299 | } |
@@ -301,11 +301,11 @@ discard block |
||
| 301 | 301 | $key = $this->generate_key($customer_id); |
| 302 | 302 | $value = get_transient($key); |
| 303 | 303 | |
| 304 | - if ( !$value ) { |
|
| 304 | + if (!$value) { |
|
| 305 | 305 | $value = $default; |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - return maybe_unserialize( $value ); |
|
| 308 | + return maybe_unserialize($value); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | * |
| 314 | 314 | * @param int $customer_id Customer ID. |
| 315 | 315 | */ |
| 316 | - public function delete_session( $customer_id ) { |
|
| 316 | + public function delete_session($customer_id) { |
|
| 317 | 317 | |
| 318 | 318 | $key = $this->generate_key($customer_id); |
| 319 | 319 | |
@@ -326,9 +326,9 @@ discard block |
||
| 326 | 326 | * @param string $customer_id Customer ID. |
| 327 | 327 | * @param int $timestamp Timestamp to expire the cookie. |
| 328 | 328 | */ |
| 329 | - public function update_session_timestamp( $customer_id, $timestamp ) { |
|
| 329 | + public function update_session_timestamp($customer_id, $timestamp) { |
|
| 330 | 330 | |
| 331 | - set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp); |
|
| 331 | + set_transient($this->generate_key($customer_id), maybe_serialize($this->_data), $timestamp); |
|
| 332 | 332 | |
| 333 | 333 | } |
| 334 | 334 | } |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | </div> |
| 127 | 127 | </div> |
| 128 | 128 | <?php |
| 129 | - }else{ |
|
| 129 | + } else{ |
|
| 130 | 130 | $installed_plugins = get_plugins(); |
| 131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
| 132 | 132 | if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
@@ -151,14 +151,14 @@ discard block |
||
| 151 | 151 | echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
| 152 | 152 | echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
| 153 | 153 | echo '</a>'; |
| 154 | - }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
| 154 | + } elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
| 155 | 155 | if(defined('WP_EASY_UPDATES_ACTIVE')){ |
| 156 | 156 | $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com&TB_iframe=true'); |
| 157 | - }else{ |
|
| 157 | + } else{ |
|
| 158 | 158 | // if installed show activation link |
| 159 | 159 | if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
| 160 | 160 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
| 161 | - }else{ |
|
| 161 | + } else{ |
|
| 162 | 162 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
| 163 | 163 | } |
| 164 | 164 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | - exit; |
|
| 7 | + exit; |
|
| 8 | 8 | } |
| 9 | 9 | add_ThickBox(); |
| 10 | 10 | ?> |
@@ -14,18 +14,18 @@ discard block |
||
| 14 | 14 | <?php if ( $tabs ){ ?> |
| 15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
| 16 | 16 | <?php |
| 17 | - foreach ( $tabs as $name => $label ) { |
|
| 18 | - echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
| 19 | - } |
|
| 20 | - do_action( 'wpi_addons_tabs' ); |
|
| 21 | - ?> |
|
| 17 | + foreach ( $tabs as $name => $label ) { |
|
| 18 | + echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
| 19 | + } |
|
| 20 | + do_action( 'wpi_addons_tabs' ); |
|
| 21 | + ?> |
|
| 22 | 22 | </nav> |
| 23 | 23 | |
| 24 | 24 | <?php |
| 25 | 25 | |
| 26 | - if($current_tab == 'membership'){ |
|
| 26 | + if($current_tab == 'membership'){ |
|
| 27 | 27 | |
| 28 | - ?> |
|
| 28 | + ?> |
|
| 29 | 29 | |
| 30 | 30 | <div class="wpi-membership-tab-conatiner"> |
| 31 | 31 | <div class="membership-content"> |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | <h2><?php _e("Have a membership key?","invoicing");?></h2> |
| 37 | 37 | <p> |
| 38 | 38 | <?php |
| 39 | - $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
| 40 | - echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108,12351)); |
|
| 41 | - ?> |
|
| 39 | + $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
| 40 | + echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108,12351)); |
|
| 41 | + ?> |
|
| 42 | 42 | </p> |
| 43 | 43 | <?php }?> |
| 44 | 44 | |
@@ -48,13 +48,13 @@ discard block |
||
| 48 | 48 | <div class="feature-list"> |
| 49 | 49 | <ul> |
| 50 | 50 | <?php |
| 51 | - $addon_obj = new WPInv_Admin_Addons(); |
|
| 52 | - if ($addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
| 53 | - foreach ( $addons as $addon ) { |
|
| 54 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - ?> |
|
| 51 | + $addon_obj = new WPInv_Admin_Addons(); |
|
| 52 | + if ($addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
| 53 | + foreach ( $addons as $addon ) { |
|
| 54 | + echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + ?> |
|
| 58 | 58 | </ul> |
| 59 | 59 | |
| 60 | 60 | <div class="feature-cta"> |
@@ -65,12 +65,12 @@ discard block |
||
| 65 | 65 | <h3><?php _e("Included Gateways:","invoicing");?></h3> |
| 66 | 66 | <ul> |
| 67 | 67 | <?php |
| 68 | - if ($addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
| 69 | - foreach ( $addons as $addon ) { |
|
| 70 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - ?> |
|
| 68 | + if ($addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
| 69 | + foreach ( $addons as $addon ) { |
|
| 70 | + echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + ?> |
|
| 74 | 74 | </ul> |
| 75 | 75 | </div> |
| 76 | 76 | |
@@ -81,8 +81,8 @@ discard block |
||
| 81 | 81 | <div class="testimonial-content"> |
| 82 | 82 | <div class="t-image"> |
| 83 | 83 | <?php |
| 84 | - echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
| 85 | - ?> |
|
| 84 | + echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
| 85 | + ?> |
|
| 86 | 86 | </div> |
| 87 | 87 | <div class="t-content"> |
| 88 | 88 | <p> |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | <div class="testimonial-content"> |
| 102 | 102 | <div class="t-image"> |
| 103 | 103 | <?php |
| 104 | - echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
| 105 | - ?> |
|
| 104 | + echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
| 105 | + ?> |
|
| 106 | 106 | </div> |
| 107 | 107 | <div class="t-content"> |
| 108 | 108 | <p> |
@@ -126,20 +126,20 @@ discard block |
||
| 126 | 126 | </div> |
| 127 | 127 | </div> |
| 128 | 128 | <?php |
| 129 | - }else{ |
|
| 130 | - $installed_plugins = get_plugins(); |
|
| 129 | + }else{ |
|
| 130 | + $installed_plugins = get_plugins(); |
|
| 131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
| 132 | - if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
| 133 | - ?> |
|
| 132 | + if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
| 133 | + ?> |
|
| 134 | 134 | <ul class="wpi-products"><?php foreach ( $addons as $addon ) : |
| 135 | 135 | if(965==$addon->info->id){continue;}// don't show quote add on |
| 136 | - ?><li class="wpi-product"> |
|
| 136 | + ?><li class="wpi-product"> |
|
| 137 | 137 | <div class="wpi-product-title"> |
| 138 | 138 | <h3><?php |
| 139 | - if ( ! empty( $addon->info->excerpt) ){ |
|
| 140 | - echo wpi_help_tip( $addon->info->excerpt ); |
|
| 141 | - } |
|
| 142 | - echo esc_html( $addon->info->title ); ?></h3> |
|
| 139 | + if ( ! empty( $addon->info->excerpt) ){ |
|
| 140 | + echo wpi_help_tip( $addon->info->excerpt ); |
|
| 141 | + } |
|
| 142 | + echo esc_html( $addon->info->title ); ?></h3> |
|
| 143 | 143 | </div> |
| 144 | 144 | |
| 145 | 145 | <span class="wpi-product-image"> |
@@ -147,27 +147,27 @@ discard block |
||
| 147 | 147 | <img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/> |
| 148 | 148 | <?php endif; |
| 149 | 149 | |
| 150 | - if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
| 151 | - echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
| 152 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
| 153 | - echo '</a>'; |
|
| 154 | - }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
| 155 | - if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
| 156 | - $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com&TB_iframe=true'); |
|
| 157 | - }else{ |
|
| 158 | - // if installed show activation link |
|
| 159 | - if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
| 160 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
| 161 | - }else{ |
|
| 162 | - $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - echo '<a href="'.$url.'" class="thickbox">'; |
|
| 166 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
| 167 | - echo '</a>'; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - ?> |
|
| 150 | + if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
| 151 | + echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
| 152 | + echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
| 153 | + echo '</a>'; |
|
| 154 | + }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
| 155 | + if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
| 156 | + $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com&TB_iframe=true'); |
|
| 157 | + }else{ |
|
| 158 | + // if installed show activation link |
|
| 159 | + if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
| 160 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
|
| 161 | + }else{ |
|
| 162 | + $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + echo '<a href="'.$url.'" class="thickbox">'; |
|
| 166 | + echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
| 167 | + echo '</a>'; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + ?> |
|
| 171 | 171 | |
| 172 | 172 | </span> |
| 173 | 173 | |
@@ -175,15 +175,15 @@ discard block |
||
| 175 | 175 | <span class="wpi-product-button"> |
| 176 | 176 | <?php |
| 177 | 177 | $addon_obj->output_button( $addon ); |
| 178 | - ?> |
|
| 178 | + ?> |
|
| 179 | 179 | </span> |
| 180 | 180 | |
| 181 | 181 | <span class="wpi-price"><?php //print_r($addon); //echo wp_kses_post( $addon->price ); ?></span></li><?php endforeach; ?></ul> |
| 182 | 182 | <?php endif; |
| 183 | - } |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - } |
|
| 186 | - ?> |
|
| 185 | + } |
|
| 186 | + ?> |
|
| 187 | 187 | |
| 188 | 188 | |
| 189 | 189 | <div class="clearfix" ></div> |
@@ -202,8 +202,8 @@ discard block |
||
| 202 | 202 | <input class="wpeu-licence-key" type="text" placeholder="<?php _e("Enter your licence key",'invoicing');?>"> <button class="button-primary wpeu-licence-popup-button" ><?php _e("Install",'invoicing');?></button> |
| 203 | 203 | <br> |
| 204 | 204 | <?php |
| 205 | - echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
| 206 | - ?> |
|
| 205 | + echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
| 206 | + ?> |
|
| 207 | 207 | </span> |
| 208 | 208 | </div> |
| 209 | 209 | |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Admin View: Page - Addons |
| 4 | 4 | * |
| 5 | 5 | */ |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 6 | +if (!defined('ABSPATH')) { |
|
| 7 | 7 | exit; |
| 8 | 8 | } |
| 9 | 9 | add_ThickBox(); |
@@ -11,19 +11,19 @@ discard block |
||
| 11 | 11 | <div class="wrap wpi_addons_wrap"> |
| 12 | 12 | <h1><?php echo get_admin_page_title(); ?></h1> |
| 13 | 13 | |
| 14 | - <?php if ( $tabs ){ ?> |
|
| 14 | + <?php if ($tabs) { ?> |
|
| 15 | 15 | <nav class="nav-tab-wrapper wpi-nav-tab-wrapper"> |
| 16 | 16 | <?php |
| 17 | - foreach ( $tabs as $name => $label ) { |
|
| 18 | - echo '<a href="' . admin_url( 'admin.php?page=wpi-addons&tab=' . $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . $label . '</a>'; |
|
| 17 | + foreach ($tabs as $name => $label) { |
|
| 18 | + echo '<a href="' . admin_url('admin.php?page=wpi-addons&tab=' . $name) . '" class="nav-tab ' . ($current_tab == $name ? 'nav-tab-active' : '') . '">' . $label . '</a>'; |
|
| 19 | 19 | } |
| 20 | - do_action( 'wpi_addons_tabs' ); |
|
| 20 | + do_action('wpi_addons_tabs'); |
|
| 21 | 21 | ?> |
| 22 | 22 | </nav> |
| 23 | 23 | |
| 24 | 24 | <?php |
| 25 | 25 | |
| 26 | - if($current_tab == 'membership'){ |
|
| 26 | + if ($current_tab == 'membership') { |
|
| 27 | 27 | |
| 28 | 28 | ?> |
| 29 | 29 | |
@@ -32,42 +32,42 @@ discard block |
||
| 32 | 32 | <!-- |
| 33 | 33 | <h2>With our WPInvoicing Membership you get access to all our products!</h2> |
| 34 | 34 | <p><a class="button button-primary" href="https://wpinvoicing.com/downloads/membership/">View Memberships</a></p>--> |
| 35 | - <?php if(defined('WP_EASY_UPDATES_ACTIVE')){?> |
|
| 36 | - <h2><?php _e("Have a membership key?","invoicing");?></h2> |
|
| 35 | + <?php if (defined('WP_EASY_UPDATES_ACTIVE')) {?> |
|
| 36 | + <h2><?php _e("Have a membership key?", "invoicing"); ?></h2> |
|
| 37 | 37 | <p> |
| 38 | 38 | <?php |
| 39 | - $wpeu_admin = new External_Updates_Admin('wpinvoicing.com','1'); |
|
| 40 | - echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership',array(95, 106, 108,12351)); |
|
| 39 | + $wpeu_admin = new External_Updates_Admin('wpinvoicing.com', '1'); |
|
| 40 | + echo $wpeu_admin->render_licence_actions('wpinvoicing.com', 'membership', array(95, 106, 108, 12351)); |
|
| 41 | 41 | ?> |
| 42 | 42 | </p> |
| 43 | 43 | <?php }?> |
| 44 | 44 | |
| 45 | 45 | <div class="membership-cta-contet"> |
| 46 | 46 | <div class="main-cta"> |
| 47 | - <h2><?php _e("Membership benefits Include:","invoicing");?></h2> |
|
| 47 | + <h2><?php _e("Membership benefits Include:", "invoicing"); ?></h2> |
|
| 48 | 48 | <div class="feature-list"> |
| 49 | 49 | <ul> |
| 50 | 50 | <?php |
| 51 | 51 | $addon_obj = new WPInv_Admin_Addons(); |
| 52 | - if ($addons = $addon_obj->get_section_data( 'addons' ) ) { |
|
| 53 | - foreach ( $addons as $addon ) { |
|
| 54 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
| 52 | + if ($addons = $addon_obj->get_section_data('addons')) { |
|
| 53 | + foreach ($addons as $addon) { |
|
| 54 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html($addon->info->title) . '</li>'; |
|
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | ?> |
| 58 | 58 | </ul> |
| 59 | 59 | |
| 60 | 60 | <div class="feature-cta"> |
| 61 | - <h3><?php _e("Membership Starts from","invoicing");?></h3> |
|
| 61 | + <h3><?php _e("Membership Starts from", "invoicing"); ?></h3> |
|
| 62 | 62 | <h4>$99</h4> |
| 63 | - <a href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php _e("Buy Membership","invoicing");?></a> |
|
| 63 | + <a href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php _e("Buy Membership", "invoicing"); ?></a> |
|
| 64 | 64 | </div> |
| 65 | - <h3><?php _e("Included Gateways:","invoicing");?></h3> |
|
| 65 | + <h3><?php _e("Included Gateways:", "invoicing"); ?></h3> |
|
| 66 | 66 | <ul> |
| 67 | 67 | <?php |
| 68 | - if ($addons = $addon_obj->get_section_data( 'gateways' ) ) { |
|
| 69 | - foreach ( $addons as $addon ) { |
|
| 70 | - echo '<li><i class="far fa-check-circle fa-sm"></i> '.esc_html( $addon->info->title ).'</li>'; |
|
| 68 | + if ($addons = $addon_obj->get_section_data('gateways')) { |
|
| 69 | + foreach ($addons as $addon) { |
|
| 70 | + echo '<li><i class="far fa-check-circle fa-sm"></i> ' . esc_html($addon->info->title) . '</li>'; |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | ?> |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | <div class="testimonial-content"> |
| 82 | 82 | <div class="t-image"> |
| 83 | 83 | <?php |
| 84 | - echo '<img src="' . plugins_url( 'images/t-image2.png', dirname(__FILE__) ) . '" > '; |
|
| 84 | + echo '<img src="' . plugins_url('images/t-image2.png', dirname(__FILE__)) . '" > '; |
|
| 85 | 85 | ?> |
| 86 | 86 | </div> |
| 87 | 87 | <div class="t-content"> |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | <div class="testimonial-content"> |
| 102 | 102 | <div class="t-image"> |
| 103 | 103 | <?php |
| 104 | - echo '<img src="' . plugins_url( 'images/t-image1.png', dirname(__FILE__) ) . '" > '; |
|
| 104 | + echo '<img src="' . plugins_url('images/t-image1.png', dirname(__FILE__)) . '" > '; |
|
| 105 | 105 | ?> |
| 106 | 106 | </div> |
| 107 | 107 | <div class="t-content"> |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | </div> |
| 118 | 118 | </div> |
| 119 | 119 | <div class="member-footer"> |
| 120 | - <a class="footer-btn" href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php _e("Buy Membership","invoicing");?></a> |
|
| 121 | - <a class="footer-link" href="post-new.php?post_type=wpi_invoice"><?php _e("Create Invoice","invoicing");?></a> |
|
| 120 | + <a class="footer-btn" href="https://wpinvoicing.com/downloads/membership/" target="_blank"><?php _e("Buy Membership", "invoicing"); ?></a> |
|
| 121 | + <a class="footer-link" href="post-new.php?post_type=wpi_invoice"><?php _e("Create Invoice", "invoicing"); ?></a> |
|
| 122 | 122 | </div> |
| 123 | 123 | </div> |
| 124 | 124 | |
@@ -126,44 +126,44 @@ discard block |
||
| 126 | 126 | </div> |
| 127 | 127 | </div> |
| 128 | 128 | <?php |
| 129 | - }else{ |
|
| 129 | + } else { |
|
| 130 | 130 | $installed_plugins = get_plugins(); |
| 131 | 131 | $addon_obj = new WPInv_Admin_Addons(); |
| 132 | - if ($addons = $addon_obj->get_section_data( $current_tab ) ) : |
|
| 132 | + if ($addons = $addon_obj->get_section_data($current_tab)) : |
|
| 133 | 133 | ?> |
| 134 | - <ul class="wpi-products"><?php foreach ( $addons as $addon ) : |
|
| 135 | - if(965==$addon->info->id){continue;}// don't show quote add on |
|
| 134 | + <ul class="wpi-products"><?php foreach ($addons as $addon) : |
|
| 135 | + if (965 == $addon->info->id) {continue; }// don't show quote add on |
|
| 136 | 136 | ?><li class="wpi-product"> |
| 137 | 137 | <div class="wpi-product-title"> |
| 138 | 138 | <h3><?php |
| 139 | - if ( ! empty( $addon->info->excerpt) ){ |
|
| 140 | - echo wpi_help_tip( $addon->info->excerpt ); |
|
| 139 | + if (!empty($addon->info->excerpt)) { |
|
| 140 | + echo wpi_help_tip($addon->info->excerpt); |
|
| 141 | 141 | } |
| 142 | - echo esc_html( $addon->info->title ); ?></h3> |
|
| 142 | + echo esc_html($addon->info->title); ?></h3> |
|
| 143 | 143 | </div> |
| 144 | 144 | |
| 145 | 145 | <span class="wpi-product-image"> |
| 146 | - <?php if ( ! empty( $addon->info->thumbnail) ) : ?> |
|
| 147 | - <img src="<?php echo esc_attr( $addon->info->thumbnail ); ?>"/> |
|
| 146 | + <?php if (!empty($addon->info->thumbnail)) : ?> |
|
| 147 | + <img src="<?php echo esc_attr($addon->info->thumbnail); ?>"/> |
|
| 148 | 148 | <?php endif; |
| 149 | 149 | |
| 150 | - if(isset($addon->info->link) && substr( $addon->info->link, 0, 21 ) === "https://wordpress.org"){ |
|
| 151 | - echo '<a href="'.admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug).'&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
| 152 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
| 150 | + if (isset($addon->info->link) && substr($addon->info->link, 0, 21) === "https://wordpress.org") { |
|
| 151 | + echo '<a href="' . admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug) . '&width=770&height=660&TB_iframe=true" class="thickbox" >'; |
|
| 152 | + echo '<span class="wpi-product-info">' . __('More info', 'invoicing') . '</span>'; |
|
| 153 | 153 | echo '</a>'; |
| 154 | - }elseif(isset($addon->info->link) && substr( $addon->info->link, 0, 23 ) === "https://wpinvoicing.com"){ |
|
| 155 | - if(defined('WP_EASY_UPDATES_ACTIVE')){ |
|
| 156 | - $url = admin_url('/plugin-install.php?tab=plugin-information&plugin='.$addon->info->slug.'&width=770&height=660&item_id='.$addon->info->id.'&update_url=https://wpinvoicing.com&TB_iframe=true'); |
|
| 157 | - }else{ |
|
| 154 | + }elseif (isset($addon->info->link) && substr($addon->info->link, 0, 23) === "https://wpinvoicing.com") { |
|
| 155 | + if (defined('WP_EASY_UPDATES_ACTIVE')) { |
|
| 156 | + $url = admin_url('/plugin-install.php?tab=plugin-information&plugin=' . $addon->info->slug . '&width=770&height=660&item_id=' . $addon->info->id . '&update_url=https://wpinvoicing.com&TB_iframe=true'); |
|
| 157 | + } else { |
|
| 158 | 158 | // if installed show activation link |
| 159 | - if(isset($installed_plugins['wp-easy-updates/external-updates.php'])){ |
|
| 159 | + if (isset($installed_plugins['wp-easy-updates/external-updates.php'])) { |
|
| 160 | 160 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-activation'; |
| 161 | - }else{ |
|
| 161 | + } else { |
|
| 162 | 162 | $url = '#TB_inline?width=600&height=50&inlineId=wpi-wpeu-required-for-external'; |
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | - echo '<a href="'.$url.'" class="thickbox">'; |
|
| 166 | - echo '<span class="wpi-product-info">'.__('More info','invoicing').'</span>'; |
|
| 165 | + echo '<a href="' . $url . '" class="thickbox">'; |
|
| 166 | + echo '<span class="wpi-product-info">' . __('More info', 'invoicing') . '</span>'; |
|
| 167 | 167 | echo '</a>'; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | <span class="wpi-product-button"> |
| 176 | 176 | <?php |
| 177 | - $addon_obj->output_button( $addon ); |
|
| 177 | + $addon_obj->output_button($addon); |
|
| 178 | 178 | ?> |
| 179 | 179 | </span> |
| 180 | 180 | |
@@ -188,21 +188,21 @@ discard block |
||
| 188 | 188 | |
| 189 | 189 | <div class="clearfix" ></div> |
| 190 | 190 | |
| 191 | - <?php if($current_tab =='addons'){ ?> |
|
| 192 | - <p><?php printf( __( 'All of our Invoicing Addons can be found on WPInvoicing.com here: <a href="%s">Invoicing Addons</a>', 'invoicing' ), 'https://wpinvoicing.com/downloads/category/addons/' ); ?></p> |
|
| 193 | - <?php } if($current_tab =='gateways'){ ?> |
|
| 194 | - <p><?php printf( __( 'All of our Invoicing Payment Gateways can be found on WPInvoicing.com here: <a href="%s">Invoicing Payment Gateways</a>', 'invoicing' ), 'https://wpinvoicing.com/downloads/category/gateways/' ); ?></p> |
|
| 191 | + <?php if ($current_tab == 'addons') { ?> |
|
| 192 | + <p><?php printf(__('All of our Invoicing Addons can be found on WPInvoicing.com here: <a href="%s">Invoicing Addons</a>', 'invoicing'), 'https://wpinvoicing.com/downloads/category/addons/'); ?></p> |
|
| 193 | + <?php } if ($current_tab == 'gateways') { ?> |
|
| 194 | + <p><?php printf(__('All of our Invoicing Payment Gateways can be found on WPInvoicing.com here: <a href="%s">Invoicing Payment Gateways</a>', 'invoicing'), 'https://wpinvoicing.com/downloads/category/gateways/'); ?></p> |
|
| 195 | 195 | <?php } ?> |
| 196 | 196 | |
| 197 | - <div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php printf( __("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.",'invoicing'),wp_nonce_url(admin_url('plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php'), 'activate-plugin_wp-easy-updates/external-updates.php'));?></span></div> |
|
| 198 | - <div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php printf( __("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.",'invoicing'),admin_url("plugin-install.php?tab=upload&wpeu-install=true"));?></span></div> |
|
| 197 | + <div id="wpi-wpeu-required-activation" style="display:none;"><span class="wpi-notification "><?php printf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s'>activate</a> it now.", 'invoicing'), wp_nonce_url(admin_url('plugins.php?action=activate&plugin=wp-easy-updates/external-updates.php'), 'activate-plugin_wp-easy-updates/external-updates.php')); ?></span></div> |
|
| 198 | + <div id="wpi-wpeu-required-for-external" style="display:none;"><span class="wpi-notification "><?php printf(__("The plugin <a href='https://wpeasyupdates.com/' target='_blank'>WP Easy Updates</a> is required to check for and update some installed plugins/themes, please <a href='%s' onclick='window.open(\"https://wpeasyupdates.com/wp-easy-updates.zip\", \"_blank\");' >download</a> and install it now.", 'invoicing'), admin_url("plugin-install.php?tab=upload&wpeu-install=true")); ?></span></div> |
|
| 199 | 199 | <div id="wpeu-licence-popup" style="display:none;"> |
| 200 | 200 | <span class="wpi-notification noti-white"> |
| 201 | - <h3 class="wpeu-licence-title"><?php _e("Licence key",'invoicing');?></h3> |
|
| 202 | - <input class="wpeu-licence-key" type="text" placeholder="<?php _e("Enter your licence key",'invoicing');?>"> <button class="button-primary wpeu-licence-popup-button" ><?php _e("Install",'invoicing');?></button> |
|
| 201 | + <h3 class="wpeu-licence-title"><?php _e("Licence key", 'invoicing'); ?></h3> |
|
| 202 | + <input class="wpeu-licence-key" type="text" placeholder="<?php _e("Enter your licence key", 'invoicing'); ?>"> <button class="button-primary wpeu-licence-popup-button" ><?php _e("Install", 'invoicing'); ?></button> |
|
| 203 | 203 | <br> |
| 204 | 204 | <?php |
| 205 | - echo sprintf( __('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">','</a>','<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">','</a>' ); |
|
| 205 | + echo sprintf(__('%sFind your licence key here%s OR %sBuy one here%s', 'invoicing'), '<a href="https://wpinvoicing.com/your-account/" target="_blank">', '</a>', '<a class="wpeu-licence-link" href="https://wpinvoicing.com/downloads/category/addons/" target="_blank">', '</a>'); |
|
| 206 | 206 | ?> |
| 207 | 207 | </span> |
| 208 | 208 | </div> |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | 11 | exit; |
| 12 | 12 | } |
| 13 | 13 | |
@@ -24,40 +24,40 @@ discard block |
||
| 24 | 24 | * @param Array $assoc_args Key value arguments stored in associated array format. |
| 25 | 25 | * @since 1.0.13 |
| 26 | 26 | */ |
| 27 | - public function insert_invoice( $args, $assoc_args ) { |
|
| 27 | + public function insert_invoice($args, $assoc_args) { |
|
| 28 | 28 | |
| 29 | 29 | // Fetch invoice data from the args |
| 30 | - $invoice_data = wp_unslash( $assoc_args ); |
|
| 30 | + $invoice_data = wp_unslash($assoc_args); |
|
| 31 | 31 | |
| 32 | 32 | // Abort if no invoice data is provided |
| 33 | - if( empty( $invoice_data ) ) { |
|
| 34 | - return WP_CLI::error( __( 'Invoice data not provided', 'invoicing' ) ); |
|
| 33 | + if (empty($invoice_data)) { |
|
| 34 | + return WP_CLI::error(__('Invoice data not provided', 'invoicing')); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | //Cart details |
| 38 | - if( !empty( $invoice_data['cart_details'] ) ) { |
|
| 39 | - $invoice_data['cart_details'] = json_decode( $invoice_data['cart_details'], true ); |
|
| 38 | + if (!empty($invoice_data['cart_details'])) { |
|
| 39 | + $invoice_data['cart_details'] = json_decode($invoice_data['cart_details'], true); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | //User details |
| 43 | - if( !empty( $invoice_data['user_info'] ) ) { |
|
| 44 | - $invoice_data['user_info'] = json_decode( $invoice_data['user_info'], true ); |
|
| 43 | + if (!empty($invoice_data['user_info'])) { |
|
| 44 | + $invoice_data['user_info'] = json_decode($invoice_data['user_info'], true); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | //Payment info |
| 48 | - if( !empty( $invoice_data['payment_details'] ) ) { |
|
| 49 | - $invoice_data['payment_details'] = json_decode( $invoice_data['payment_details'], true ); |
|
| 48 | + if (!empty($invoice_data['payment_details'])) { |
|
| 49 | + $invoice_data['payment_details'] = json_decode($invoice_data['payment_details'], true); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // Try creating the invoice |
| 53 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
| 53 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
| 54 | 54 | |
| 55 | - if ( is_wp_error( $invoice ) ) { |
|
| 56 | - return WP_CLI::error( $invoice->get_error_message() ); |
|
| 55 | + if (is_wp_error($invoice)) { |
|
| 56 | + return WP_CLI::error($invoice->get_error_message()); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - $message = sprintf( __( 'Invoice %s created', 'invoicing' ), $invoice->ID ); |
|
| 60 | - WP_CLI::success( $message ); |
|
| 59 | + $message = sprintf(__('Invoice %s created', 'invoicing'), $invoice->ID); |
|
| 60 | + WP_CLI::success($message); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
@@ -46,25 +46,25 @@ |
||
| 46 | 46 | parent::__construct( $options ); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * The Super block output function. |
|
| 51 | - * |
|
| 52 | - * @param array $args |
|
| 53 | - * @param array $widget_args |
|
| 54 | - * @param string $content |
|
| 55 | - * |
|
| 56 | - * @return mixed|string|bool |
|
| 57 | - */ |
|
| 49 | + /** |
|
| 50 | + * The Super block output function. |
|
| 51 | + * |
|
| 52 | + * @param array $args |
|
| 53 | + * @param array $widget_args |
|
| 54 | + * @param string $content |
|
| 55 | + * |
|
| 56 | + * @return mixed|string|bool |
|
| 57 | + */ |
|
| 58 | 58 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 59 | 59 | |
| 60 | - ob_start(); |
|
| 60 | + ob_start(); |
|
| 61 | 61 | |
| 62 | - do_action( 'wpinv_before_user_invoice_history' ); |
|
| 63 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
| 64 | - do_action( 'wpinv_after_user_invoice_history' ); |
|
| 62 | + do_action( 'wpinv_before_user_invoice_history' ); |
|
| 63 | + wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
| 64 | + do_action( 'wpinv_after_user_invoice_history' ); |
|
| 65 | 65 | |
| 66 | - $output = ob_get_clean(); |
|
| 67 | - return trim($output); |
|
| 66 | + $output = ob_get_clean(); |
|
| 67 | + return trim($output); |
|
| 68 | 68 | |
| 69 | 69 | } |
| 70 | 70 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -22,15 +22,15 @@ discard block |
||
| 22 | 22 | 'block-keywords'=> "['invoicing','history']", |
| 23 | 23 | 'class_name' => __CLASS__, |
| 24 | 24 | 'base_id' => 'wpinv_history', |
| 25 | - 'name' => __('Invoicing > Invoice History','invoicing'), |
|
| 25 | + 'name' => __('Invoicing > Invoice History', 'invoicing'), |
|
| 26 | 26 | 'widget_ops' => array( |
| 27 | 27 | 'classname' => 'wpinv-history-class wpi-g', |
| 28 | - 'description' => esc_html__('Displays invoice history.','invoicing'), |
|
| 28 | + 'description' => esc_html__('Displays invoice history.', 'invoicing'), |
|
| 29 | 29 | ), |
| 30 | 30 | 'arguments' => array( |
| 31 | 31 | 'title' => array( |
| 32 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
| 33 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 32 | + 'title' => __('Widget title', 'invoicing'), |
|
| 33 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
| 34 | 34 | 'type' => 'text', |
| 35 | 35 | 'desc_tip' => true, |
| 36 | 36 | 'default' => '', |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - parent::__construct( $options ); |
|
| 44 | + parent::__construct($options); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return mixed|string|bool |
| 55 | 55 | */ |
| 56 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 56 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
| 57 | 57 | |
| 58 | 58 | ob_start(); |
| 59 | 59 | |
| 60 | - do_action( 'wpinv_before_user_invoice_history' ); |
|
| 61 | - wpinv_get_template_part( 'wpinv-invoice-history' ); |
|
| 62 | - do_action( 'wpinv_after_user_invoice_history' ); |
|
| 60 | + do_action('wpinv_before_user_invoice_history'); |
|
| 61 | + wpinv_get_template_part('wpinv-invoice-history'); |
|
| 62 | + do_action('wpinv_after_user_invoice_history'); |
|
| 63 | 63 | |
| 64 | 64 | $output = ob_get_clean(); |
| 65 | 65 | return trim($output); |
@@ -44,22 +44,22 @@ |
||
| 44 | 44 | parent::__construct( $options ); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * The Super block output function. |
|
| 49 | - * |
|
| 50 | - * @param array $args |
|
| 51 | - * @param array $widget_args |
|
| 52 | - * @param string $content |
|
| 53 | - * |
|
| 54 | - * @return mixed|string|bool |
|
| 55 | - */ |
|
| 47 | + /** |
|
| 48 | + * The Super block output function. |
|
| 49 | + * |
|
| 50 | + * @param array $args |
|
| 51 | + * @param array $widget_args |
|
| 52 | + * @param string $content |
|
| 53 | + * |
|
| 54 | + * @return mixed|string|bool |
|
| 55 | + */ |
|
| 56 | 56 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 57 | 57 | |
| 58 | - ob_start(); |
|
| 58 | + ob_start(); |
|
| 59 | 59 | |
| 60 | - wpinv_print_errors(); |
|
| 60 | + wpinv_print_errors(); |
|
| 61 | 61 | |
| 62 | - return '<div class="wpinv">' . ob_get_clean() . '</div>'; |
|
| 62 | + return '<div class="wpinv">' . ob_get_clean() . '</div>'; |
|
| 63 | 63 | |
| 64 | 64 | } |
| 65 | 65 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -22,15 +22,15 @@ discard block |
||
| 22 | 22 | 'block-keywords'=> "['invoicing','history']", |
| 23 | 23 | 'class_name' => __CLASS__, |
| 24 | 24 | 'base_id' => 'wpinv_messages', |
| 25 | - 'name' => __('Invoicing > Invoice Messages','invoicing'), |
|
| 25 | + 'name' => __('Invoicing > Invoice Messages', 'invoicing'), |
|
| 26 | 26 | 'widget_ops' => array( |
| 27 | 27 | 'classname' => 'wpinv-messages-class wpi-g', |
| 28 | - 'description' => esc_html__('Displays invoice error and warning messages on checkout page.','invoicing'), |
|
| 28 | + 'description' => esc_html__('Displays invoice error and warning messages on checkout page.', 'invoicing'), |
|
| 29 | 29 | ), |
| 30 | 30 | 'arguments' => array( |
| 31 | 31 | 'title' => array( |
| 32 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
| 33 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 32 | + 'title' => __('Widget title', 'invoicing'), |
|
| 33 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
| 34 | 34 | 'type' => 'text', |
| 35 | 35 | 'desc_tip' => true, |
| 36 | 36 | 'default' => '', |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - parent::__construct( $options ); |
|
| 44 | + parent::__construct($options); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return mixed|string|bool |
| 55 | 55 | */ |
| 56 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 56 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
| 57 | 57 | |
| 58 | 58 | ob_start(); |
| 59 | 59 | |
@@ -46,18 +46,18 @@ |
||
| 46 | 46 | parent::__construct( $options ); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * The Super block output function. |
|
| 51 | - * |
|
| 52 | - * @param array $args |
|
| 53 | - * @param array $widget_args |
|
| 54 | - * @param string $content |
|
| 55 | - * |
|
| 56 | - * @return mixed|string|bool |
|
| 57 | - */ |
|
| 49 | + /** |
|
| 50 | + * The Super block output function. |
|
| 51 | + * |
|
| 52 | + * @param array $args |
|
| 53 | + * @param array $widget_args |
|
| 54 | + * @param string $content |
|
| 55 | + * |
|
| 56 | + * @return mixed|string|bool |
|
| 57 | + */ |
|
| 58 | 58 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 59 | 59 | |
| 60 | - return wpinv_checkout_form(); |
|
| 60 | + return wpinv_checkout_form(); |
|
| 61 | 61 | |
| 62 | 62 | } |
| 63 | 63 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -23,15 +23,15 @@ discard block |
||
| 23 | 23 | 'block-keywords'=> "['invoicing','checkout']", |
| 24 | 24 | 'class_name' => __CLASS__, |
| 25 | 25 | 'base_id' => 'wpinv_checkout', |
| 26 | - 'name' => __('Invoicing > Checkout','invoicing'), |
|
| 26 | + 'name' => __('Invoicing > Checkout', 'invoicing'), |
|
| 27 | 27 | 'widget_ops' => array( |
| 28 | 28 | 'classname' => 'wpinv-checkout-class wpi-g', |
| 29 | - 'description' => esc_html__('Displays checkout form.','invoicing'), |
|
| 29 | + 'description' => esc_html__('Displays checkout form.', 'invoicing'), |
|
| 30 | 30 | ), |
| 31 | 31 | 'arguments' => array( |
| 32 | 32 | 'title' => array( |
| 33 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
| 34 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 33 | + 'title' => __('Widget title', 'invoicing'), |
|
| 34 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
| 35 | 35 | 'type' => 'text', |
| 36 | 36 | 'desc_tip' => true, |
| 37 | 37 | 'default' => '', |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | ); |
| 43 | 43 | |
| 44 | 44 | |
| 45 | - parent::__construct( $options ); |
|
| 45 | + parent::__construct($options); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | * |
| 55 | 55 | * @return mixed|string|bool |
| 56 | 56 | */ |
| 57 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 57 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
| 58 | 58 | |
| 59 | 59 | return wpinv_checkout_form(); |
| 60 | 60 | |
@@ -46,25 +46,25 @@ |
||
| 46 | 46 | parent::__construct( $options ); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * The Super block output function. |
|
| 51 | - * |
|
| 52 | - * @param array $args |
|
| 53 | - * @param array $widget_args |
|
| 54 | - * @param string $content |
|
| 55 | - * |
|
| 56 | - * @return mixed|string|bool |
|
| 57 | - */ |
|
| 49 | + /** |
|
| 50 | + * The Super block output function. |
|
| 51 | + * |
|
| 52 | + * @param array $args |
|
| 53 | + * @param array $widget_args |
|
| 54 | + * @param string $content |
|
| 55 | + * |
|
| 56 | + * @return mixed|string|bool |
|
| 57 | + */ |
|
| 58 | 58 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 59 | 59 | |
| 60 | - ob_start(); |
|
| 60 | + ob_start(); |
|
| 61 | 61 | |
| 62 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
| 63 | - wpinv_get_template_part( 'wpinv-subscriptions-history' ); |
|
| 64 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
| 62 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
| 63 | + wpinv_get_template_part( 'wpinv-subscriptions-history' ); |
|
| 64 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
| 65 | 65 | |
| 66 | - $output = ob_get_clean(); |
|
| 67 | - return trim($output); |
|
| 66 | + $output = ob_get_clean(); |
|
| 67 | + return trim($output); |
|
| 68 | 68 | |
| 69 | 69 | } |
| 70 | 70 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -22,15 +22,15 @@ discard block |
||
| 22 | 22 | 'block-keywords'=> "['invoicing','subscriptions']", |
| 23 | 23 | 'class_name' => __CLASS__, |
| 24 | 24 | 'base_id' => 'wpinv_subscriptions', |
| 25 | - 'name' => __('Invoicing > Subscriptions History','invoicing'), |
|
| 25 | + 'name' => __('Invoicing > Subscriptions History', 'invoicing'), |
|
| 26 | 26 | 'widget_ops' => array( |
| 27 | 27 | 'classname' => 'wpinv-checkout-class wpi-g', |
| 28 | - 'description' => esc_html__('Displays subscriptions history.','invoicing'), |
|
| 28 | + 'description' => esc_html__('Displays subscriptions history.', 'invoicing'), |
|
| 29 | 29 | ), |
| 30 | 30 | 'arguments' => array( |
| 31 | 31 | 'title' => array( |
| 32 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
| 33 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 32 | + 'title' => __('Widget title', 'invoicing'), |
|
| 33 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
| 34 | 34 | 'type' => 'text', |
| 35 | 35 | 'desc_tip' => true, |
| 36 | 36 | 'default' => '', |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - parent::__construct( $options ); |
|
| 44 | + parent::__construct($options); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return mixed|string|bool |
| 55 | 55 | */ |
| 56 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 56 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
| 57 | 57 | |
| 58 | 58 | ob_start(); |
| 59 | 59 | |
| 60 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
| 61 | - wpinv_get_template_part( 'wpinv-subscriptions-history' ); |
|
| 62 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
| 60 | + do_action('wpinv_before_user_subscriptions'); |
|
| 61 | + wpinv_get_template_part('wpinv-subscriptions-history'); |
|
| 62 | + do_action('wpinv_after_user_subscriptions'); |
|
| 63 | 63 | |
| 64 | 64 | $output = ob_get_clean(); |
| 65 | 65 | return trim($output); |
@@ -44,25 +44,25 @@ |
||
| 44 | 44 | parent::__construct( $options ); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * The Super block output function. |
|
| 49 | - * |
|
| 50 | - * @param array $args |
|
| 51 | - * @param array $widget_args |
|
| 52 | - * @param string $content |
|
| 53 | - * |
|
| 54 | - * @return mixed|string|bool |
|
| 55 | - */ |
|
| 47 | + /** |
|
| 48 | + * The Super block output function. |
|
| 49 | + * |
|
| 50 | + * @param array $args |
|
| 51 | + * @param array $widget_args |
|
| 52 | + * @param string $content |
|
| 53 | + * |
|
| 54 | + * @return mixed|string|bool |
|
| 55 | + */ |
|
| 56 | 56 | public function output( $args = array(), $widget_args = array(), $content = '' ) { |
| 57 | 57 | |
| 58 | - ob_start(); |
|
| 58 | + ob_start(); |
|
| 59 | 59 | |
| 60 | - do_action( 'wpinv_success_content_before' ); |
|
| 61 | - echo wpinv_payment_receipt( $args ); |
|
| 62 | - do_action( 'wpinv_success_content_after' ); |
|
| 60 | + do_action( 'wpinv_success_content_before' ); |
|
| 61 | + echo wpinv_payment_receipt( $args ); |
|
| 62 | + do_action( 'wpinv_success_content_after' ); |
|
| 63 | 63 | |
| 64 | - $output = ob_get_clean(); |
|
| 65 | - return trim($output); |
|
| 64 | + $output = ob_get_clean(); |
|
| 65 | + return trim($output); |
|
| 66 | 66 | |
| 67 | 67 | } |
| 68 | 68 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 2 | +if (!defined('ABSPATH')) { |
|
| 3 | 3 | exit; |
| 4 | 4 | } |
| 5 | 5 | |
@@ -22,15 +22,15 @@ discard block |
||
| 22 | 22 | 'block-keywords'=> "['invoicing','receipt']", |
| 23 | 23 | 'class_name' => __CLASS__, |
| 24 | 24 | 'base_id' => 'wpinv_receipt', |
| 25 | - 'name' => __('Invoicing > Invoice Receipt','invoicing'), |
|
| 25 | + 'name' => __('Invoicing > Invoice Receipt', 'invoicing'), |
|
| 26 | 26 | 'widget_ops' => array( |
| 27 | 27 | 'classname' => 'wpinv-receipt-class wpi-g', |
| 28 | - 'description' => esc_html__('Displays invoice receipt after checkout.','invoicing'), |
|
| 28 | + 'description' => esc_html__('Displays invoice receipt after checkout.', 'invoicing'), |
|
| 29 | 29 | ), |
| 30 | 30 | 'arguments' => array( |
| 31 | 31 | 'title' => array( |
| 32 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
| 33 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
| 32 | + 'title' => __('Widget title', 'invoicing'), |
|
| 33 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
| 34 | 34 | 'type' => 'text', |
| 35 | 35 | 'desc_tip' => true, |
| 36 | 36 | 'default' => '', |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | ); |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - parent::__construct( $options ); |
|
| 44 | + parent::__construct($options); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -53,13 +53,13 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return mixed|string|bool |
| 55 | 55 | */ |
| 56 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
| 56 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
| 57 | 57 | |
| 58 | 58 | ob_start(); |
| 59 | 59 | |
| 60 | - do_action( 'wpinv_success_content_before' ); |
|
| 61 | - echo wpinv_payment_receipt( $args ); |
|
| 62 | - do_action( 'wpinv_success_content_after' ); |
|
| 60 | + do_action('wpinv_success_content_before'); |
|
| 61 | + echo wpinv_payment_receipt($args); |
|
| 62 | + do_action('wpinv_success_content_after'); |
|
| 63 | 63 | |
| 64 | 64 | $output = ob_get_clean(); |
| 65 | 65 | return trim($output); |