Passed
Pull Request — master (#47)
by Kiran
04:17
created
includes/class-wpinv-api.php 2 patches
Doc Comments   +8 added lines patch added patch discarded remove patch
@@ -47,6 +47,9 @@  discard block
 block discarded – undo
47 47
         }
48 48
     }
49 49
     
50
+    /**
51
+     * @param integer $code
52
+     */
50 53
     public function send_status( $code ) {
51 54
         status_header( $code );
52 55
     }
@@ -195,6 +198,11 @@  discard block
 block discarded – undo
195 198
 class WPInv_API_Exception extends Exception {
196 199
     protected $error_code;
197 200
 
201
+    /**
202
+     * @param string $error_code
203
+     * @param string $error_message
204
+     * @param integer $http_status_code
205
+     */
198 206
     public function __construct( $error_code, $error_message, $http_status_code ) {
199 207
         $this->error_code = $error_code;
200 208
         parent::__construct( $error_message, $http_status_code );
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -7,51 +7,51 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_API {
15 15
     protected $post_type = 'wpi_invoice';
16 16
     
17
-    public function __construct( $params = array() ) {
17
+    public function __construct($params = array()) {
18 18
     }
19
-    public function insert_invoice( $data ) {
19
+    public function insert_invoice($data) {
20 20
         global $wpdb;
21 21
         //wpinv_transaction_query( 'start' );
22 22
 
23 23
         try {
24
-            if ( empty( $data['invoice'] ) ) {
25
-                throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 );
24
+            if (empty($data['invoice'])) {
25
+                throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400);
26 26
             }
27 27
 
28
-            $data = apply_filters( 'wpinv_api_create_invoice_data', $data['invoice'], $this );
28
+            $data = apply_filters('wpinv_api_create_invoice_data', $data['invoice'], $this);
29 29
 
30
-            $invoice = wpinv_insert_invoice( $data, true );
31
-            if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
32
-                throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 );
30
+            $invoice = wpinv_insert_invoice($data, true);
31
+            if (empty($invoice->ID) || is_wp_error($invoice)) {
32
+                throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400);
33 33
             }
34 34
 
35 35
             // HTTP 201 Created
36
-            $this->send_status( 201 );
36
+            $this->send_status(201);
37 37
 
38
-            do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this );
38
+            do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this);
39 39
 
40 40
             //wpinv_transaction_query( 'commit' );
41 41
 
42
-            return wpinv_get_invoice( $invoice->ID );
43
-        } catch ( WPInv_API_Exception $e ) {
42
+            return wpinv_get_invoice($invoice->ID);
43
+        } catch (WPInv_API_Exception $e) {
44 44
             //wpinv_transaction_query( 'rollback' );
45 45
 
46
-            return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
46
+            return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
47 47
         }
48 48
     }
49 49
     
50
-    public function send_status( $code ) {
51
-        status_header( $code );
50
+    public function send_status($code) {
51
+        status_header($code);
52 52
     }
53 53
     
54
-    protected function set_billing_details( $invoice, $data ) {
54
+    protected function set_billing_details($invoice, $data) {
55 55
         $address_fields = array(
56 56
             'user_id',
57 57
             'first_name',
@@ -70,66 +70,66 @@  discard block
 block discarded – undo
70 70
         $billing_details = array();
71 71
         $user_id = $invoice->get_user_id();
72 72
         
73
-        foreach ( $address_fields as $field ) {
74
-            if ( isset( $data['billing_details'][ $field ] ) ) {
75
-                $value = sanitize_text_field( $data['billing_details'][ $field ] );
73
+        foreach ($address_fields as $field) {
74
+            if (isset($data['billing_details'][$field])) {
75
+                $value = sanitize_text_field($data['billing_details'][$field]);
76 76
                 
77
-                if ( $field == 'country' && empty( $value ) ) {
78
-                    if ( !empty( $invoice->country ) ) {
77
+                if ($field == 'country' && empty($value)) {
78
+                    if (!empty($invoice->country)) {
79 79
                         $value = $invoice->country;
80 80
                     } else {
81
-                        $value = wpinv_default_billing_country( '', $user_id );
81
+                        $value = wpinv_default_billing_country('', $user_id);
82 82
                     }
83 83
                 }
84 84
                 
85
-                if ( $field == 'state' && empty( $value ) ) {
86
-                    if ( !empty( $invoice->state ) ) {
85
+                if ($field == 'state' && empty($value)) {
86
+                    if (!empty($invoice->state)) {
87 87
                         $value = $invoice->state;
88 88
                     } else {
89 89
                         $value = wpinv_get_default_state();
90 90
                     }
91 91
                 }
92 92
                 
93
-                $invoice->set( $field, $value );
93
+                $invoice->set($field, $value);
94 94
                 
95
-                update_post_meta( $invoice->ID, '_wpinv_' . $field, $value );
95
+                update_post_meta($invoice->ID, '_wpinv_' . $field, $value);
96 96
             }
97 97
         }
98 98
         
99 99
         return $invoice;
100 100
     }
101 101
     
102
-    protected function set_discount( $invoice, $data ) {
103
-        if ( isset( $data['discount'] ) ) {
104
-            $invoice->set( 'discount', wpinv_round_amount( $data['discount'] ) );
102
+    protected function set_discount($invoice, $data) {
103
+        if (isset($data['discount'])) {
104
+            $invoice->set('discount', wpinv_round_amount($data['discount']));
105 105
             
106
-            update_post_meta( $invoice->ID, '_wpinv_discount', wpinv_round_amount( $data['discount'] ) );
106
+            update_post_meta($invoice->ID, '_wpinv_discount', wpinv_round_amount($data['discount']));
107 107
             
108
-            if ( isset( $data['discount_code'] ) ) {
109
-                $invoice->set( 'discount_code', $data['discount_code'] );
108
+            if (isset($data['discount_code'])) {
109
+                $invoice->set('discount_code', $data['discount_code']);
110 110
                 
111
-                update_post_meta( $invoice->ID, '_wpinv_discount_code', $data['discount_code'] );
111
+                update_post_meta($invoice->ID, '_wpinv_discount_code', $data['discount_code']);
112 112
             }
113 113
         }
114 114
         
115 115
         return $invoice;
116 116
     }
117 117
     
118
-    protected function set_items( $invoice, $data ) {
119
-        if ( !empty( $data['items'] ) && is_array( $data['items'] ) ) {
118
+    protected function set_items($invoice, $data) {
119
+        if (!empty($data['items']) && is_array($data['items'])) {
120 120
             $items_array = array();
121 121
            
122
-            if ( !empty( $invoice->country ) ) {
122
+            if (!empty($invoice->country)) {
123 123
                 $country = $invoice->country;
124
-            } else if ( !empty( $data['billing_details']['country'] ) ) {
124
+            } else if (!empty($data['billing_details']['country'])) {
125 125
                 $country = $data['billing_details']['country'];
126 126
             } else {
127
-                $country = wpinv_default_billing_country( '', $invoice->get_user_id() );
127
+                $country = wpinv_default_billing_country('', $invoice->get_user_id());
128 128
             }
129 129
             
130
-            if ( !empty( $invoice->state ) ) {
130
+            if (!empty($invoice->state)) {
131 131
                 $state = $invoice->state;
132
-            } else if ( !empty( $data['billing_details']['state'] ) ) {
132
+            } else if (!empty($data['billing_details']['state'])) {
133 133
                 $state = $data['billing_details']['state'];
134 134
             } else {
135 135
                 $state = wpinv_get_default_state();
@@ -138,54 +138,54 @@  discard block
 block discarded – undo
138 138
             $_POST['country']   = $country;
139 139
             $_POST['state']     = $state;
140 140
             
141
-            $rate = wpinv_get_tax_rate( $country, $state, 'global' );
141
+            $rate = wpinv_get_tax_rate($country, $state, 'global');
142 142
             
143 143
             $total_tax = 0;
144
-            foreach ( $data['items'] as $item ) {
145
-                $id                 = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
146
-                $title              = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : '';
147
-                $desc               = isset( $item['description'] ) ? sanitize_text_field( $item['description'] ) : '';
148
-                $amount             = isset( $item['amount'] ) ? wpinv_round_amount( $item['amount'] ) : 0;
144
+            foreach ($data['items'] as $item) {
145
+                $id                 = isset($item['id']) ? sanitize_text_field($item['id']) : '';
146
+                $title              = isset($item['title']) ? sanitize_text_field($item['title']) : '';
147
+                $desc               = isset($item['description']) ? sanitize_text_field($item['description']) : '';
148
+                $amount             = isset($item['amount']) ? wpinv_round_amount($item['amount']) : 0;
149 149
                 
150
-                if ( !empty( $item['vat_rates_class'] ) ) {
150
+                if (!empty($item['vat_rates_class'])) {
151 151
                     $vat_rates_class = $item['vat_rates_class'];
152 152
                 } else {
153 153
                     $vat_rates_class = '_standard';
154 154
                 }
155
-                $vat_rate = wpinv_get_tax_rate( $country, $state, $id );
155
+                $vat_rate = wpinv_get_tax_rate($country, $state, $id);
156 156
                 
157
-                $tax = $amount > 0 ? ( $amount * 0.01 * (float)$vat_rate ) : 0;
157
+                $tax = $amount > 0 ? ($amount * 0.01 * (float)$vat_rate) : 0;
158 158
                 $total_tax += $tax;
159 159
                 
160 160
                 $items_array[] = array(
161 161
                     'id'                => $id,
162
-                    'title'             => esc_html( $title ),
163
-                    'description'       => esc_html( $desc ),
164
-                    'amount'            => $amount > 0 ? wpinv_round_amount( $amount ) : 0,
165
-                    'subtotal'          => $amount > 0 ? wpinv_round_amount( $amount ) : 0,
162
+                    'title'             => esc_html($title),
163
+                    'description'       => esc_html($desc),
164
+                    'amount'            => $amount > 0 ? wpinv_round_amount($amount) : 0,
165
+                    'subtotal'          => $amount > 0 ? wpinv_round_amount($amount) : 0,
166 166
                     'vat_rates_class'   => $vat_rates_class,
167 167
                     'vat_rate'          => $vat_rate,
168
-                    'tax'               => $tax > 0 ? wpinv_round_amount( $tax ) : 0,
168
+                    'tax'               => $tax > 0 ? wpinv_round_amount($tax) : 0,
169 169
                 );
170 170
             }
171 171
 
172
-            update_post_meta( $invoice->ID, '_wpinv_tax', wpinv_round_amount( $total_tax ) );
173
-            $invoice->set( 'tax', wpinv_round_amount( $total_tax ) );
172
+            update_post_meta($invoice->ID, '_wpinv_tax', wpinv_round_amount($total_tax));
173
+            $invoice->set('tax', wpinv_round_amount($total_tax));
174 174
             
175
-            $items_array = apply_filters( 'wpinv_save_invoice_items', $items_array, $data['items'], $invoice );
175
+            $items_array = apply_filters('wpinv_save_invoice_items', $items_array, $data['items'], $invoice);
176 176
             
177
-            $invoice->set( 'items', $items_array );
178
-            update_post_meta( $invoice->ID, '_wpinv_items', $items_array );
177
+            $invoice->set('items', $items_array);
178
+            update_post_meta($invoice->ID, '_wpinv_items', $items_array);
179 179
         }
180 180
         
181 181
         return $invoice;
182 182
     }
183 183
     
184
-    protected function set_invoice_meta( $invoice_id, $invoice_meta ) {
185
-        foreach ( $invoice_meta as $meta_key => $meta_value ) {
184
+    protected function set_invoice_meta($invoice_id, $invoice_meta) {
185
+        foreach ($invoice_meta as $meta_key => $meta_value) {
186 186
 
187
-            if ( is_string( $meta_key) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) {
188
-                update_post_meta( $invoice_id, $meta_key, $meta_value );
187
+            if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) {
188
+                update_post_meta($invoice_id, $meta_key, $meta_value);
189 189
             }
190 190
         }
191 191
     }
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
 class WPInv_API_Exception extends Exception {
196 196
     protected $error_code;
197 197
 
198
-    public function __construct( $error_code, $error_message, $http_status_code ) {
198
+    public function __construct($error_code, $error_message, $http_status_code) {
199 199
         $this->error_code = $error_code;
200
-        parent::__construct( $error_message, $http_status_code );
200
+        parent::__construct($error_message, $http_status_code);
201 201
     }
202 202
 
203 203
     public function getErrorCode() {
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 2 patches
Doc Comments   +36 added lines patch added patch discarded remove patch
@@ -83,6 +83,9 @@  discard block
 block discarded – undo
83 83
         return $value;
84 84
     }
85 85
 
86
+    /**
87
+     * @param string $key
88
+     */
86 89
     public function set( $key, $value ) {
87 90
         $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
88 91
 
@@ -916,6 +919,9 @@  discard block
 block discarded – undo
916 919
         return $removed;
917 920
     }
918 921
 
922
+    /**
923
+     * @param string $key
924
+     */
919 925
     public function remove_fee_by( $key, $value, $global = false ) {
920 926
         $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
921 927
             'index', 'label', 'amount', 'type',
@@ -1375,6 +1381,9 @@  discard block
 block discarded – undo
1375 1381
         return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1376 1382
     }
1377 1383
     
1384
+    /**
1385
+     * @return boolean
1386
+     */
1378 1387
     public function get_discounts( $array = false ) {
1379 1388
         $discounts = $this->discounts;
1380 1389
         if ( $array && $discounts ) {
@@ -1383,6 +1392,9 @@  discard block
 block discarded – undo
1383 1392
         return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1384 1393
     }
1385 1394
     
1395
+    /**
1396
+     * @return string
1397
+     */
1386 1398
     public function get_discount( $currency = false, $dash = false ) {
1387 1399
         if ( !empty( $this->discounts ) ) {
1388 1400
             global $ajax_cart_details;
@@ -1479,10 +1491,16 @@  discard block
 block discarded – undo
1479 1491
         return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1480 1492
     }
1481 1493
     
1494
+    /**
1495
+     * @return string
1496
+     */
1482 1497
     public function get_user_info() {
1483 1498
         return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1484 1499
     }
1485 1500
     
1501
+    /**
1502
+     * @return string
1503
+     */
1486 1504
     public function get_email() {
1487 1505
         return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1488 1506
     }
@@ -1525,10 +1543,16 @@  discard block
 block discarded – undo
1525 1543
         return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1526 1544
     }
1527 1545
     
1546
+    /**
1547
+     * @return string
1548
+     */
1528 1549
     public function get_created_date() {
1529 1550
         return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1530 1551
     }
1531 1552
     
1553
+    /**
1554
+     * @return string
1555
+     */
1532 1556
     public function get_due_date( $display = false ) {
1533 1557
         $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1534 1558
         
@@ -2081,6 +2105,9 @@  discard block
 block discarded – undo
2081 2105
         return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2082 2106
     }
2083 2107
         
2108
+    /**
2109
+     * @return string
2110
+     */
2084 2111
     public function get_expiration() {
2085 2112
         $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );
2086 2113
         return $expiration;
@@ -2096,6 +2123,9 @@  discard block
 block discarded – undo
2096 2123
         return $cancelled_date;
2097 2124
     }
2098 2125
     
2126
+    /**
2127
+     * @return string
2128
+     */
2099 2129
     public function get_trial_end_date( $formatted = true ) {
2100 2130
         if ( !$this->is_free_trial() || !$this->is_paid() ) {
2101 2131
             return NULL;
@@ -2117,6 +2147,9 @@  discard block
 block discarded – undo
2117 2147
         return $trial_end_date;
2118 2148
     }
2119 2149
     
2150
+    /**
2151
+     * @return string
2152
+     */
2120 2153
     public function get_subscription_created( $default = true ) {
2121 2154
         $created = $this->get_meta( '_wpinv_subscr_created', true );
2122 2155
         
@@ -2126,6 +2159,9 @@  discard block
 block discarded – undo
2126 2159
         return $created;
2127 2160
     }
2128 2161
     
2162
+    /**
2163
+     * @return string
2164
+     */
2129 2165
     public function get_subscription_start( $formatted = true ) {
2130 2166
         if ( !$this->is_paid() ) {
2131 2167
             return '-';
Please login to merge, or discard this patch.
Spacing   +798 added lines, -798 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  discard block
 block discarded – undo
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
     
@@ -65,17 +65,17 @@  discard block
 block discarded – undo
65 65
     public $full_name = '';
66 66
     public $parent_invoice = 0;
67 67
     
68
-    public function __construct( $invoice_id = false ) {
69
-        if( empty( $invoice_id ) ) {
68
+    public function __construct($invoice_id = false) {
69
+        if (empty($invoice_id)) {
70 70
             return false;
71 71
         }
72 72
 
73
-        $this->setup_invoice( $invoice_id );
73
+        $this->setup_invoice($invoice_id);
74 74
     }
75 75
 
76
-    public function get( $key ) {
77
-        if ( method_exists( $this, 'get_' . $key ) ) {
78
-            $value = call_user_func( array( $this, 'get_' . $key ) );
76
+    public function get($key) {
77
+        if (method_exists($this, 'get_' . $key)) {
78
+            $value = call_user_func(array($this, 'get_' . $key));
79 79
         } else {
80 80
             $value = $this->$key;
81 81
         }
@@ -83,51 +83,51 @@  discard block
 block discarded – undo
83 83
         return $value;
84 84
     }
85 85
 
86
-    public function set( $key, $value ) {
87
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
86
+    public function set($key, $value) {
87
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
88 88
 
89
-        if ( $key === 'status' ) {
89
+        if ($key === 'status') {
90 90
             $this->old_status = $this->status;
91 91
         }
92 92
 
93
-        if ( ! in_array( $key, $ignore ) ) {
94
-            $this->pending[ $key ] = $value;
93
+        if (!in_array($key, $ignore)) {
94
+            $this->pending[$key] = $value;
95 95
         }
96 96
 
97
-        if( '_ID' !== $key ) {
97
+        if ('_ID' !== $key) {
98 98
             $this->$key = $value;
99 99
         }
100 100
     }
101 101
 
102
-    public function _isset( $name ) {
103
-        if ( property_exists( $this, $name) ) {
104
-            return false === empty( $this->$name );
102
+    public function _isset($name) {
103
+        if (property_exists($this, $name)) {
104
+            return false === empty($this->$name);
105 105
         } else {
106 106
             return null;
107 107
         }
108 108
     }
109 109
 
110
-    private function setup_invoice( $invoice_id ) {
110
+    private function setup_invoice($invoice_id) {
111 111
         $this->pending = array();
112 112
 
113
-        if ( empty( $invoice_id ) ) {
113
+        if (empty($invoice_id)) {
114 114
             return false;
115 115
         }
116 116
 
117
-        $invoice = get_post( $invoice_id );
117
+        $invoice = get_post($invoice_id);
118 118
 
119
-        if( !$invoice || is_wp_error( $invoice ) ) {
119
+        if (!$invoice || is_wp_error($invoice)) {
120 120
             return false;
121 121
         }
122 122
 
123
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
123
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
124 124
             return false;
125 125
         }
126 126
 
127
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
127
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
128 128
         
129 129
         // Primary Identifier
130
-        $this->ID              = absint( $invoice_id );
130
+        $this->ID              = absint($invoice_id);
131 131
         $this->post_type       = $invoice->post_type;
132 132
         
133 133
         // We have a payment, get the generic payment_meta item to reduce calls to it
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         $this->post_status     = $this->status;
140 140
         $this->mode            = $this->setup_mode();
141 141
         $this->parent_invoice  = $invoice->post_parent;
142
-        $this->post_name       = $this->setup_post_name( $invoice );
142
+        $this->post_name       = $this->setup_post_name($invoice);
143 143
         $this->status_nicename = $this->setup_status_nicename($invoice->post_status);
144 144
 
145 145
         // Items
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
         
162 162
         // User based
163 163
         $this->ip              = $this->setup_ip();
164
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
165
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
164
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
165
+        $this->email           = get_the_author_meta('email', $this->user_id);
166 166
         
167 167
         $this->user_info       = $this->setup_user_info();
168 168
                 
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
         $this->company         = $this->user_info['company'];
172 172
         $this->vat_number      = $this->user_info['vat_number'];
173 173
         $this->vat_rate        = $this->user_info['vat_rate'];
174
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
174
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
175 175
         $this->address         = $this->user_info['address'];
176 176
         $this->city            = $this->user_info['city'];
177 177
         $this->country         = $this->user_info['country'];
@@ -186,47 +186,47 @@  discard block
 block discarded – undo
186 186
         // Other Identifiers
187 187
         $this->key             = $this->setup_invoice_key();
188 188
         $this->number          = $this->setup_invoice_number();
189
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
189
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
190 190
         
191
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
191
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
192 192
         
193 193
         // Allow extensions to add items to this object via hook
194
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
194
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
195 195
 
196 196
         return true;
197 197
     }
198 198
     
199 199
     private function setup_status_nicename($status) {
200
-        $all_invoice_statuses  = wpinv_get_invoice_statuses();
201
-        $status   = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );
200
+        $all_invoice_statuses = wpinv_get_invoice_statuses();
201
+        $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');
202 202
 
203
-        return apply_filters( 'setup_status_nicename', $status );
203
+        return apply_filters('setup_status_nicename', $status);
204 204
     }
205 205
     
206
-    private function setup_post_name( $post = NULL ) {
206
+    private function setup_post_name($post = NULL) {
207 207
         $post_name = '';
208 208
         
209
-        if ( !empty( $post ) ) {
210
-            if( !empty( $post->post_name ) ) {
209
+        if (!empty($post)) {
210
+            if (!empty($post->post_name)) {
211 211
                 $post_name = $post->post_name;
212
-            } else if ( !empty( $post->ID ) && !empty( $post->post_title ) ) {
213
-                $post_name = sanitize_title( $post->post_title );
212
+            } else if (!empty($post->ID) && !empty($post->post_title)) {
213
+                $post_name = sanitize_title($post->post_title);
214 214
                 
215 215
                 global $wpdb;
216
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
216
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
217 217
             }
218 218
         }
219 219
 
220
-        $this->post_name   = $post_name;
220
+        $this->post_name = $post_name;
221 221
     }
222 222
     
223 223
     private function setup_due_date() {
224
-        $due_date = $this->get_meta( '_wpinv_due_date' );
224
+        $due_date = $this->get_meta('_wpinv_due_date');
225 225
         
226
-        if ( empty( $due_date ) ) {
227
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
228
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
229
-        } else if ( $due_date == 'none' ) {
226
+        if (empty($due_date)) {
227
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
228
+            $due_date = date_i18n('Y-m-d', $overdue_time);
229
+        } else if ($due_date == 'none') {
230 230
             $due_date = '';
231 231
         }
232 232
 
@@ -234,63 +234,63 @@  discard block
 block discarded – undo
234 234
     }
235 235
     
236 236
     private function setup_completed_date() {
237
-        $invoice = get_post( $this->ID );
237
+        $invoice = get_post($this->ID);
238 238
 
239
-        if ( 'pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
239
+        if ('pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
240 240
             return false; // This invoice was never paid
241 241
         }
242 242
 
243
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
243
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
244 244
 
245 245
         return $date;
246 246
     }
247 247
     
248 248
     private function setup_cart_details() {
249
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
249
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
250 250
         return $cart_details;
251 251
     }
252 252
     
253 253
     public function array_convert() {
254
-        return get_object_vars( $this );
254
+        return get_object_vars($this);
255 255
     }
256 256
     
257 257
     private function setup_items() {
258
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
258
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
259 259
         return $items;
260 260
     }
261 261
     
262 262
     private function setup_fees() {
263
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
263
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
264 264
         return $payment_fees;
265 265
     }
266 266
         
267 267
     private function setup_currency() {
268
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
268
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
269 269
         return $currency;
270 270
     }
271 271
     
272 272
     private function setup_discount() {
273 273
         //$discount = $this->get_meta( '_wpinv_discount', true );
274
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
275
-        if ( $discount < 0 ) {
274
+        $discount = (float)$this->subtotal - ((float)$this->total - (float)$this->tax - (float)$this->fees_total);
275
+        if ($discount < 0) {
276 276
             $discount = 0;
277 277
         }
278
-        $discount = wpinv_round_amount( $discount );
278
+        $discount = wpinv_round_amount($discount);
279 279
         
280 280
         return $discount;
281 281
     }
282 282
     
283 283
     private function setup_discount_code() {
284
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
284
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
285 285
         return $discount_code;
286 286
     }
287 287
     
288 288
     private function setup_tax() {
289
-        $tax = $this->get_meta( '_wpinv_tax', true );
289
+        $tax = $this->get_meta('_wpinv_tax', true);
290 290
 
291 291
         // We don't have tax as it's own meta and no meta was passed
292
-        if ( '' === $tax ) {            
293
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
292
+        if ('' === $tax) {            
293
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
294 294
         }
295 295
 
296 296
         return $tax;
@@ -300,9 +300,9 @@  discard block
 block discarded – undo
300 300
         $subtotal     = 0;
301 301
         $cart_details = $this->cart_details;
302 302
 
303
-        if ( is_array( $cart_details ) ) {
304
-            foreach ( $cart_details as $item ) {
305
-                if ( isset( $item['subtotal'] ) ) {
303
+        if (is_array($cart_details)) {
304
+            foreach ($cart_details as $item) {
305
+                if (isset($item['subtotal'])) {
306 306
                     $subtotal += $item['subtotal'];
307 307
                 }
308 308
             }
@@ -316,18 +316,18 @@  discard block
 block discarded – undo
316 316
     }
317 317
     
318 318
     private function setup_discounts() {
319
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
319
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
320 320
         return $discounts;
321 321
     }
322 322
     
323 323
     private function setup_total() {
324
-        $amount = $this->get_meta( '_wpinv_total', true );
324
+        $amount = $this->get_meta('_wpinv_total', true);
325 325
 
326
-        if ( empty( $amount ) && '0.00' != $amount ) {
327
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
328
-            $meta   = maybe_unserialize( $meta );
326
+        if (empty($amount) && '0.00' != $amount) {
327
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
328
+            $meta   = maybe_unserialize($meta);
329 329
 
330
-            if ( isset( $meta['amount'] ) ) {
330
+            if (isset($meta['amount'])) {
331 331
                 $amount = $meta['amount'];
332 332
             }
333 333
         }
@@ -336,13 +336,13 @@  discard block
 block discarded – undo
336 336
     }
337 337
     
338 338
     private function setup_mode() {
339
-        return $this->get_meta( '_wpinv_mode' );
339
+        return $this->get_meta('_wpinv_mode');
340 340
     }
341 341
 
342 342
     private function setup_gateway() {
343
-        $gateway = $this->get_meta( '_wpinv_gateway' );
343
+        $gateway = $this->get_meta('_wpinv_gateway');
344 344
         
345
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
345
+        if (empty($gateway) && 'publish' === $this->status) {
346 346
             $gateway = 'manual';
347 347
         }
348 348
         
@@ -350,23 +350,23 @@  discard block
 block discarded – undo
350 350
     }
351 351
     
352 352
     private function setup_gateway_title() {
353
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
353
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
354 354
         return $gateway_title;
355 355
     }
356 356
 
357 357
     private function setup_transaction_id() {
358
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
358
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
359 359
 
360
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
360
+        if (empty($transaction_id) || (int)$transaction_id === (int)$this->ID) {
361 361
             $gateway        = $this->gateway;
362
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
362
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
363 363
         }
364 364
 
365 365
         return $transaction_id;
366 366
     }
367 367
 
368 368
     private function setup_ip() {
369
-        $ip = $this->get_meta( '_wpinv_user_ip' );
369
+        $ip = $this->get_meta('_wpinv_user_ip');
370 370
         return $ip;
371 371
     }
372 372
 
@@ -376,62 +376,62 @@  discard block
 block discarded – undo
376 376
     ///}
377 377
         
378 378
     private function setup_first_name() {
379
-        $first_name = $this->get_meta( '_wpinv_first_name' );
379
+        $first_name = $this->get_meta('_wpinv_first_name');
380 380
         return $first_name;
381 381
     }
382 382
     
383 383
     private function setup_last_name() {
384
-        $last_name = $this->get_meta( '_wpinv_last_name' );
384
+        $last_name = $this->get_meta('_wpinv_last_name');
385 385
         return $last_name;
386 386
     }
387 387
     
388 388
     private function setup_company() {
389
-        $company = $this->get_meta( '_wpinv_company' );
389
+        $company = $this->get_meta('_wpinv_company');
390 390
         return $company;
391 391
     }
392 392
     
393 393
     private function setup_vat_number() {
394
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
394
+        $vat_number = $this->get_meta('_wpinv_vat_number');
395 395
         return $vat_number;
396 396
     }
397 397
     
398 398
     private function setup_vat_rate() {
399
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
399
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
400 400
         return $vat_rate;
401 401
     }
402 402
     
403 403
     private function setup_adddress_confirmed() {
404
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
404
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
405 405
         return $adddress_confirmed;
406 406
     }
407 407
     
408 408
     private function setup_phone() {
409
-        $phone = $this->get_meta( '_wpinv_phone' );
409
+        $phone = $this->get_meta('_wpinv_phone');
410 410
         return $phone;
411 411
     }
412 412
     
413 413
     private function setup_address() {
414
-        $address = $this->get_meta( '_wpinv_address', true );
414
+        $address = $this->get_meta('_wpinv_address', true);
415 415
         return $address;
416 416
     }
417 417
     
418 418
     private function setup_city() {
419
-        $city = $this->get_meta( '_wpinv_city', true );
419
+        $city = $this->get_meta('_wpinv_city', true);
420 420
         return $city;
421 421
     }
422 422
     
423 423
     private function setup_country() {
424
-        $country = $this->get_meta( '_wpinv_country', true );
424
+        $country = $this->get_meta('_wpinv_country', true);
425 425
         return $country;
426 426
     }
427 427
     
428 428
     private function setup_state() {
429
-        $state = $this->get_meta( '_wpinv_state', true );
429
+        $state = $this->get_meta('_wpinv_state', true);
430 430
         return $state;
431 431
     }
432 432
     
433 433
     private function setup_zip() {
434
-        $zip = $this->get_meta( '_wpinv_zip', true );
434
+        $zip = $this->get_meta('_wpinv_zip', true);
435 435
         return $zip;
436 436
     }
437 437
 
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
             'user_id'        => $this->user_id,
441 441
             'first_name'     => $this->first_name,
442 442
             'last_name'      => $this->last_name,
443
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
443
+            'email'          => get_the_author_meta('email', $this->user_id),
444 444
             'phone'          => $this->phone,
445 445
             'address'        => $this->address,
446 446
             'city'           => $this->city,
@@ -455,12 +455,12 @@  discard block
 block discarded – undo
455 455
         );
456 456
         
457 457
         $user_info = array();
458
-        if ( isset( $this->payment_meta['user_info'] ) ) {
459
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
458
+        if (isset($this->payment_meta['user_info'])) {
459
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
460 460
             
461
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
461
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
462 462
                 $this->user_id = $post->post_author;
463
-                $this->email = get_the_author_meta( 'email', $this->user_id );
463
+                $this->email = get_the_author_meta('email', $this->user_id);
464 464
                 
465 465
                 $user_info['user_id'] = $this->user_id;
466 466
                 $user_info['email'] = $this->email;
@@ -469,13 +469,13 @@  discard block
 block discarded – undo
469 469
             }
470 470
         }
471 471
         
472
-        $user_info    = wp_parse_args( $user_info, $defaults );
472
+        $user_info = wp_parse_args($user_info, $defaults);
473 473
         
474 474
         // Get the user, but only if it's been created
475
-        $user = get_userdata( $this->user_id );
475
+        $user = get_userdata($this->user_id);
476 476
         
477
-        if ( !empty( $user ) && $user->ID > 0 ) {
478
-            if ( empty( $user_info ) ) {
477
+        if (!empty($user) && $user->ID > 0) {
478
+            if (empty($user_info)) {
479 479
                 $user_info = array(
480 480
                     'user_id'    => $user->ID,
481 481
                     'first_name' => $user->first_name,
@@ -484,23 +484,23 @@  discard block
 block discarded – undo
484 484
                     'discount'   => '',
485 485
                 );
486 486
             } else {
487
-                foreach ( $user_info as $key => $value ) {
488
-                    if ( ! empty( $value ) ) {
487
+                foreach ($user_info as $key => $value) {
488
+                    if (!empty($value)) {
489 489
                         continue;
490 490
                     }
491 491
 
492
-                    switch( $key ) {
492
+                    switch ($key) {
493 493
                         case 'user_id':
494
-                            $user_info[ $key ] = $user->ID;
494
+                            $user_info[$key] = $user->ID;
495 495
                             break;
496 496
                         case 'first_name':
497
-                            $user_info[ $key ] = $user->first_name;
497
+                            $user_info[$key] = $user->first_name;
498 498
                             break;
499 499
                         case 'last_name':
500
-                            $user_info[ $key ] = $user->last_name;
500
+                            $user_info[$key] = $user->last_name;
501 501
                             break;
502 502
                         case 'email':
503
-                            $user_info[ $key ] = $user->user_email;
503
+                            $user_info[$key] = $user->user_email;
504 504
                             break;
505 505
                     }
506 506
                 }
@@ -511,16 +511,16 @@  discard block
 block discarded – undo
511 511
     }
512 512
 
513 513
     private function setup_invoice_key() {
514
-        $key = $this->get_meta( '_wpinv_key', true );
514
+        $key = $this->get_meta('_wpinv_key', true);
515 515
         
516 516
         return $key;
517 517
     }
518 518
 
519 519
     private function setup_invoice_number() {
520
-        $number = $this->get_meta( '_wpinv_number', true );
520
+        $number = $this->get_meta('_wpinv_number', true);
521 521
 
522
-        if ( !$number ) {
523
-            $number = wpinv_format_invoice_number( $this->ID );
522
+        if (!$number) {
523
+            $number = wpinv_format_invoice_number($this->ID);
524 524
         }
525 525
 
526 526
         return $number;
@@ -531,18 +531,18 @@  discard block
 block discarded – undo
531 531
 
532 532
         if ($number = $this->get_number()) {
533 533
             $invoice_title = $number;
534
-        } else if ( ! empty( $this->ID ) ) {
535
-            $invoice_title = wpinv_format_invoice_number( $this->ID );
534
+        } else if (!empty($this->ID)) {
535
+            $invoice_title = wpinv_format_invoice_number($this->ID);
536 536
         } else {
537
-            $invoice_title = wpinv_format_invoice_number( 0 );
537
+            $invoice_title = wpinv_format_invoice_number(0);
538 538
         }
539 539
 
540
-        if ( empty( $this->key ) ) {
540
+        if (empty($this->key)) {
541 541
             $this->key = self::generate_key();
542 542
             $this->pending['key'] = $this->key;
543 543
         }
544 544
 
545
-        if ( empty( $this->ip ) ) {
545
+        if (empty($this->ip)) {
546 546
             $this->ip = wpinv_get_ip();
547 547
             $this->pending['ip'] = $this->ip;
548 548
         }
@@ -574,75 +574,75 @@  discard block
 block discarded – undo
574 574
             'fees'         => $this->fees,
575 575
         );
576 576
         
577
-        $post_name      = sanitize_title( $invoice_title );
577
+        $post_name = sanitize_title($invoice_title);
578 578
 
579 579
         $post_data = array(
580 580
                         'post_title'    => $invoice_title,
581 581
                         'post_status'   => $this->status,
582 582
                         'post_author'   => $this->user_id,
583 583
                         'post_type'     => $this->post_type,
584
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
585
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
584
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
585
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
586 586
                         'post_parent'   => $this->parent_invoice,
587 587
                     );
588
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
588
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
589 589
 
590 590
         // Create a blank invoice
591
-        if ( !empty( $this->ID ) ) {
591
+        if (!empty($this->ID)) {
592 592
             $args['ID']         = $this->ID;
593 593
             $args['post_name']  = $post_name;
594 594
             
595
-            $invoice_id = wp_update_post( $args );
595
+            $invoice_id = wp_update_post($args);
596 596
         } else {
597
-            $invoice_id = wp_insert_post( $args );
597
+            $invoice_id = wp_insert_post($args);
598 598
             
599
-            $post_title = wpinv_format_invoice_number( $invoice_id );
599
+            $post_title = wpinv_format_invoice_number($invoice_id);
600 600
             global $wpdb;
601
-            $wpdb->update( $wpdb->posts, array( 'post_title' => $post_title, 'post_name' => sanitize_title( $post_title ) ), array( 'ID' => $invoice_id ) );
602
-            clean_post_cache( $invoice_id );
601
+            $wpdb->update($wpdb->posts, array('post_title' => $post_title, 'post_name' => sanitize_title($post_title)), array('ID' => $invoice_id));
602
+            clean_post_cache($invoice_id);
603 603
         }
604 604
 
605
-        if ( !empty( $invoice_id ) ) {             
605
+        if (!empty($invoice_id)) {             
606 606
             $this->ID  = $invoice_id;
607 607
             $this->_ID = $invoice_id;
608 608
             
609 609
             ///$this->pending['user_id'] = $this->user_id;
610
-            if ( isset( $this->pending['number'] ) ) {
610
+            if (isset($this->pending['number'])) {
611 611
                 $this->pending['number'] = $post_name;
612 612
             }
613 613
             
614
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
615
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
616
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
617
-                foreach( $this->fees as $fee ) {
618
-                    $this->increase_fees( $fee['amount'] );
614
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
615
+            if (!empty($this->payment_meta['fees'])) {
616
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
617
+                foreach ($this->fees as $fee) {
618
+                    $this->increase_fees($fee['amount']);
619 619
                 }
620 620
             }
621 621
 
622
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );            
622
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);            
623 623
             $this->new = true;
624 624
         }
625 625
 
626 626
         return $this->ID;
627 627
     }
628 628
 
629
-    public function save( $setup = false ) {
629
+    public function save($setup = false) {
630 630
         global $wpi_session;
631 631
         
632 632
         $saved = false;
633
-        if ( empty( $this->items ) ) {
633
+        if (empty($this->items)) {
634 634
             return $saved; // Don't save empty invoice.
635 635
         }
636 636
         
637
-        if ( empty( $this->key ) ) {
637
+        if (empty($this->key)) {
638 638
             $this->key = self::generate_key();
639 639
             $this->pending['key'] = $this->key;
640 640
         }
641 641
         
642
-        if ( empty( $this->ID ) ) {
642
+        if (empty($this->ID)) {
643 643
             $invoice_id = $this->insert_invoice();
644 644
 
645
-            if ( false === $invoice_id ) {
645
+            if (false === $invoice_id) {
646 646
                 $saved = false;
647 647
             } else {
648 648
                 $this->ID = $invoice_id;
@@ -650,27 +650,27 @@  discard block
 block discarded – undo
650 650
         }        
651 651
 
652 652
         // If we have something pending, let's save it
653
-        if ( !empty( $this->pending ) ) {
653
+        if (!empty($this->pending)) {
654 654
             $total_increase = 0;
655 655
             $total_decrease = 0;
656 656
 
657
-            foreach ( $this->pending as $key => $value ) {
658
-                switch( $key ) {
657
+            foreach ($this->pending as $key => $value) {
658
+                switch ($key) {
659 659
                     case 'items':
660 660
                         // Update totals for pending items
661
-                        foreach ( $this->pending[ $key ] as $item ) {
662
-                            switch( $item['action'] ) {
661
+                        foreach ($this->pending[$key] as $item) {
662
+                            switch ($item['action']) {
663 663
                                 case 'add':
664 664
                                     $price = $item['price'];
665 665
                                     $taxes = $item['tax'];
666 666
 
667
-                                    if ( 'publish' === $this->status ) {
667
+                                    if ('publish' === $this->status) {
668 668
                                         $total_increase += $price;
669 669
                                     }
670 670
                                     break;
671 671
 
672 672
                                 case 'remove':
673
-                                    if ( 'publish' === $this->status ) {
673
+                                    if ('publish' === $this->status) {
674 674
                                         $total_decrease += $item['price'];
675 675
                                     }
676 676
                                     break;
@@ -678,16 +678,16 @@  discard block
 block discarded – undo
678 678
                         }
679 679
                         break;
680 680
                     case 'fees':
681
-                        if ( 'publish' !== $this->status ) {
681
+                        if ('publish' !== $this->status) {
682 682
                             break;
683 683
                         }
684 684
 
685
-                        if ( empty( $this->pending[ $key ] ) ) {
685
+                        if (empty($this->pending[$key])) {
686 686
                             break;
687 687
                         }
688 688
 
689
-                        foreach ( $this->pending[ $key ] as $fee ) {
690
-                            switch( $fee['action'] ) {
689
+                        foreach ($this->pending[$key] as $fee) {
690
+                            switch ($fee['action']) {
691 691
                                 case 'add':
692 692
                                     $total_increase += $fee['amount'];
693 693
                                     break;
@@ -699,86 +699,86 @@  discard block
 block discarded – undo
699 699
                         }
700 700
                         break;
701 701
                     case 'status':
702
-                        $this->update_status( $this->status );
702
+                        $this->update_status($this->status);
703 703
                         break;
704 704
                     case 'gateway':
705
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
705
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
706 706
                         break;
707 707
                     case 'mode':
708
-                        $this->update_meta( '_wpinv_mode', $this->mode );
708
+                        $this->update_meta('_wpinv_mode', $this->mode);
709 709
                         break;
710 710
                     case 'transaction_id':
711
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
711
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
712 712
                         break;
713 713
                     case 'ip':
714
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
714
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
715 715
                         break;
716 716
                     ///case 'user_id':
717 717
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
718 718
                         ///$this->user_info['user_id'] = $this->user_id;
719 719
                         ///break;
720 720
                     case 'first_name':
721
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
721
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
722 722
                         $this->user_info['first_name'] = $this->first_name;
723 723
                         break;
724 724
                     case 'last_name':
725
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
725
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
726 726
                         $this->user_info['last_name'] = $this->last_name;
727 727
                         break;
728 728
                     case 'phone':
729
-                        $this->update_meta( '_wpinv_phone', $this->phone );
729
+                        $this->update_meta('_wpinv_phone', $this->phone);
730 730
                         $this->user_info['phone'] = $this->phone;
731 731
                         break;
732 732
                     case 'address':
733
-                        $this->update_meta( '_wpinv_address', $this->address );
733
+                        $this->update_meta('_wpinv_address', $this->address);
734 734
                         $this->user_info['address'] = $this->address;
735 735
                         break;
736 736
                     case 'city':
737
-                        $this->update_meta( '_wpinv_city', $this->city );
737
+                        $this->update_meta('_wpinv_city', $this->city);
738 738
                         $this->user_info['city'] = $this->city;
739 739
                         break;
740 740
                     case 'country':
741
-                        $this->update_meta( '_wpinv_country', $this->country );
741
+                        $this->update_meta('_wpinv_country', $this->country);
742 742
                         $this->user_info['country'] = $this->country;
743 743
                         break;
744 744
                     case 'state':
745
-                        $this->update_meta( '_wpinv_state', $this->state );
745
+                        $this->update_meta('_wpinv_state', $this->state);
746 746
                         $this->user_info['state'] = $this->state;
747 747
                         break;
748 748
                     case 'zip':
749
-                        $this->update_meta( '_wpinv_zip', $this->zip );
749
+                        $this->update_meta('_wpinv_zip', $this->zip);
750 750
                         $this->user_info['zip'] = $this->zip;
751 751
                         break;
752 752
                     case 'company':
753
-                        $this->update_meta( '_wpinv_company', $this->company );
753
+                        $this->update_meta('_wpinv_company', $this->company);
754 754
                         $this->user_info['company'] = $this->company;
755 755
                         break;
756 756
                     case 'vat_number':
757
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
757
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
758 758
                         $this->user_info['vat_number'] = $this->vat_number;
759 759
                         
760
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
761
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
762
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
763
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
760
+                        $vat_info = $wpi_session->get('user_vat_data');
761
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
762
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
763
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool)$adddress_confirmed);
764 764
                             $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
765 765
                         }
766 766
     
767 767
                         break;
768 768
                     case 'vat_rate':
769
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
769
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
770 770
                         $this->user_info['vat_rate'] = $this->vat_rate;
771 771
                         break;
772 772
                     case 'adddress_confirmed':
773
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
773
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
774 774
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
775 775
                         break;
776 776
                     
777 777
                     case 'key':
778
-                        $this->update_meta( '_wpinv_key', $this->key );
778
+                        $this->update_meta('_wpinv_key', $this->key);
779 779
                         break;
780 780
                     case 'number':
781
-                        $this->update_meta( '_wpinv_number', $this->number );
781
+                        $this->update_meta('_wpinv_number', $this->number);
782 782
                         break;
783 783
                     case 'date':
784 784
                         $args = array(
@@ -787,34 +787,34 @@  discard block
 block discarded – undo
787 787
                             'edit_date' => true,
788 788
                         );
789 789
 
790
-                        wp_update_post( $args );
790
+                        wp_update_post($args);
791 791
                         break;
792 792
                     case 'due_date':
793
-                        if ( empty( $this->due_date ) ) {
793
+                        if (empty($this->due_date)) {
794 794
                             $this->due_date = 'none';
795 795
                         }
796 796
                         
797
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
797
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
798 798
                         break;
799 799
                     case 'completed_date':
800
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
800
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
801 801
                         break;
802 802
                     case 'discounts':
803
-                        if ( ! is_array( $this->discounts ) ) {
804
-                            $this->discounts = explode( ',', $this->discounts );
803
+                        if (!is_array($this->discounts)) {
804
+                            $this->discounts = explode(',', $this->discounts);
805 805
                         }
806 806
 
807
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
807
+                        $this->user_info['discount'] = implode(',', $this->discounts);
808 808
                         break;
809 809
                         
810 810
                     //case 'tax':
811 811
                         //$this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
812 812
                         //break;
813 813
                     case 'discount':
814
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
814
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
815 815
                         break;
816 816
                     case 'discount_code':
817
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
817
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
818 818
                         break;
819 819
                     //case 'fees':
820 820
                         //$this->update_meta( '_wpinv_fees', $this->fees );
@@ -824,19 +824,19 @@  discard block
 block discarded – undo
824 824
                             'ID'          => $this->ID,
825 825
                             'post_parent' => $this->parent_invoice,
826 826
                         );
827
-                        wp_update_post( $args );
827
+                        wp_update_post($args);
828 828
                         break;
829 829
                     default:
830
-                        do_action( 'wpinv_save', $this, $key );
830
+                        do_action('wpinv_save', $this, $key);
831 831
                         break;
832 832
                 }
833 833
             }       
834 834
 
835
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
836
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
837
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
835
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
836
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
837
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
838 838
             
839
-            $this->items    = array_values( $this->items );
839
+            $this->items = array_values($this->items);
840 840
             
841 841
             $new_meta = array(
842 842
                 'items'         => $this->items,
@@ -847,12 +847,12 @@  discard block
 block discarded – undo
847 847
             );
848 848
             
849 849
             $meta        = $this->get_meta();
850
-            $merged_meta = array_merge( $meta, $new_meta );
850
+            $merged_meta = array_merge($meta, $new_meta);
851 851
 
852 852
             // Only save the payment meta if it's changed
853
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
854
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
855
-                if ( false !== $updated ) {
853
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
854
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
855
+                if (false !== $updated) {
856 856
                     $saved = true;
857 857
                 }
858 858
             }
@@ -860,15 +860,15 @@  discard block
 block discarded – undo
860 860
             $this->pending = array();
861 861
             $saved         = true;
862 862
         } else {
863
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
864
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
865
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
863
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
864
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
865
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
866 866
         }
867 867
         
868
-        do_action( 'wpinv_invoice_save', $this, $saved );
868
+        do_action('wpinv_invoice_save', $this, $saved);
869 869
 
870
-        if ( true === $saved || $setup ) {
871
-            $this->setup_invoice( $this->ID );
870
+        if (true === $saved || $setup) {
871
+            $this->setup_invoice($this->ID);
872 872
         }
873 873
         
874 874
         $this->refresh_item_ids();
@@ -876,7 +876,7 @@  discard block
 block discarded – undo
876 876
         return $saved;
877 877
     }
878 878
     
879
-    public function add_fee( $args, $global = true ) {
879
+    public function add_fee($args, $global = true) {
880 880
         $default_args = array(
881 881
             'label'       => '',
882 882
             'amount'      => 0,
@@ -886,75 +886,75 @@  discard block
 block discarded – undo
886 886
             'item_id'     => 0,
887 887
         );
888 888
 
889
-        $fee = wp_parse_args( $args, $default_args );
889
+        $fee = wp_parse_args($args, $default_args);
890 890
         
891
-        if ( !empty( $fee['label'] ) ) {
891
+        if (!empty($fee['label'])) {
892 892
             return false;
893 893
         }
894 894
         
895
-        $fee['id']  = sanitize_title( $fee['label'] );
895
+        $fee['id'] = sanitize_title($fee['label']);
896 896
         
897
-        $this->fees[]               = $fee;
897
+        $this->fees[] = $fee;
898 898
         
899 899
         $added_fee               = $fee;
900 900
         $added_fee['action']     = 'add';
901 901
         $this->pending['fees'][] = $added_fee;
902
-        reset( $this->fees );
902
+        reset($this->fees);
903 903
 
904
-        $this->increase_fees( $fee['amount'] );
904
+        $this->increase_fees($fee['amount']);
905 905
         return true;
906 906
     }
907 907
 
908
-    public function remove_fee( $key ) {
908
+    public function remove_fee($key) {
909 909
         $removed = false;
910 910
 
911
-        if ( is_numeric( $key ) ) {
912
-            $removed = $this->remove_fee_by( 'index', $key );
911
+        if (is_numeric($key)) {
912
+            $removed = $this->remove_fee_by('index', $key);
913 913
         }
914 914
 
915 915
         return $removed;
916 916
     }
917 917
 
918
-    public function remove_fee_by( $key, $value, $global = false ) {
919
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
918
+    public function remove_fee_by($key, $value, $global = false) {
919
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
920 920
             'index', 'label', 'amount', 'type',
921
-        ) );
921
+        ));
922 922
 
923
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
923
+        if (!in_array($key, $allowed_fee_keys)) {
924 924
             return false;
925 925
         }
926 926
 
927 927
         $removed = false;
928
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
929
-            $removed_fee             = $this->fees[ $value ];
928
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
929
+            $removed_fee             = $this->fees[$value];
930 930
             $removed_fee['action']   = 'remove';
931 931
             $this->pending['fees'][] = $removed_fee;
932 932
 
933
-            $this->decrease_fees( $removed_fee['amount'] );
933
+            $this->decrease_fees($removed_fee['amount']);
934 934
 
935
-            unset( $this->fees[ $value ] );
935
+            unset($this->fees[$value]);
936 936
             $removed = true;
937
-        } else if ( 'index' !== $key ) {
938
-            foreach ( $this->fees as $index => $fee ) {
939
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
937
+        } else if ('index' !== $key) {
938
+            foreach ($this->fees as $index => $fee) {
939
+                if (isset($fee[$key]) && $fee[$key] == $value) {
940 940
                     $removed_fee             = $fee;
941 941
                     $removed_fee['action']   = 'remove';
942 942
                     $this->pending['fees'][] = $removed_fee;
943 943
 
944
-                    $this->decrease_fees( $removed_fee['amount'] );
944
+                    $this->decrease_fees($removed_fee['amount']);
945 945
 
946
-                    unset( $this->fees[ $index ] );
946
+                    unset($this->fees[$index]);
947 947
                     $removed = true;
948 948
 
949
-                    if ( false === $global ) {
949
+                    if (false === $global) {
950 950
                         break;
951 951
                     }
952 952
                 }
953 953
             }
954 954
         }
955 955
 
956
-        if ( true === $removed ) {
957
-            $this->fees = array_values( $this->fees );
956
+        if (true === $removed) {
957
+            $this->fees = array_values($this->fees);
958 958
         }
959 959
 
960 960
         return $removed;
@@ -962,35 +962,35 @@  discard block
 block discarded – undo
962 962
 
963 963
     
964 964
 
965
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
965
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
966 966
         // Bail if no note specified
967
-        if( !$note ) {
967
+        if (!$note) {
968 968
             return false;
969 969
         }
970 970
 
971
-        if ( empty( $this->ID ) )
971
+        if (empty($this->ID))
972 972
             return false;
973 973
         
974
-        if ( ( ( is_user_logged_in() && current_user_can( 'manage_options' ) ) || $added_by_user ) && !$system ) {
975
-            $user                 = get_user_by( 'id', get_current_user_id() );
974
+        if (((is_user_logged_in() && current_user_can('manage_options')) || $added_by_user) && !$system) {
975
+            $user                 = get_user_by('id', get_current_user_id());
976 976
             $comment_author       = $user->display_name;
977 977
             $comment_author_email = $user->user_email;
978 978
         } else {
979
-            $comment_author       = __( 'System', 'invoicing' );
980
-            $comment_author_email = strtolower( __( 'System', 'invoicing' ) ) . '@';
981
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
982
-            $comment_author_email = sanitize_email( $comment_author_email );
979
+            $comment_author       = __('System', 'invoicing');
980
+            $comment_author_email = strtolower(__('System', 'invoicing')) . '@';
981
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
982
+            $comment_author_email = sanitize_email($comment_author_email);
983 983
         }
984 984
 
985
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
985
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
986 986
 
987
-        $note_id = wp_insert_comment( wp_filter_comment( array(
987
+        $note_id = wp_insert_comment(wp_filter_comment(array(
988 988
             'comment_post_ID'      => $this->ID,
989 989
             'comment_content'      => $note,
990 990
             'comment_agent'        => 'GeoDirectory',
991 991
             'user_id'              => is_admin() ? get_current_user_id() : 0,
992
-            'comment_date'         => current_time( 'mysql' ),
993
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
992
+            'comment_date'         => current_time('mysql'),
993
+            'comment_date_gmt'     => current_time('mysql', 1),
994 994
             'comment_approved'     => 1,
995 995
             'comment_parent'       => 0,
996 996
             'comment_author'       => $comment_author,
@@ -998,53 +998,53 @@  discard block
 block discarded – undo
998 998
             'comment_author_url'   => '',
999 999
             'comment_author_email' => $comment_author_email,
1000 1000
             'comment_type'         => 'wpinv_note'
1001
-        ) ) );
1001
+        )));
1002 1002
 
1003
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1003
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1004 1004
         
1005
-        if ( $customer_type ) {
1006
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1005
+        if ($customer_type) {
1006
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1007 1007
 
1008
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1008
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1009 1009
         }
1010 1010
 
1011 1011
         return $note_id;
1012 1012
     }
1013 1013
 
1014
-    private function increase_subtotal( $amount = 0.00 ) {
1015
-        $amount          = (float) $amount;
1014
+    private function increase_subtotal($amount = 0.00) {
1015
+        $amount          = (float)$amount;
1016 1016
         $this->subtotal += $amount;
1017
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1017
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1018 1018
 
1019 1019
         $this->recalculate_total();
1020 1020
     }
1021 1021
 
1022
-    private function decrease_subtotal( $amount = 0.00 ) {
1023
-        $amount          = (float) $amount;
1022
+    private function decrease_subtotal($amount = 0.00) {
1023
+        $amount          = (float)$amount;
1024 1024
         $this->subtotal -= $amount;
1025
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1025
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1026 1026
 
1027
-        if ( $this->subtotal < 0 ) {
1027
+        if ($this->subtotal < 0) {
1028 1028
             $this->subtotal = 0;
1029 1029
         }
1030 1030
 
1031 1031
         $this->recalculate_total();
1032 1032
     }
1033 1033
 
1034
-    private function increase_fees( $amount = 0.00 ) {
1034
+    private function increase_fees($amount = 0.00) {
1035 1035
         $amount            = (float)$amount;
1036 1036
         $this->fees_total += $amount;
1037
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1037
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1038 1038
 
1039 1039
         $this->recalculate_total();
1040 1040
     }
1041 1041
 
1042
-    private function decrease_fees( $amount = 0.00 ) {
1043
-        $amount            = (float) $amount;
1042
+    private function decrease_fees($amount = 0.00) {
1043
+        $amount            = (float)$amount;
1044 1044
         $this->fees_total -= $amount;
1045
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1045
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1046 1046
 
1047
-        if ( $this->fees_total < 0 ) {
1047
+        if ($this->fees_total < 0) {
1048 1048
             $this->fees_total = 0;
1049 1049
         }
1050 1050
 
@@ -1055,54 +1055,54 @@  discard block
 block discarded – undo
1055 1055
         global $wpi_nosave;
1056 1056
         
1057 1057
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1058
-        $this->total = wpinv_round_amount( $this->total );
1058
+        $this->total = wpinv_round_amount($this->total);
1059 1059
         
1060
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1060
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1061 1061
     }
1062 1062
     
1063
-    public function increase_tax( $amount = 0.00 ) {
1064
-        $amount       = (float) $amount;
1063
+    public function increase_tax($amount = 0.00) {
1064
+        $amount       = (float)$amount;
1065 1065
         $this->tax   += $amount;
1066 1066
 
1067 1067
         $this->recalculate_total();
1068 1068
     }
1069 1069
 
1070
-    public function decrease_tax( $amount = 0.00 ) {
1071
-        $amount     = (float) $amount;
1070
+    public function decrease_tax($amount = 0.00) {
1071
+        $amount     = (float)$amount;
1072 1072
         $this->tax -= $amount;
1073 1073
 
1074
-        if ( $this->tax < 0 ) {
1074
+        if ($this->tax < 0) {
1075 1075
             $this->tax = 0;
1076 1076
         }
1077 1077
 
1078 1078
         $this->recalculate_total();
1079 1079
     }
1080 1080
 
1081
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1082
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1081
+    public function update_status($new_status = false, $note = '', $manual = false) {
1082
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1083 1083
         
1084
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses() ) ) ) {
1084
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses()))) {
1085 1085
             return false; // Don't permit status changes that aren't changes
1086 1086
         }
1087 1087
 
1088
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1088
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1089 1089
         $updated = false;
1090 1090
 
1091
-        if ( $do_change ) {
1092
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1091
+        if ($do_change) {
1092
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1093 1093
 
1094 1094
             $update_post_data                   = array();
1095 1095
             $update_post_data['ID']             = $this->ID;
1096 1096
             $update_post_data['post_status']    = $new_status;
1097
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1098
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1097
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1098
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1099 1099
             
1100
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1100
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1101 1101
 
1102
-            $updated = wp_update_post( $update_post_data );     
1102
+            $updated = wp_update_post($update_post_data);     
1103 1103
            
1104 1104
             // Process any specific status functions
1105
-            switch( $new_status ) {
1105
+            switch ($new_status) {
1106 1106
                 case 'wpi-refunded':
1107 1107
                     $this->process_refund();
1108 1108
                     break;
@@ -1115,9 +1115,9 @@  discard block
 block discarded – undo
1115 1115
             }
1116 1116
             
1117 1117
             // Status was changed.
1118
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1119
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1120
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1118
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1119
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1120
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1121 1121
         }
1122 1122
 
1123 1123
         return $updated;
@@ -1131,72 +1131,72 @@  discard block
 block discarded – undo
1131 1131
         $this->save();
1132 1132
     }
1133 1133
 
1134
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1135
-        if ( empty( $meta_key ) ) {
1134
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1135
+        if (empty($meta_key)) {
1136 1136
             return false;
1137 1137
         }
1138 1138
 
1139
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1139
+        if ($meta_key == 'key' || $meta_key == 'date') {
1140 1140
             $current_meta = $this->get_meta();
1141
-            $current_meta[ $meta_key ] = $meta_value;
1141
+            $current_meta[$meta_key] = $meta_value;
1142 1142
 
1143 1143
             $meta_key     = '_wpinv_payment_meta';
1144 1144
             $meta_value   = $current_meta;
1145 1145
         }
1146 1146
 
1147
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1147
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1148 1148
         
1149
-        if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
1149
+        if ($meta_key == '_wpinv_completed_date' && !empty($meta_value)) {
1150 1150
             $args = array(
1151 1151
                 'ID'                => $this->ID,
1152 1152
                 'post_date'         => $meta_value,
1153 1153
                 'edit_date'         => true,
1154
-                'post_date_gmt'     => get_gmt_from_date( $meta_value ),
1154
+                'post_date_gmt'     => get_gmt_from_date($meta_value),
1155 1155
                 'post_modified'     => $meta_value,
1156
-                'post_modified_gmt' => get_gmt_from_date( $meta_value )
1156
+                'post_modified_gmt' => get_gmt_from_date($meta_value)
1157 1157
             );
1158
-            wp_update_post( $args );
1158
+            wp_update_post($args);
1159 1159
         }
1160 1160
         
1161
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1161
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1162 1162
     }
1163 1163
 
1164 1164
     private function process_refund() {
1165 1165
         $process_refund = true;
1166 1166
 
1167 1167
         // If the payment was not in publish, don't decrement stats as they were never incremented
1168
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1168
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1169 1169
             $process_refund = false;
1170 1170
         }
1171 1171
 
1172 1172
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1173
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1173
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1174 1174
 
1175
-        if ( false === $process_refund ) {
1175
+        if (false === $process_refund) {
1176 1176
             return;
1177 1177
         }
1178 1178
 
1179
-        do_action( 'wpinv_pre_refund_invoice', $this );
1179
+        do_action('wpinv_pre_refund_invoice', $this);
1180 1180
         
1181
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1182
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1183
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1181
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1182
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1183
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1184 1184
         
1185
-        do_action( 'wpinv_post_refund_invoice', $this );
1185
+        do_action('wpinv_post_refund_invoice', $this);
1186 1186
     }
1187 1187
 
1188 1188
     private function process_failure() {
1189 1189
         $discounts = $this->discounts;
1190
-        if ( empty( $discounts ) ) {
1190
+        if (empty($discounts)) {
1191 1191
             return;
1192 1192
         }
1193 1193
 
1194
-        if ( ! is_array( $discounts ) ) {
1195
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1194
+        if (!is_array($discounts)) {
1195
+            $discounts = array_map('trim', explode(',', $discounts));
1196 1196
         }
1197 1197
 
1198
-        foreach ( $discounts as $discount ) {
1199
-            wpinv_decrease_discount_usage( $discount );
1198
+        foreach ($discounts as $discount) {
1199
+            wpinv_decrease_discount_usage($discount);
1200 1200
         }
1201 1201
     }
1202 1202
     
@@ -1204,92 +1204,92 @@  discard block
 block discarded – undo
1204 1204
         $process_pending = true;
1205 1205
 
1206 1206
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1207
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'pending' != $this->status ) {
1207
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'pending' != $this->status) {
1208 1208
             $process_pending = false;
1209 1209
         }
1210 1210
 
1211 1211
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1212
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1212
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1213 1213
 
1214
-        if ( false === $process_pending ) {
1214
+        if (false === $process_pending) {
1215 1215
             return;
1216 1216
         }
1217 1217
 
1218
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1219
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1220
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1218
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1219
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1220
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1221 1221
 
1222 1222
         $this->completed_date = '';
1223
-        $this->update_meta( '_wpinv_completed_date', '' );
1223
+        $this->update_meta('_wpinv_completed_date', '');
1224 1224
     }
1225 1225
     
1226 1226
     // get data
1227
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1228
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1227
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1228
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1229 1229
 
1230
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1230
+        if ($meta_key === '_wpinv_payment_meta') {
1231 1231
 
1232
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1232
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1233 1233
 
1234
-            if ( empty( $meta['key'] ) ) {
1234
+            if (empty($meta['key'])) {
1235 1235
                 $meta['key'] = $this->setup_invoice_key();
1236 1236
             }
1237 1237
 
1238
-            if ( empty( $meta['date'] ) ) {
1239
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1238
+            if (empty($meta['date'])) {
1239
+                $meta['date'] = get_post_field('post_date', $this->ID);
1240 1240
             }
1241 1241
         }
1242 1242
 
1243
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1243
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1244 1244
 
1245
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1245
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1246 1246
     }
1247 1247
     
1248 1248
     public function get_description() {
1249
-        $post = get_post( $this->ID );
1249
+        $post = get_post($this->ID);
1250 1250
         
1251
-        $description = !empty( $post ) ? $post->post_content : '';
1252
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1251
+        $description = !empty($post) ? $post->post_content : '';
1252
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1253 1253
     }
1254 1254
     
1255
-    public function get_status( $nicename = false ) {
1256
-        if ( !$nicename ) {
1255
+    public function get_status($nicename = false) {
1256
+        if (!$nicename) {
1257 1257
             $status = $this->status;
1258 1258
         } else {
1259 1259
             $status = $this->status_nicename;
1260 1260
         }
1261 1261
         
1262
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1262
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1263 1263
     }
1264 1264
     
1265 1265
     public function get_cart_details() {
1266
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1266
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1267 1267
     }
1268 1268
     
1269
-    public function get_subtotal( $currency = false ) {
1270
-        $subtotal = wpinv_round_amount( $this->subtotal );
1269
+    public function get_subtotal($currency = false) {
1270
+        $subtotal = wpinv_round_amount($this->subtotal);
1271 1271
         
1272
-        if ( $currency ) {
1273
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1272
+        if ($currency) {
1273
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1274 1274
         }
1275 1275
         
1276
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1276
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1277 1277
     }
1278 1278
     
1279
-    public function get_total( $currency = false ) {        
1280
-        if ( $this->is_free_trial() ) {
1281
-            $total = wpinv_round_amount( 0 );
1279
+    public function get_total($currency = false) {        
1280
+        if ($this->is_free_trial()) {
1281
+            $total = wpinv_round_amount(0);
1282 1282
         } else {
1283
-            $total = wpinv_round_amount( $this->total );
1283
+            $total = wpinv_round_amount($this->total);
1284 1284
         }
1285
-        if ( $currency ) {
1286
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1285
+        if ($currency) {
1286
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1287 1287
         }
1288 1288
         
1289
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1289
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1290 1290
     }
1291 1291
     
1292
-    public function get_recurring_details( $field = '', $currency = false ) {        
1292
+    public function get_recurring_details($field = '', $currency = false) {        
1293 1293
         $data                 = array();
1294 1294
         $data['cart_details'] = $this->cart_details;
1295 1295
         $data['subtotal']     = $this->get_subtotal();
@@ -1297,45 +1297,45 @@  discard block
 block discarded – undo
1297 1297
         $data['tax']          = $this->get_tax();
1298 1298
         $data['total']        = $this->get_total();
1299 1299
     
1300
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1300
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1301 1301
             $is_free_trial = $this->is_free_trial();
1302
-            $discounts = $this->get_discounts( true );
1302
+            $discounts = $this->get_discounts(true);
1303 1303
             
1304
-            if ( $is_free_trial || !empty( $discounts ) ) {
1304
+            if ($is_free_trial || !empty($discounts)) {
1305 1305
                 $first_use_only = false;
1306 1306
                 
1307
-                if ( !empty( $discounts ) ) {
1308
-                    foreach ( $discounts as $key => $code ) {
1309
-                        if ( wpinv_discount_is_recurring( $code, true ) ) {
1307
+                if (!empty($discounts)) {
1308
+                    foreach ($discounts as $key => $code) {
1309
+                        if (wpinv_discount_is_recurring($code, true)) {
1310 1310
                             $first_use_only = true;
1311 1311
                             break;
1312 1312
                         }
1313 1313
                     }
1314 1314
                 }
1315 1315
                     
1316
-                if ( !$first_use_only ) {
1317
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1318
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1319
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1320
-                    $data['total']    = wpinv_round_amount( $this->total );
1316
+                if (!$first_use_only) {
1317
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1318
+                    $data['discount'] = wpinv_round_amount($this->discount);
1319
+                    $data['tax']      = wpinv_round_amount($this->tax);
1320
+                    $data['total']    = wpinv_round_amount($this->total);
1321 1321
                 } else {
1322 1322
                     $cart_subtotal   = 0;
1323 1323
                     $cart_discount   = 0;
1324 1324
                     $cart_tax        = 0;
1325 1325
 
1326
-                    foreach ( $this->cart_details as $key => $item ) {
1327
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1328
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1326
+                    foreach ($this->cart_details as $key => $item) {
1327
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1328
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1329 1329
                         $item_discount  = 0;
1330
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1330
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float)$item['vat_rate']) : 0;
1331 1331
                         
1332
-                        if ( wpinv_prices_include_tax() ) {
1333
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1332
+                        if (wpinv_prices_include_tax()) {
1333
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1334 1334
                         }
1335 1335
                         
1336 1336
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1337 1337
                         // Do not allow totals to go negative
1338
-                        if ( $item_total < 0 ) {
1338
+                        if ($item_total < 0) {
1339 1339
                             $item_total = 0;
1340 1340
                         }
1341 1341
                         
@@ -1343,113 +1343,113 @@  discard block
 block discarded – undo
1343 1343
                         $cart_discount  += (float)($item_discount);
1344 1344
                         $cart_tax       += (float)($item_tax);
1345 1345
                         
1346
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1347
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1348
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1346
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1347
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1348
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1349 1349
                     }
1350 1350
                     
1351
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1352
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1353
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1354
-                    $data['total']    = wpinv_round_amount( $data['subtotal'] + $data['tax'] );
1351
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1352
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1353
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1354
+                    $data['total']    = wpinv_round_amount($data['subtotal'] + $data['tax']);
1355 1355
                 }
1356 1356
             }
1357 1357
         }
1358 1358
         
1359
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1359
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1360 1360
 
1361
-        if ( isset( $data[$field] ) ) {
1362
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1361
+        if (isset($data[$field])) {
1362
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1363 1363
         }
1364 1364
         
1365 1365
         return $data;
1366 1366
     }
1367 1367
     
1368
-    public function get_final_tax( $currency = false ) {        
1369
-        $final_total = wpinv_round_amount( $this->tax );
1370
-        if ( $currency ) {
1371
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1368
+    public function get_final_tax($currency = false) {        
1369
+        $final_total = wpinv_round_amount($this->tax);
1370
+        if ($currency) {
1371
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1372 1372
         }
1373 1373
         
1374
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1374
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1375 1375
     }
1376 1376
     
1377
-    public function get_discounts( $array = false ) {
1377
+    public function get_discounts($array = false) {
1378 1378
         $discounts = $this->discounts;
1379
-        if ( $array && $discounts ) {
1380
-            $discounts = explode( ',', $discounts );
1379
+        if ($array && $discounts) {
1380
+            $discounts = explode(',', $discounts);
1381 1381
         }
1382
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1382
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1383 1383
     }
1384 1384
     
1385
-    public function get_discount( $currency = false, $dash = false ) {
1386
-        if ( !empty( $this->discounts ) ) {
1385
+    public function get_discount($currency = false, $dash = false) {
1386
+        if (!empty($this->discounts)) {
1387 1387
             global $ajax_cart_details;
1388 1388
             $ajax_cart_details = $this->get_cart_details();
1389 1389
             
1390
-            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) {
1390
+            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) {
1391 1391
                 $cart_items = $ajax_cart_details;
1392 1392
             } else {
1393 1393
                 $cart_items = $this->items;
1394 1394
             }
1395 1395
 
1396
-            $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );
1396
+            $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);
1397 1397
         }
1398
-        $discount   = wpinv_round_amount( $this->discount );
1398
+        $discount   = wpinv_round_amount($this->discount);
1399 1399
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1400 1400
         
1401
-        if ( $currency ) {
1402
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1401
+        if ($currency) {
1402
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1403 1403
         }
1404 1404
         
1405
-        $discount   = $dash . $discount;
1405
+        $discount = $dash . $discount;
1406 1406
         
1407
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1407
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1408 1408
     }
1409 1409
     
1410 1410
     public function get_discount_code() {
1411 1411
         return $this->discount_code;
1412 1412
     }
1413 1413
     
1414
-    public function get_tax( $currency = false ) {
1415
-        $tax = wpinv_round_amount( $this->tax );
1414
+    public function get_tax($currency = false) {
1415
+        $tax = wpinv_round_amount($this->tax);
1416 1416
         
1417
-        if ( $currency ) {
1418
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1417
+        if ($currency) {
1418
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1419 1419
         }
1420 1420
         
1421
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1421
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1422 1422
     }
1423 1423
     
1424
-    public function get_fees( $type = 'all' ) {
1425
-        $fees    = array();
1424
+    public function get_fees($type = 'all') {
1425
+        $fees = array();
1426 1426
 
1427
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1428
-            foreach ( $this->fees as $fee ) {
1429
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1427
+        if (!empty($this->fees) && is_array($this->fees)) {
1428
+            foreach ($this->fees as $fee) {
1429
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1430 1430
                     continue;
1431 1431
                 }
1432 1432
 
1433
-                $fee['label'] = stripslashes( $fee['label'] );
1434
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1435
-                $fees[]    = $fee;
1433
+                $fee['label'] = stripslashes($fee['label']);
1434
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1435
+                $fees[] = $fee;
1436 1436
             }
1437 1437
         }
1438 1438
 
1439
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1439
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1440 1440
     }
1441 1441
     
1442
-    public function get_fees_total( $type = 'all' ) {
1443
-        $fees_total = (float) 0.00;
1442
+    public function get_fees_total($type = 'all') {
1443
+        $fees_total = (float)0.00;
1444 1444
 
1445
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1446
-        if ( ! empty( $payment_fees ) ) {
1447
-            foreach ( $payment_fees as $fee ) {
1448
-                $fees_total += (float) $fee['amount'];
1445
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1446
+        if (!empty($payment_fees)) {
1447
+            foreach ($payment_fees as $fee) {
1448
+                $fees_total += (float)$fee['amount'];
1449 1449
             }
1450 1450
         }
1451 1451
 
1452
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1452
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1453 1453
         /*
1454 1454
         $fees = $this->get_fees( $type );
1455 1455
 
@@ -1469,116 +1469,116 @@  discard block
 block discarded – undo
1469 1469
     }
1470 1470
 
1471 1471
     public function get_user_id() {
1472
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1472
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1473 1473
     }
1474 1474
     
1475 1475
     public function get_first_name() {
1476
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1476
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1477 1477
     }
1478 1478
     
1479 1479
     public function get_last_name() {
1480
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1480
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1481 1481
     }
1482 1482
     
1483 1483
     public function get_user_full_name() {
1484
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1484
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1485 1485
     }
1486 1486
     
1487 1487
     public function get_user_info() {
1488
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1488
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1489 1489
     }
1490 1490
     
1491 1491
     public function get_email() {
1492
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1492
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1493 1493
     }
1494 1494
     
1495 1495
     public function get_address() {
1496
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1496
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1497 1497
     }
1498 1498
     
1499 1499
     public function get_phone() {
1500
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1500
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1501 1501
     }
1502 1502
     
1503 1503
     public function get_number() {
1504
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1504
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1505 1505
     }
1506 1506
     
1507 1507
     public function get_items() {
1508
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1508
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1509 1509
     }
1510 1510
     
1511 1511
     public function get_key() {
1512
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1512
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1513 1513
     }
1514 1514
     
1515 1515
     public function get_transaction_id() {
1516
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1516
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1517 1517
     }
1518 1518
     
1519 1519
     public function get_gateway() {
1520
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1520
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1521 1521
     }
1522 1522
     
1523 1523
     public function get_gateway_title() {
1524
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1524
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1525 1525
         
1526
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1526
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1527 1527
     }
1528 1528
     
1529 1529
     public function get_currency() {
1530
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1530
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1531 1531
     }
1532 1532
     
1533 1533
     public function get_created_date() {
1534
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1534
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1535 1535
     }
1536 1536
     
1537
-    public function get_due_date( $display = false ) {
1538
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1537
+    public function get_due_date($display = false) {
1538
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1539 1539
         
1540
-        if ( !$display || empty( $due_date ) ) {
1540
+        if (!$display || empty($due_date)) {
1541 1541
             return $due_date;
1542 1542
         }
1543 1543
         
1544
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1544
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1545 1545
     }
1546 1546
     
1547 1547
     public function get_completed_date() {
1548
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1548
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1549 1549
     }
1550 1550
     
1551
-    public function get_invoice_date( $formatted = true ) {
1551
+    public function get_invoice_date($formatted = true) {
1552 1552
         $date_completed = $this->completed_date;
1553 1553
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1554 1554
         
1555
-        if ( $invoice_date == '' ) {
1555
+        if ($invoice_date == '') {
1556 1556
             $date_created   = $this->date;
1557 1557
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1558 1558
         }
1559 1559
         
1560
-        if ( $formatted && $invoice_date ) {
1561
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1560
+        if ($formatted && $invoice_date) {
1561
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1562 1562
         }
1563 1563
 
1564
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1564
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1565 1565
     }
1566 1566
     
1567 1567
     public function get_ip() {
1568
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1568
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1569 1569
     }
1570 1570
         
1571
-    public function has_status( $status ) {
1572
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1571
+    public function has_status($status) {
1572
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1573 1573
     }
1574 1574
     
1575
-    public function add_item( $item_id = 0, $args = array() ) {
1575
+    public function add_item($item_id = 0, $args = array()) {
1576 1576
         global $wpi_current_id, $wpi_item_id;
1577 1577
         
1578
-        $item = new WPInv_Item( $item_id );
1578
+        $item = new WPInv_Item($item_id);
1579 1579
 
1580 1580
         // Bail if this post isn't a item
1581
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1581
+        if (!$item || $item->post_type !== 'wpi_item') {
1582 1582
             return false;
1583 1583
         }
1584 1584
         
@@ -1597,8 +1597,8 @@  discard block
 block discarded – undo
1597 1597
             'fees'          => array()
1598 1598
         );
1599 1599
 
1600
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1601
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1600
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1601
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1602 1602
 
1603 1603
         $wpi_current_id         = $this->ID;
1604 1604
         $wpi_item_id            = $item->ID;
@@ -1610,19 +1610,19 @@  discard block
 block discarded – undo
1610 1610
         $found_cart_key         = false;
1611 1611
         
1612 1612
         if ($has_quantities) {
1613
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1613
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1614 1614
             
1615
-            foreach ( $this->items as $key => $cart_item ) {
1616
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1615
+            foreach ($this->items as $key => $cart_item) {
1616
+                if ((int)$item_id !== (int)$cart_item['id']) {
1617 1617
                     continue;
1618 1618
                 }
1619 1619
 
1620
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1620
+                $this->items[$key]['quantity'] += $args['quantity'];
1621 1621
                 break;
1622 1622
             }
1623 1623
             
1624
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1625
-                if ( $item_id != $cart_item['id'] ) {
1624
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1625
+                if ($item_id != $cart_item['id']) {
1626 1626
                     continue;
1627 1627
                 }
1628 1628
 
@@ -1634,29 +1634,29 @@  discard block
 block discarded – undo
1634 1634
         if ($has_quantities && $found_cart_key !== false) {
1635 1635
             $cart_item          = $this->cart_details[$found_cart_key];
1636 1636
             $item_price         = $cart_item['item_price'];
1637
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1638
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1637
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1638
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1639 1639
             
1640 1640
             $new_quantity       = $quantity + $args['quantity'];
1641 1641
             $subtotal           = $item_price * $new_quantity;
1642 1642
             
1643 1643
             $args['quantity']   = $new_quantity;
1644
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1645
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1644
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1645
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1646 1646
             
1647 1647
             $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1648 1648
             $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1649 1649
             // The total increase equals the number removed * the item_price
1650
-            $total_increased    = wpinv_round_amount( $item_price );
1650
+            $total_increased    = wpinv_round_amount($item_price);
1651 1651
             
1652
-            if ( wpinv_prices_include_tax() ) {
1653
-                $subtotal -= wpinv_round_amount( $tax );
1652
+            if (wpinv_prices_include_tax()) {
1653
+                $subtotal -= wpinv_round_amount($tax);
1654 1654
             }
1655 1655
 
1656
-            $total              = $subtotal - $discount + $tax;
1656
+            $total = $subtotal - $discount + $tax;
1657 1657
 
1658 1658
             // Do not allow totals to go negative
1659
-            if( $total < 0 ) {
1659
+            if ($total < 0) {
1660 1660
                 $total = 0;
1661 1661
             }
1662 1662
             
@@ -1672,25 +1672,25 @@  discard block
 block discarded – undo
1672 1672
             $this->cart_details[$found_cart_key] = $cart_item;
1673 1673
         } else {
1674 1674
             // Set custom price.
1675
-            if ( $args['custom_price'] !== '' ) {
1675
+            if ($args['custom_price'] !== '') {
1676 1676
                 $item_price = $args['custom_price'];
1677 1677
             } else {
1678 1678
                 // Allow overriding the price
1679
-                if ( false !== $args['item_price'] ) {
1679
+                if (false !== $args['item_price']) {
1680 1680
                     $item_price = $args['item_price'];
1681 1681
                 } else {
1682
-                    $item_price = wpinv_get_item_price( $item->ID );
1682
+                    $item_price = wpinv_get_item_price($item->ID);
1683 1683
                 }
1684 1684
             }
1685 1685
 
1686 1686
             // Sanitizing the price here so we don't have a dozen calls later
1687
-            $item_price = wpinv_sanitize_amount( $item_price );
1688
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1687
+            $item_price = wpinv_sanitize_amount($item_price);
1688
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1689 1689
         
1690
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1691
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1692
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1693
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1690
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1691
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1692
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1693
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1694 1694
 
1695 1695
             // Setup the items meta item
1696 1696
             $new_item = array(
@@ -1698,29 +1698,29 @@  discard block
 block discarded – undo
1698 1698
                 'quantity' => $args['quantity'],
1699 1699
             );
1700 1700
 
1701
-            $this->items[]  = $new_item;
1701
+            $this->items[] = $new_item;
1702 1702
 
1703
-            if ( wpinv_prices_include_tax() ) {
1704
-                $subtotal -= wpinv_round_amount( $tax );
1703
+            if (wpinv_prices_include_tax()) {
1704
+                $subtotal -= wpinv_round_amount($tax);
1705 1705
             }
1706 1706
 
1707
-            $total      = $subtotal - $discount + $tax;
1707
+            $total = $subtotal - $discount + $tax;
1708 1708
 
1709 1709
             // Do not allow totals to go negative
1710
-            if( $total < 0 ) {
1710
+            if ($total < 0) {
1711 1711
                 $total = 0;
1712 1712
             }
1713 1713
         
1714 1714
             $this->cart_details[] = array(
1715 1715
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1716 1716
                 'id'            => $item->ID,
1717
-                'item_price'    => wpinv_round_amount( $item_price ),
1718
-                'custom_price'  => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),
1717
+                'item_price'    => wpinv_round_amount($item_price),
1718
+                'custom_price'  => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),
1719 1719
                 'quantity'      => $args['quantity'],
1720 1720
                 'discount'      => $discount,
1721
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1722
-                'tax'           => wpinv_round_amount( $tax ),
1723
-                'price'         => wpinv_round_amount( $total ),
1721
+                'subtotal'      => wpinv_round_amount($subtotal),
1722
+                'tax'           => wpinv_round_amount($tax),
1723
+                'price'         => wpinv_round_amount($total),
1724 1724
                 'vat_rate'      => $tax_rate,
1725 1725
                 'vat_class'     => $tax_class,
1726 1726
                 'meta'          => $args['meta'],
@@ -1730,18 +1730,18 @@  discard block
 block discarded – undo
1730 1730
             $subtotal = $subtotal - $discount;
1731 1731
         }
1732 1732
         
1733
-        $added_item = end( $this->cart_details );
1734
-        $added_item['action']  = 'add';
1733
+        $added_item = end($this->cart_details);
1734
+        $added_item['action'] = 'add';
1735 1735
         
1736 1736
         $this->pending['items'][] = $added_item;
1737 1737
         
1738
-        $this->increase_subtotal( $subtotal );
1739
-        $this->increase_tax( $tax );
1738
+        $this->increase_subtotal($subtotal);
1739
+        $this->increase_tax($tax);
1740 1740
 
1741 1741
         return true;
1742 1742
     }
1743 1743
     
1744
-    public function remove_item( $item_id, $args = array() ) {
1744
+    public function remove_item($item_id, $args = array()) {
1745 1745
         // Set some defaults
1746 1746
         $defaults = array(
1747 1747
             'quantity'      => 1,
@@ -1749,51 +1749,51 @@  discard block
 block discarded – undo
1749 1749
             'custom_price'  => '',
1750 1750
             'cart_index'    => false,
1751 1751
         );
1752
-        $args = wp_parse_args( $args, $defaults );
1752
+        $args = wp_parse_args($args, $defaults);
1753 1753
 
1754 1754
         // Bail if this post isn't a item
1755
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1755
+        if (get_post_type($item_id) !== 'wpi_item') {
1756 1756
             return false;
1757 1757
         }
1758 1758
         
1759
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1759
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1760 1760
 
1761
-        foreach ( $this->items as $key => $item ) {
1762
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1761
+        foreach ($this->items as $key => $item) {
1762
+            if (!empty($item['id']) && (int)$item_id !== (int)$item['id']) {
1763 1763
                 continue;
1764 1764
             }
1765 1765
 
1766
-            if ( false !== $args['cart_index'] ) {
1767
-                $cart_index = absint( $args['cart_index'] );
1768
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1766
+            if (false !== $args['cart_index']) {
1767
+                $cart_index = absint($args['cart_index']);
1768
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1769 1769
 
1770
-                if ( ! empty( $cart_item ) ) {
1770
+                if (!empty($cart_item)) {
1771 1771
                     // If the cart index item isn't the same item ID, don't remove it
1772
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1772
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1773 1773
                         continue;
1774 1774
                     }
1775 1775
                 }
1776 1776
             }
1777 1777
 
1778
-            $item_quantity = $this->items[ $key ]['quantity'];
1779
-            if ( $item_quantity > $args['quantity'] ) {
1780
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1778
+            $item_quantity = $this->items[$key]['quantity'];
1779
+            if ($item_quantity > $args['quantity']) {
1780
+                $this->items[$key]['quantity'] -= $args['quantity'];
1781 1781
                 break;
1782 1782
             } else {
1783
-                unset( $this->items[ $key ] );
1783
+                unset($this->items[$key]);
1784 1784
                 break;
1785 1785
             }
1786 1786
         }
1787 1787
 
1788 1788
         $found_cart_key = false;
1789
-        if ( false === $args['cart_index'] ) {
1790
-            foreach ( $this->cart_details as $cart_key => $item ) {
1791
-                if ( $item_id != $item['id'] ) {
1789
+        if (false === $args['cart_index']) {
1790
+            foreach ($this->cart_details as $cart_key => $item) {
1791
+                if ($item_id != $item['id']) {
1792 1792
                     continue;
1793 1793
                 }
1794 1794
 
1795
-                if ( false !== $args['item_price'] ) {
1796
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1795
+                if (false !== $args['item_price']) {
1796
+                    if (isset($item['item_price']) && (float)$args['item_price'] != (float)$item['item_price']) {
1797 1797
                         continue;
1798 1798
                     }
1799 1799
                 }
@@ -1802,13 +1802,13 @@  discard block
 block discarded – undo
1802 1802
                 break;
1803 1803
             }
1804 1804
         } else {
1805
-            $cart_index = absint( $args['cart_index'] );
1805
+            $cart_index = absint($args['cart_index']);
1806 1806
 
1807
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1807
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1808 1808
                 return false; // Invalid cart index passed.
1809 1809
             }
1810 1810
 
1811
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1811
+            if ((int)$this->cart_details[$cart_index]['id'] > 0 && (int)$this->cart_details[$cart_index]['id'] !== (int)$item_id) {
1812 1812
                 return false; // We still need the proper Item ID to be sure.
1813 1813
             }
1814 1814
 
@@ -1816,41 +1816,41 @@  discard block
 block discarded – undo
1816 1816
         }
1817 1817
         
1818 1818
         $cart_item  = $this->cart_details[$found_cart_key];
1819
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1819
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1820 1820
         
1821
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1821
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1822 1822
             return false; // Invoice must contain at least one item.
1823 1823
         }
1824 1824
         
1825
-        $discounts  = $this->get_discounts();
1825
+        $discounts = $this->get_discounts();
1826 1826
         
1827
-        if ( $quantity > $args['quantity'] ) {
1827
+        if ($quantity > $args['quantity']) {
1828 1828
             $item_price         = $cart_item['item_price'];
1829
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1829
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1830 1830
             
1831
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1831
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1832 1832
             $subtotal           = $item_price * $new_quantity;
1833 1833
             
1834 1834
             $args['quantity']   = $new_quantity;
1835
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1836
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1835
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1836
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1837 1837
             
1838
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
1838
+            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['discount'] / $quantity)) : 0;
1839 1839
             $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1840
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
1840
+            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float)$cart_item['tax'] / $quantity)) : 0;
1841 1841
             $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1842 1842
             
1843 1843
             // The total increase equals the number removed * the item_price
1844
-            $total_decrease     = wpinv_round_amount( $item_price );
1844
+            $total_decrease     = wpinv_round_amount($item_price);
1845 1845
             
1846
-            if ( wpinv_prices_include_tax() ) {
1847
-                $subtotal -= wpinv_round_amount( $tax );
1846
+            if (wpinv_prices_include_tax()) {
1847
+                $subtotal -= wpinv_round_amount($tax);
1848 1848
             }
1849 1849
 
1850
-            $total              = $subtotal - $discount + $tax;
1850
+            $total = $subtotal - $discount + $tax;
1851 1851
 
1852 1852
             // Do not allow totals to go negative
1853
-            if( $total < 0 ) {
1853
+            if ($total < 0) {
1854 1854
                 $total = 0;
1855 1855
             }
1856 1856
             
@@ -1869,16 +1869,16 @@  discard block
 block discarded – undo
1869 1869
             
1870 1870
             $this->cart_details[$found_cart_key] = $cart_item;
1871 1871
             
1872
-            $remove_item = end( $this->cart_details );
1872
+            $remove_item = end($this->cart_details);
1873 1873
         } else {
1874 1874
             $item_price     = $cart_item['item_price'];
1875
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1876
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1875
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1876
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1877 1877
         
1878
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1878
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1879 1879
             $tax_decrease       = $tax;
1880 1880
 
1881
-            unset( $this->cart_details[$found_cart_key] );
1881
+            unset($this->cart_details[$found_cart_key]);
1882 1882
             
1883 1883
             $remove_item             = $args;
1884 1884
             $remove_item['id']       = $item_id;
@@ -1889,8 +1889,8 @@  discard block
 block discarded – undo
1889 1889
         $remove_item['action']      = 'remove';
1890 1890
         $this->pending['items'][]   = $remove_item;
1891 1891
                
1892
-        $this->decrease_subtotal( $subtotal_decrease );
1893
-        $this->decrease_tax( $tax_decrease );
1892
+        $this->decrease_subtotal($subtotal_decrease);
1893
+        $this->decrease_tax($tax_decrease);
1894 1894
         
1895 1895
         return true;
1896 1896
     }
@@ -1898,7 +1898,7 @@  discard block
 block discarded – undo
1898 1898
     public function update_items($temp = false) {
1899 1899
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
1900 1900
         
1901
-        if ( !empty( $this->cart_details ) ) {
1901
+        if (!empty($this->cart_details)) {
1902 1902
             $wpi_nosave             = $temp;
1903 1903
             $cart_subtotal          = 0;
1904 1904
             $cart_discount          = 0;
@@ -1908,46 +1908,46 @@  discard block
 block discarded – undo
1908 1908
             $_POST['wpinv_country'] = $this->country;
1909 1909
             $_POST['wpinv_state']   = $this->state;
1910 1910
             
1911
-            foreach ( $this->cart_details as $key => $item ) {
1911
+            foreach ($this->cart_details as $key => $item) {
1912 1912
                 //$item['item_price'] = $item['custom_price'];
1913
-                wpinv_error_log( $item, 'item', __FILE__, __LINE__ );
1913
+                wpinv_error_log($item, 'item', __FILE__, __LINE__);
1914 1914
                 $item_price = $item['item_price'];
1915
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1916
-                $amount     = wpinv_round_amount( $item_price * $quantity );
1915
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1916
+                $amount     = wpinv_round_amount($item_price * $quantity);
1917 1917
                 $subtotal   = $item_price * $quantity;
1918 1918
                 
1919 1919
                 $wpi_current_id         = $this->ID;
1920 1920
                 $wpi_item_id            = $item['id'];
1921 1921
                 
1922
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
1923
-                wpinv_error_log( $discount, 'discount', __FILE__, __LINE__ );
1922
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
1923
+                wpinv_error_log($discount, 'discount', __FILE__, __LINE__);
1924 1924
                 
1925
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
1926
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
1927
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1928
-                wpinv_error_log( $tax, 'tax', __FILE__, __LINE__ );
1925
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
1926
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
1927
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float)$tax_rate) : 0;
1928
+                wpinv_error_log($tax, 'tax', __FILE__, __LINE__);
1929 1929
 
1930
-                if ( wpinv_prices_include_tax() ) {
1931
-                    $subtotal -= wpinv_round_amount( $tax );
1930
+                if (wpinv_prices_include_tax()) {
1931
+                    $subtotal -= wpinv_round_amount($tax);
1932 1932
                 }
1933 1933
 
1934
-                $total      = $subtotal - $discount + $tax;
1934
+                $total = $subtotal - $discount + $tax;
1935 1935
 
1936 1936
                 // Do not allow totals to go negative
1937
-                if( $total < 0 ) {
1937
+                if ($total < 0) {
1938 1938
                     $total = 0;
1939 1939
                 }
1940 1940
 
1941 1941
                 $cart_details[] = array(
1942 1942
                     'id'          => $item['id'],
1943 1943
                     'name'        => $item['name'],
1944
-                    'item_price'  => wpinv_round_amount( $item_price ),
1945
-                    'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),
1944
+                    'item_price'  => wpinv_round_amount($item_price),
1945
+                    'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),
1946 1946
                     'quantity'    => $quantity,
1947 1947
                     'discount'    => $discount,
1948
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
1949
-                    'tax'         => wpinv_round_amount( $tax ),
1950
-                    'price'       => wpinv_round_amount( $total ),
1948
+                    'subtotal'    => wpinv_round_amount($subtotal),
1949
+                    'tax'         => wpinv_round_amount($tax),
1950
+                    'price'       => wpinv_round_amount($total),
1951 1951
                     'vat_rate'    => $tax_rate,
1952 1952
                     'vat_class'   => $tax_class,
1953 1953
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
@@ -1958,9 +1958,9 @@  discard block
 block discarded – undo
1958 1958
                 $cart_discount  += (float)($discount);
1959 1959
                 $cart_tax       += (float)($tax);
1960 1960
             }
1961
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
1962
-            $this->tax      = wpinv_round_amount( $cart_tax );
1963
-            $this->discount = wpinv_round_amount( $cart_discount );
1961
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
1962
+            $this->tax      = wpinv_round_amount($cart_tax);
1963
+            $this->discount = wpinv_round_amount($cart_discount);
1964 1964
             
1965 1965
             $this->recalculate_total();
1966 1966
             
@@ -1972,221 +1972,221 @@  discard block
 block discarded – undo
1972 1972
     
1973 1973
     public function recalculate_totals($temp = false) {        
1974 1974
         $this->update_items($temp);
1975
-        $this->save( true );
1975
+        $this->save(true);
1976 1976
         
1977 1977
         return $this;
1978 1978
     }
1979 1979
     
1980 1980
     public function needs_payment() {
1981
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'pending' ), $this );
1981
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('pending'), $this);
1982 1982
 
1983
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() ) ) {
1983
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free())) {
1984 1984
             $needs_payment = true;
1985 1985
         } else {
1986 1986
             $needs_payment = false;
1987 1987
         }
1988 1988
 
1989
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
1989
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
1990 1990
     }
1991 1991
     
1992
-    public function get_checkout_payment_url( $on_checkout = false, $secret = false ) {
1992
+    public function get_checkout_payment_url($on_checkout = false, $secret = false) {
1993 1993
         $pay_url = wpinv_get_checkout_uri();
1994 1994
 
1995
-        if ( is_ssl() ) {
1996
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1995
+        if (is_ssl()) {
1996
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1997 1997
         }
1998 1998
         
1999 1999
         $key = $this->get_key();
2000 2000
 
2001
-        if ( $on_checkout ) {
2002
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
2001
+        if ($on_checkout) {
2002
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
2003 2003
         } else {
2004
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
2004
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
2005 2005
         }
2006 2006
         
2007
-        if ( $secret ) {
2008
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
2007
+        if ($secret) {
2008
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
2009 2009
         }
2010 2010
 
2011
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this );
2011
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this);
2012 2012
     }
2013 2013
     
2014
-    public function get_view_url( $secret = false ) {
2015
-        $print_url = get_permalink( $this->ID );
2014
+    public function get_view_url($secret = false) {
2015
+        $print_url = get_permalink($this->ID);
2016 2016
         
2017
-        if ( $secret ) {
2018
-            $print_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $print_url );
2017
+        if ($secret) {
2018
+            $print_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $print_url);
2019 2019
         }
2020 2020
 
2021
-        return apply_filters( 'wpinv_get_view_url', $print_url, $this );
2021
+        return apply_filters('wpinv_get_view_url', $print_url, $this);
2022 2022
     }
2023 2023
     
2024
-    public function generate_key( $string = '' ) {
2025
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2026
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2024
+    public function generate_key($string = '') {
2025
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2026
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2027 2027
     }
2028 2028
     
2029 2029
     public function is_recurring() {
2030
-        if ( empty( $this->cart_details ) ) {
2030
+        if (empty($this->cart_details)) {
2031 2031
             return false;
2032 2032
         }
2033 2033
         
2034 2034
         $has_subscription = false;
2035
-        foreach( $this->cart_details as $cart_item ) {
2036
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2035
+        foreach ($this->cart_details as $cart_item) {
2036
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2037 2037
                 $has_subscription = true;
2038 2038
                 break;
2039 2039
             }
2040 2040
         }
2041 2041
         
2042
-        if ( count( $this->cart_details ) > 1 ) {
2042
+        if (count($this->cart_details) > 1) {
2043 2043
             $has_subscription = false;
2044 2044
         }
2045 2045
 
2046
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2046
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2047 2047
     }
2048 2048
     
2049 2049
     public function is_free_trial() {
2050 2050
         $is_free_trial = false;
2051 2051
         
2052
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2053
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2052
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2053
+            if (!empty($item) && $item->has_free_trial()) {
2054 2054
                 $is_free_trial = true;
2055 2055
             }
2056 2056
         }
2057 2057
 
2058
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details );
2058
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details);
2059 2059
     }
2060 2060
     
2061
-    public function get_recurring( $object = false ) {
2061
+    public function get_recurring($object = false) {
2062 2062
         $item = NULL;
2063 2063
         
2064
-        if ( empty( $this->cart_details ) ) {
2064
+        if (empty($this->cart_details)) {
2065 2065
             return $item;
2066 2066
         }
2067 2067
         
2068
-        foreach( $this->cart_details as $cart_item ) {
2069
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2068
+        foreach ($this->cart_details as $cart_item) {
2069
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2070 2070
                 $item = $cart_item['id'];
2071 2071
                 break;
2072 2072
             }
2073 2073
         }
2074 2074
         
2075
-        if ( $object ) {
2076
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2075
+        if ($object) {
2076
+            $item = $item ? new WPInv_Item($item) : NULL;
2077 2077
             
2078
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2078
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2079 2079
         }
2080 2080
 
2081
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2081
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2082 2082
     }
2083 2083
     
2084 2084
     public function get_subscription_name() {
2085
-        $item = $this->get_recurring( true );
2085
+        $item = $this->get_recurring(true);
2086 2086
         
2087
-        if ( empty( $item ) ) {
2087
+        if (empty($item)) {
2088 2088
             return NULL;
2089 2089
         }
2090 2090
         
2091
-        if ( !($name = $item->get_name()) ) {
2091
+        if (!($name = $item->get_name())) {
2092 2092
             $name = $item->post_name;
2093 2093
         }
2094 2094
 
2095
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2095
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2096 2096
     }
2097 2097
         
2098 2098
     public function get_expiration() {
2099
-        $expiration = $this->get_meta( '_wpinv_subscr_expiration', true );
2099
+        $expiration = $this->get_meta('_wpinv_subscr_expiration', true);
2100 2100
         return $expiration;
2101 2101
     }
2102 2102
     
2103
-    public function get_cancelled_date( $formatted = true ) {
2104
-        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta( '_wpinv_subscr_cancelled_on', true ) : '';
2103
+    public function get_cancelled_date($formatted = true) {
2104
+        $cancelled_date = $this->get_subscription_status() == 'cancelled' ? $this->get_meta('_wpinv_subscr_cancelled_on', true) : '';
2105 2105
         
2106
-        if ( $formatted && $cancelled_date ) {
2107
-            $cancelled_date = date_i18n( get_option( 'date_format' ), strtotime( $cancelled_date ) );
2106
+        if ($formatted && $cancelled_date) {
2107
+            $cancelled_date = date_i18n(get_option('date_format'), strtotime($cancelled_date));
2108 2108
         }
2109 2109
         
2110 2110
         return $cancelled_date;
2111 2111
     }
2112 2112
     
2113
-    public function get_trial_end_date( $formatted = true ) {
2114
-        if ( !$this->is_free_trial() || !$this->is_paid() ) {
2113
+    public function get_trial_end_date($formatted = true) {
2114
+        if (!$this->is_free_trial() || !$this->is_paid()) {
2115 2115
             return NULL;
2116 2116
         }
2117 2117
         
2118
-        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta( '_wpinv_subscr_trial_end', true ) : '';
2118
+        $trial_end_date = $this->get_subscription_status() == 'trialing' ? $this->get_meta('_wpinv_subscr_trial_end', true) : '';
2119 2119
         
2120
-        if ( empty( $trial_end_date ) ) {
2121
-            $trial_start_time = strtotime( $this->get_subscription_start() );
2122
-            $trial_start_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2120
+        if (empty($trial_end_date)) {
2121
+            $trial_start_time = strtotime($this->get_subscription_start());
2122
+            $trial_start_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2123 2123
             
2124
-            $trial_end_date = date_i18n( 'Y-m-d H:i:s', $trial_start_time );
2124
+            $trial_end_date = date_i18n('Y-m-d H:i:s', $trial_start_time);
2125 2125
         }
2126 2126
         
2127
-        if ( $formatted && $trial_end_date ) {
2128
-            $trial_end_date = date_i18n( get_option( 'date_format' ), strtotime( $trial_end_date ) );
2127
+        if ($formatted && $trial_end_date) {
2128
+            $trial_end_date = date_i18n(get_option('date_format'), strtotime($trial_end_date));
2129 2129
         }
2130 2130
         
2131 2131
         return $trial_end_date;
2132 2132
     }
2133 2133
     
2134
-    public function get_subscription_created( $default = true ) {
2135
-        $created = $this->get_meta( '_wpinv_subscr_created', true );
2134
+    public function get_subscription_created($default = true) {
2135
+        $created = $this->get_meta('_wpinv_subscr_created', true);
2136 2136
         
2137
-        if ( empty( $created ) && $default ) {
2137
+        if (empty($created) && $default) {
2138 2138
             $created = $this->date;
2139 2139
         }
2140 2140
         return $created;
2141 2141
     }
2142 2142
     
2143
-    public function get_subscription_start( $formatted = true ) {
2144
-        if ( !$this->is_paid() ) {
2143
+    public function get_subscription_start($formatted = true) {
2144
+        if (!$this->is_paid()) {
2145 2145
             return '-';
2146 2146
         }
2147
-        $start   = $this->get_subscription_created();
2147
+        $start = $this->get_subscription_created();
2148 2148
         
2149
-        if ( $formatted ) {
2150
-            $date = date_i18n( get_option( 'date_format' ), strtotime( $start ) );
2149
+        if ($formatted) {
2150
+            $date = date_i18n(get_option('date_format'), strtotime($start));
2151 2151
         } else {
2152
-            $date = date_i18n( 'Y-m-d H:i:s', strtotime( $start ) );
2152
+            $date = date_i18n('Y-m-d H:i:s', strtotime($start));
2153 2153
         }
2154 2154
 
2155 2155
         return $date;
2156 2156
     }
2157 2157
     
2158
-    public function get_subscription_end( $formatted = true ) {
2159
-        if ( !$this->is_paid() ) {
2158
+    public function get_subscription_end($formatted = true) {
2159
+        if (!$this->is_paid()) {
2160 2160
             return '-';
2161 2161
         }
2162 2162
         $start          = $this->get_subscription_created();
2163 2163
         $interval       = $this->get_subscription_interval();
2164
-        $period         = $this->get_subscription_period( true );
2164
+        $period         = $this->get_subscription_period(true);
2165 2165
         $bill_times     = (int)$this->get_bill_times();
2166 2166
         
2167
-        if ( $bill_times == 0 ) {
2168
-            return $formatted ? __( 'Until cancelled', 'invoicing' ) : $bill_times;
2167
+        if ($bill_times == 0) {
2168
+            return $formatted ? __('Until cancelled', 'invoicing') : $bill_times;
2169 2169
         }
2170 2170
         
2171
-        $total_period = $start . '+' . ( $interval * $bill_times ) . ' ' . $period;
2171
+        $total_period = $start . '+' . ($interval * $bill_times) . ' ' . $period;
2172 2172
         
2173
-        $end_time = strtotime( $start . '+' . ( $interval * $bill_times ) . ' ' . $period );
2173
+        $end_time = strtotime($start . '+' . ($interval * $bill_times) . ' ' . $period);
2174 2174
         
2175
-        if ( $this->is_free_trial() ) {
2176
-            $end_time += ( wpinv_period_in_days( $this->get_subscription_trial_interval(), $this->get_subscription_trial_period() ) * DAY_IN_SECONDS ) ;
2175
+        if ($this->is_free_trial()) {
2176
+            $end_time += (wpinv_period_in_days($this->get_subscription_trial_interval(), $this->get_subscription_trial_period()) * DAY_IN_SECONDS);
2177 2177
         }
2178 2178
         
2179
-        if ( $formatted ) {
2180
-            $date = date_i18n( get_option( 'date_format' ), $end_time );
2179
+        if ($formatted) {
2180
+            $date = date_i18n(get_option('date_format'), $end_time);
2181 2181
         } else {
2182
-            $date = date_i18n( 'Y-m-d H:i:s', $end_time );
2182
+            $date = date_i18n('Y-m-d H:i:s', $end_time);
2183 2183
         }
2184 2184
 
2185 2185
         return $date;
2186 2186
     }
2187 2187
     
2188 2188
     public function get_expiration_time() {
2189
-        return strtotime( $this->get_expiration(), current_time( 'timestamp' ) );
2189
+        return strtotime($this->get_expiration(), current_time('timestamp'));
2190 2190
     }
2191 2191
     
2192 2192
     public function get_original_invoice_id() {        
@@ -2198,125 +2198,125 @@  discard block
 block discarded – undo
2198 2198
         return $subscription_data['bill_times'];
2199 2199
     }
2200 2200
 
2201
-    public function get_child_payments( $self = false ) {
2202
-        $invoices = get_posts( array(
2201
+    public function get_child_payments($self = false) {
2202
+        $invoices = get_posts(array(
2203 2203
             'post_type'         => $this->post_type,
2204 2204
             'post_parent'       => (int)$this->ID,
2205 2205
             'posts_per_page'    => '999',
2206
-            'post_status'       => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
2206
+            'post_status'       => array('publish', 'wpi-processing', 'wpi-renewal'),
2207 2207
             'orderby'           => 'ID',
2208 2208
             'order'             => 'DESC',
2209 2209
             'fields'            => 'ids'
2210
-        ) );
2210
+        ));
2211 2211
         
2212
-        if ( $this->is_free_trial() ) {
2212
+        if ($this->is_free_trial()) {
2213 2213
             $self = false;
2214 2214
         }
2215 2215
         
2216
-        if ( $self && $this->is_paid() ) {
2217
-            if ( !empty( $invoices ) ) {
2216
+        if ($self && $this->is_paid()) {
2217
+            if (!empty($invoices)) {
2218 2218
                 $invoices[] = (int)$this->ID;
2219 2219
             } else {
2220
-                $invoices = array( $this->ID );
2220
+                $invoices = array($this->ID);
2221 2221
             }
2222 2222
             
2223
-            $invoices = array_unique( $invoices );
2223
+            $invoices = array_unique($invoices);
2224 2224
         }
2225 2225
 
2226 2226
         return $invoices;
2227 2227
     }
2228 2228
 
2229
-    public function get_total_payments( $self = true ) {
2230
-        return count( $this->get_child_payments( $self ) );
2229
+    public function get_total_payments($self = true) {
2230
+        return count($this->get_child_payments($self));
2231 2231
     }
2232 2232
     
2233
-    public function get_subscriptions( $limit = -1 ) {
2234
-        $subscriptions = wpinv_get_subscriptions( array( 'parent_invoice_id' => $this->ID, 'numberposts' => $limit ) );
2233
+    public function get_subscriptions($limit = -1) {
2234
+        $subscriptions = wpinv_get_subscriptions(array('parent_invoice_id' => $this->ID, 'numberposts' => $limit));
2235 2235
 
2236 2236
         return $subscriptions;
2237 2237
     }
2238 2238
     
2239 2239
     public function get_subscription_id() {
2240
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2240
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2241 2241
         
2242
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2243
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2242
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2243
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2244 2244
             
2245
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2245
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2246 2246
         }
2247 2247
         
2248 2248
         return $subscription_id;
2249 2249
     }
2250 2250
     
2251 2251
     public function get_subscription_status() {
2252
-        $subscription_status = $this->get_meta( '_wpinv_subscr_status', true );
2252
+        $subscription_status = $this->get_meta('_wpinv_subscr_status', true);
2253 2253
 
2254
-        if ( empty( $subscription_status ) ) {
2254
+        if (empty($subscription_status)) {
2255 2255
             $status = 'pending';
2256 2256
             
2257
-            if ( $this->is_paid() ) {        
2257
+            if ($this->is_paid()) {        
2258 2258
                 $bill_times   = (int)$this->get_bill_times();
2259 2259
                 $times_billed = (int)$this->get_total_payments();
2260
-                $expiration = $this->get_subscription_end( false );
2261
-                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime( date_i18n( 'Y-m-d', strtotime( $expiration ) ) ) < strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) ) ? true : false;
2260
+                $expiration = $this->get_subscription_end(false);
2261
+                $expired = $bill_times != 0 && $expiration != '' && $expiration != '-' && strtotime(date_i18n('Y-m-d', strtotime($expiration))) < strtotime(date_i18n('Y-m-d', current_time('timestamp'))) ? true : false;
2262 2262
                 
2263
-                if ( (int)$bill_times == 0 ) {
2263
+                if ((int)$bill_times == 0) {
2264 2264
                     $status = $expired ? 'expired' : 'active';
2265
-                } else if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2265
+                } else if ($bill_times > 0 && $times_billed >= $bill_times) {
2266 2266
                     $status = 'completed';
2267
-                } else if ( $expired ) {
2267
+                } else if ($expired) {
2268 2268
                     $status = 'expired';
2269
-                } else if ( $bill_times > 0 ) {
2269
+                } else if ($bill_times > 0) {
2270 2270
                     $status = 'active';
2271 2271
                 } else {
2272 2272
                     $status = 'pending';
2273 2273
                 }
2274 2274
             }
2275 2275
             
2276
-            if ( $status && $status != $subscription_status ) {
2276
+            if ($status && $status != $subscription_status) {
2277 2277
                 $subscription_status = $status;
2278 2278
                 
2279
-                $this->update_meta( '_wpinv_subscr_status', $status );
2279
+                $this->update_meta('_wpinv_subscr_status', $status);
2280 2280
             }
2281 2281
         }
2282 2282
         
2283 2283
         return $subscription_status;
2284 2284
     }
2285 2285
     
2286
-    public function get_subscription_status_label( $status = '' ) {
2287
-        $status = !empty( $status ) ? $status : $this->get_subscription_status();
2286
+    public function get_subscription_status_label($status = '') {
2287
+        $status = !empty($status) ? $status : $this->get_subscription_status();
2288 2288
 
2289
-        switch( $status ) {
2289
+        switch ($status) {
2290 2290
             case 'active' :
2291
-                $status_label = __( 'Active', 'invoicing' );
2291
+                $status_label = __('Active', 'invoicing');
2292 2292
                 break;
2293 2293
 
2294 2294
             case 'cancelled' :
2295
-                $status_label = __( 'Cancelled', 'invoicing' );
2295
+                $status_label = __('Cancelled', 'invoicing');
2296 2296
                 break;
2297 2297
                 
2298 2298
             case 'completed' :
2299
-                $status_label = __( 'Completed', 'invoicing' );
2299
+                $status_label = __('Completed', 'invoicing');
2300 2300
                 break;
2301 2301
 
2302 2302
             case 'expired' :
2303
-                $status_label = __( 'Expired', 'invoicing' );
2303
+                $status_label = __('Expired', 'invoicing');
2304 2304
                 break;
2305 2305
 
2306 2306
             case 'pending' :
2307
-                $status_label = __( 'Pending', 'invoicing' );
2307
+                $status_label = __('Pending', 'invoicing');
2308 2308
                 break;
2309 2309
 
2310 2310
             case 'failing' :
2311
-                $status_label = __( 'Failing', 'invoicing' );
2311
+                $status_label = __('Failing', 'invoicing');
2312 2312
                 break;
2313 2313
                 
2314 2314
             case 'stopped' :
2315
-                $status_label = __( 'Stopped', 'invoicing' );
2315
+                $status_label = __('Stopped', 'invoicing');
2316 2316
                 break;
2317 2317
                 
2318 2318
             case 'trialing' :
2319
-                $status_label = __( 'Trialing', 'invoicing' );
2319
+                $status_label = __('Trialing', 'invoicing');
2320 2320
                 break;
2321 2321
 
2322 2322
             default:
@@ -2327,26 +2327,26 @@  discard block
 block discarded – undo
2327 2327
         return $status_label;
2328 2328
     }
2329 2329
     
2330
-    public function get_subscription_period( $full = false ) {
2331
-        $period = $this->get_meta( '_wpinv_subscr_period', true );
2330
+    public function get_subscription_period($full = false) {
2331
+        $period = $this->get_meta('_wpinv_subscr_period', true);
2332 2332
         
2333 2333
         // Fix period for old invoices
2334
-        if ( $period == 'day' ) {
2334
+        if ($period == 'day') {
2335 2335
             $period = 'D';
2336
-        } else if ( $period == 'week' ) {
2336
+        } else if ($period == 'week') {
2337 2337
             $period = 'W';
2338
-        } else if ( $period == 'month' ) {
2338
+        } else if ($period == 'month') {
2339 2339
             $period = 'M';
2340
-        } else if ( $period == 'year' ) {
2340
+        } else if ($period == 'year') {
2341 2341
             $period = 'Y';
2342 2342
         }
2343 2343
         
2344
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2344
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2345 2345
             $period = 'D';
2346 2346
         }
2347 2347
         
2348
-        if ( $full ) {
2349
-            switch( $period ) {
2348
+        if ($full) {
2349
+            switch ($period) {
2350 2350
                 case 'D':
2351 2351
                     $period = 'day';
2352 2352
                 break;
@@ -2366,39 +2366,39 @@  discard block
 block discarded – undo
2366 2366
     }
2367 2367
     
2368 2368
     public function get_subscription_interval() {
2369
-        $interval = (int)$this->get_meta( '_wpinv_subscr_interval', true );
2369
+        $interval = (int)$this->get_meta('_wpinv_subscr_interval', true);
2370 2370
         
2371
-        if ( !$interval > 0 ) {
2371
+        if (!$interval > 0) {
2372 2372
             $interval = 1;
2373 2373
         }
2374 2374
         
2375 2375
         return $interval;
2376 2376
     }
2377 2377
     
2378
-    public function get_subscription_trial_period( $full = false ) {
2379
-        if ( !$this->is_free_trial() ) {
2378
+    public function get_subscription_trial_period($full = false) {
2379
+        if (!$this->is_free_trial()) {
2380 2380
             return '';
2381 2381
         }
2382 2382
         
2383
-        $period = $this->get_meta( '_wpinv_subscr_trial_period', true );
2383
+        $period = $this->get_meta('_wpinv_subscr_trial_period', true);
2384 2384
         
2385 2385
         // Fix period for old invoices
2386
-        if ( $period == 'day' ) {
2386
+        if ($period == 'day') {
2387 2387
             $period = 'D';
2388
-        } else if ( $period == 'week' ) {
2388
+        } else if ($period == 'week') {
2389 2389
             $period = 'W';
2390
-        } else if ( $period == 'month' ) {
2390
+        } else if ($period == 'month') {
2391 2391
             $period = 'M';
2392
-        } else if ( $period == 'year' ) {
2392
+        } else if ($period == 'year') {
2393 2393
             $period = 'Y';
2394 2394
         }
2395 2395
         
2396
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
2396
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
2397 2397
             $period = 'D';
2398 2398
         }
2399 2399
         
2400
-        if ( $full ) {
2401
-            switch( $period ) {
2400
+        if ($full) {
2401
+            switch ($period) {
2402 2402
                 case 'D':
2403 2403
                     $period = 'day';
2404 2404
                 break;
@@ -2418,13 +2418,13 @@  discard block
 block discarded – undo
2418 2418
     }
2419 2419
     
2420 2420
     public function get_subscription_trial_interval() {
2421
-        if ( !$this->is_free_trial() ) {
2421
+        if (!$this->is_free_trial()) {
2422 2422
             return 0;
2423 2423
         }
2424 2424
         
2425
-        $interval = (int)$this->get_meta( '_wpinv_subscr_trial_interval', true );
2425
+        $interval = (int)$this->get_meta('_wpinv_subscr_trial_interval', true);
2426 2426
         
2427
-        if ( !$interval > 0 ) {
2427
+        if (!$interval > 0) {
2428 2428
             $interval = 1;
2429 2429
         }
2430 2430
         
@@ -2436,8 +2436,8 @@  discard block
 block discarded – undo
2436 2436
             'status' => 'failing'
2437 2437
         );
2438 2438
 
2439
-        if ( $this->update_subscription( $args ) ) {
2440
-            do_action( 'wpinv_subscription_failing', $this->ID, $this );
2439
+        if ($this->update_subscription($args)) {
2440
+            do_action('wpinv_subscription_failing', $this->ID, $this);
2441 2441
             return true;
2442 2442
         }
2443 2443
 
@@ -2449,8 +2449,8 @@  discard block
 block discarded – undo
2449 2449
             'status' => 'stopped'
2450 2450
         );
2451 2451
 
2452
-        if ( $this->update_subscription( $args ) ) {
2453
-            do_action( 'wpinv_subscription_stopped', $this->ID, $this );
2452
+        if ($this->update_subscription($args)) {
2453
+            do_action('wpinv_subscription_stopped', $this->ID, $this);
2454 2454
             return true;
2455 2455
         }
2456 2456
 
@@ -2462,8 +2462,8 @@  discard block
 block discarded – undo
2462 2462
             'status' => 'active'
2463 2463
         );
2464 2464
 
2465
-        if ( $this->update_subscription( $args ) ) {
2466
-            do_action( 'wpinv_subscription_restarted', $this->ID, $this );
2465
+        if ($this->update_subscription($args)) {
2466
+            do_action('wpinv_subscription_restarted', $this->ID, $this);
2467 2467
             return true;
2468 2468
         }
2469 2469
 
@@ -2475,23 +2475,23 @@  discard block
 block discarded – undo
2475 2475
             'status' => 'cancelled'
2476 2476
         );
2477 2477
 
2478
-        if ( $this->update_subscription( $args ) ) {
2479
-            if ( is_user_logged_in() ) {
2480
-                $userdata = get_userdata( get_current_user_id() );
2478
+        if ($this->update_subscription($args)) {
2479
+            if (is_user_logged_in()) {
2480
+                $userdata = get_userdata(get_current_user_id());
2481 2481
                 $user     = $userdata->user_login;
2482 2482
             } else {
2483
-                $user = __( 'gateway', 'invoicing' );
2483
+                $user = __('gateway', 'invoicing');
2484 2484
             }
2485 2485
             
2486 2486
             $subscription_id = $this->get_subscription_id();
2487
-            if ( !$subscription_id ) {
2487
+            if (!$subscription_id) {
2488 2488
                 $subscription_id = $this->ID;
2489 2489
             }
2490 2490
 
2491
-            $note = sprintf( __( 'Subscription %s has been cancelled by %s', 'invoicing' ), $subscription_id, $user );
2492
-            $this->add_note( $note );
2491
+            $note = sprintf(__('Subscription %s has been cancelled by %s', 'invoicing'), $subscription_id, $user);
2492
+            $this->add_note($note);
2493 2493
 
2494
-            do_action( 'wpinv_subscription_cancelled', $this->ID, $this );
2494
+            do_action('wpinv_subscription_cancelled', $this->ID, $this);
2495 2495
             return true;
2496 2496
         }
2497 2497
 
@@ -2499,11 +2499,11 @@  discard block
 block discarded – undo
2499 2499
     }
2500 2500
 
2501 2501
     public function can_cancel() {
2502
-        return apply_filters( 'wpinv_subscription_can_cancel', false, $this );
2502
+        return apply_filters('wpinv_subscription_can_cancel', false, $this);
2503 2503
     }
2504 2504
     
2505
-    public function add_subscription( $data = array() ) {
2506
-        if ( empty( $this->ID ) ) {
2505
+    public function add_subscription($data = array()) {
2506
+        if (empty($this->ID)) {
2507 2507
             return false;
2508 2508
         }
2509 2509
 
@@ -2522,85 +2522,85 @@  discard block
 block discarded – undo
2522 2522
             'profile_id'        => '',
2523 2523
         );
2524 2524
 
2525
-        $args = wp_parse_args( $data, $defaults );
2525
+        $args = wp_parse_args($data, $defaults);
2526 2526
 
2527
-        if ( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2528
-            if ( 'active' == $args['status'] || $args['status'] == 'trialing' ) {
2527
+        if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2528
+            if ('active' == $args['status'] || $args['status'] == 'trialing') {
2529 2529
                 $args['status'] = 'expired';
2530 2530
             }
2531 2531
         }
2532 2532
 
2533
-        do_action( 'wpinv_subscription_pre_create', $args, $data, $this );
2533
+        do_action('wpinv_subscription_pre_create', $args, $data, $this);
2534 2534
         
2535
-        if ( !empty( $args ) ) {
2536
-            foreach ( $args as $key => $value ) {
2537
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2535
+        if (!empty($args)) {
2536
+            foreach ($args as $key => $value) {
2537
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2538 2538
             }
2539 2539
         }
2540 2540
 
2541
-        do_action( 'wpinv_subscription_post_create', $args, $data, $this );
2541
+        do_action('wpinv_subscription_post_create', $args, $data, $this);
2542 2542
 
2543 2543
         return true;
2544 2544
     }
2545 2545
     
2546
-    public function update_subscription( $args = array() ) {
2547
-        if ( empty( $this->ID ) ) {
2546
+    public function update_subscription($args = array()) {
2547
+        if (empty($this->ID)) {
2548 2548
             return false;
2549 2549
         }
2550 2550
 
2551
-        if ( !empty( $args['expiration'] ) && $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
2552
-            if ( !isset( $args['status'] ) || ( isset( $args['status'] ) && ( 'active' == $args['status'] || $args['status'] == 'trialing' ) ) ) {
2551
+        if (!empty($args['expiration']) && $args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
2552
+            if (!isset($args['status']) || (isset($args['status']) && ('active' == $args['status'] || $args['status'] == 'trialing'))) {
2553 2553
                 $args['status'] = 'expired';
2554 2554
             }
2555 2555
         }
2556 2556
 
2557
-        if ( isset( $args['status'] ) && $args['status'] == 'cancelled' && empty( $args['cancelled_on'] ) ) {
2558
-            $args['cancelled_on'] = date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) );
2557
+        if (isset($args['status']) && $args['status'] == 'cancelled' && empty($args['cancelled_on'])) {
2558
+            $args['cancelled_on'] = date_i18n('Y-m-d H:i:s', current_time('timestamp'));
2559 2559
         }
2560 2560
 
2561
-        do_action( 'wpinv_subscription_pre_update', $args, $this );
2561
+        do_action('wpinv_subscription_pre_update', $args, $this);
2562 2562
         
2563
-        if ( !empty( $args ) ) {
2564
-            foreach ( $args as $key => $value ) {
2565
-                $this->update_meta( '_wpinv_subscr_' . $key, $value );
2563
+        if (!empty($args)) {
2564
+            foreach ($args as $key => $value) {
2565
+                $this->update_meta('_wpinv_subscr_' . $key, $value);
2566 2566
             }
2567 2567
         }
2568 2568
 
2569
-        do_action( 'wpinv_subscription_post_update', $args, $this );
2569
+        do_action('wpinv_subscription_post_update', $args, $this);
2570 2570
 
2571 2571
         return true;
2572 2572
     }
2573 2573
     
2574 2574
     public function renew_subscription() {
2575 2575
         $parent_invoice = $this->get_parent_payment();
2576
-        $parent_invoice = empty( $parent_invoice ) ? $this : $parent_invoice;
2576
+        $parent_invoice = empty($parent_invoice) ? $this : $parent_invoice;
2577 2577
         
2578
-        $current_time   = current_time( 'timestamp' );
2578
+        $current_time   = current_time('timestamp');
2579 2579
         $start          = $this->get_subscription_created();
2580
-        $start          = $start ? strtotime( $start ) : $current_time;
2580
+        $start          = $start ? strtotime($start) : $current_time;
2581 2581
         $expires        = $this->get_expiration_time();
2582 2582
         
2583
-        if ( !$expires ) {
2584
-            $expires    = strtotime( '+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period( true ), $start );
2583
+        if (!$expires) {
2584
+            $expires    = strtotime('+' . $parent_invoice->get_subscription_interval() . ' ' . $parent_invoice->get_subscription_period(true), $start);
2585 2585
         }
2586 2586
         
2587
-        $expiration     = date_i18n( 'Y-m-d 23:59:59', $expires );
2588
-        $expiration     = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this );
2587
+        $expiration     = date_i18n('Y-m-d 23:59:59', $expires);
2588
+        $expiration     = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->ID, $this);
2589 2589
         $bill_times     = $parent_invoice->get_bill_times();
2590 2590
         $times_billed   = $parent_invoice->get_total_payments();
2591 2591
         
2592
-        if ( $parent_invoice->get_subscription_status() == 'trialing' && ( $times_billed > 0 || strtotime( date_i18n( 'Y-m-d' ) ) < strtotime( $parent_invoice->get_trial_end_date( false ) ) ) ) {
2592
+        if ($parent_invoice->get_subscription_status() == 'trialing' && ($times_billed > 0 || strtotime(date_i18n('Y-m-d')) < strtotime($parent_invoice->get_trial_end_date(false)))) {
2593 2593
             $args = array(
2594 2594
                 'status'     => 'active',
2595 2595
             );
2596 2596
 
2597
-            $parent_invoice->update_subscription( $args );
2597
+            $parent_invoice->update_subscription($args);
2598 2598
         }
2599 2599
         
2600
-        do_action( 'wpinv_subscription_pre_renew', $this->ID, $expiration, $this );
2600
+        do_action('wpinv_subscription_pre_renew', $this->ID, $expiration, $this);
2601 2601
 
2602
-        $status       = 'active';
2603
-        if ( $bill_times > 0 && $times_billed >= $bill_times ) {
2602
+        $status = 'active';
2603
+        if ($bill_times > 0 && $times_billed >= $bill_times) {
2604 2604
             $this->complete_subscription();
2605 2605
             $status = 'completed';
2606 2606
         }
@@ -2610,10 +2610,10 @@  discard block
 block discarded – undo
2610 2610
             'status'     => $status,
2611 2611
         );
2612 2612
 
2613
-        $this->update_subscription( $args );
2613
+        $this->update_subscription($args);
2614 2614
 
2615
-        do_action( 'wpinv_subscription_post_renew', $this->ID, $expiration, $this );
2616
-        do_action( 'wpinv_recurring_set_subscription_status', $this->ID, $status, $this );
2615
+        do_action('wpinv_subscription_post_renew', $this->ID, $expiration, $this);
2616
+        do_action('wpinv_recurring_set_subscription_status', $this->ID, $status, $this);
2617 2617
     }
2618 2618
     
2619 2619
     public function complete_subscription() {
@@ -2621,8 +2621,8 @@  discard block
 block discarded – undo
2621 2621
             'status' => 'completed'
2622 2622
         );
2623 2623
 
2624
-        if ( $this->update_subscription( $args ) ) {
2625
-            do_action( 'wpinv_subscription_completed', $this->ID, $this );
2624
+        if ($this->update_subscription($args)) {
2625
+            do_action('wpinv_subscription_completed', $this->ID, $this);
2626 2626
         }
2627 2627
     }
2628 2628
     
@@ -2631,44 +2631,44 @@  discard block
 block discarded – undo
2631 2631
             'status' => 'expired'
2632 2632
         );
2633 2633
 
2634
-        if ( $this->update_subscription( $args ) ) {
2635
-            do_action( 'wpinv_subscription_expired', $this->ID, $this );
2634
+        if ($this->update_subscription($args)) {
2635
+            do_action('wpinv_subscription_expired', $this->ID, $this);
2636 2636
         }
2637 2637
     }
2638 2638
 
2639 2639
     public function get_cancel_url() {
2640
-        $url = wp_nonce_url( add_query_arg( array( 'wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID ) ), 'wpinv-recurring-cancel' );
2640
+        $url = wp_nonce_url(add_query_arg(array('wpi_action' => 'cancel_subscription', 'sub_id' => $this->ID)), 'wpinv-recurring-cancel');
2641 2641
 
2642
-        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
2642
+        return apply_filters('wpinv_subscription_cancel_url', $url, $this);
2643 2643
     }
2644 2644
 
2645 2645
     public function can_update() {
2646
-        return apply_filters( 'wpinv_subscription_can_update', false, $this );
2646
+        return apply_filters('wpinv_subscription_can_update', false, $this);
2647 2647
     }
2648 2648
 
2649 2649
     public function get_update_url() {
2650
-        $url = add_query_arg( array( 'action' => 'update', 'sub_id' => $this->ID ) );
2650
+        $url = add_query_arg(array('action' => 'update', 'sub_id' => $this->ID));
2651 2651
 
2652
-        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
2652
+        return apply_filters('wpinv_subscription_update_url', $url, $this);
2653 2653
     }
2654 2654
 
2655 2655
     public function is_parent() {
2656
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2656
+        $is_parent = empty($this->parent_invoice) ? true : false;
2657 2657
 
2658
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2658
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2659 2659
     }
2660 2660
     
2661 2661
     public function is_renewal() {
2662 2662
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2663 2663
 
2664
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2664
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2665 2665
     }
2666 2666
     
2667 2667
     public function get_parent_payment() {
2668 2668
         $parent_payment = NULL;
2669 2669
         
2670
-        if ( $this->is_renewal() ) {
2671
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2670
+        if ($this->is_renewal()) {
2671
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2672 2672
         }
2673 2673
         
2674 2674
         return $parent_payment;
@@ -2679,100 +2679,100 @@  discard block
 block discarded – undo
2679 2679
         
2680 2680
         $subscription_status = $this->get_subscription_status();
2681 2681
 
2682
-        if( ! $this->is_subscription_expired() && ( $subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing' ) ) {
2682
+        if (!$this->is_subscription_expired() && ($subscription_status == 'active' || $subscription_status == 'cancelled' || $subscription_status == 'trialing')) {
2683 2683
             $ret = true;
2684 2684
         }
2685 2685
 
2686
-        return apply_filters( 'wpinv_subscription_is_active', $ret, $this->ID, $this );
2686
+        return apply_filters('wpinv_subscription_is_active', $ret, $this->ID, $this);
2687 2687
     }
2688 2688
 
2689 2689
     public function is_subscription_expired() {
2690 2690
         $ret = false;
2691 2691
         $subscription_status = $this->get_subscription_status();
2692 2692
 
2693
-        if ( $subscription_status == 'expired' ) {
2693
+        if ($subscription_status == 'expired') {
2694 2694
             $ret = true;
2695
-        } else if ( 'active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status ) {
2695
+        } else if ('active' === $subscription_status || 'cancelled' === $subscription_status || 'trialing' == $subscription_status) {
2696 2696
             $ret        = false;
2697 2697
             $expiration = $this->get_expiration_time();
2698 2698
 
2699
-            if ( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
2699
+            if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
2700 2700
                 $ret = true;
2701 2701
 
2702
-                if ( 'active' === $subscription_status || 'trialing' === $subscription_status ) {
2702
+                if ('active' === $subscription_status || 'trialing' === $subscription_status) {
2703 2703
                     $this->expire_subscription();
2704 2704
                 }
2705 2705
             }
2706 2706
         }
2707 2707
 
2708
-        return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->ID, $this );
2708
+        return apply_filters('wpinv_subscription_is_expired', $ret, $this->ID, $this);
2709 2709
     }
2710 2710
     
2711
-    public function get_new_expiration( $item_id = 0, $trial = true ) {
2712
-        $item   = new WPInv_Item( $item_id );
2711
+    public function get_new_expiration($item_id = 0, $trial = true) {
2712
+        $item   = new WPInv_Item($item_id);
2713 2713
         $interval = $item->get_recurring_interval();
2714
-        $period = $item->get_recurring_period( true );
2714
+        $period = $item->get_recurring_period(true);
2715 2715
         
2716
-        $expiration_time = strtotime( '+' . $interval . ' ' . $period );
2716
+        $expiration_time = strtotime('+' . $interval . ' ' . $period);
2717 2717
         
2718
-        if ( $trial && $this->is_free_trial() && $item->has_free_trial() ) {
2719
-            $expiration_time += ( wpinv_period_in_days( $item->get_trial_interval(), $item->get_trial_period() ) * DAY_IN_SECONDS ) ;
2718
+        if ($trial && $this->is_free_trial() && $item->has_free_trial()) {
2719
+            $expiration_time += (wpinv_period_in_days($item->get_trial_interval(), $item->get_trial_period()) * DAY_IN_SECONDS);
2720 2720
         }
2721 2721
 
2722
-        return date_i18n( 'Y-m-d 23:59:59', $expiration_time );
2722
+        return date_i18n('Y-m-d 23:59:59', $expiration_time);
2723 2723
     }
2724 2724
     
2725
-    public function get_subscription_data( $filed = '' ) {
2726
-        $fields = array( 'item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on' );
2725
+    public function get_subscription_data($filed = '') {
2726
+        $fields = array('item_id', 'status', 'period', 'initial_amount', 'recurring_amount', 'interval', 'bill_times', 'trial_period', 'trial_interval', 'expiration', 'profile_id', 'created', 'cancelled_on');
2727 2727
         
2728 2728
         $subscription_meta = array();
2729
-        foreach ( $fields as $field ) {
2730
-            $subscription_meta[ $field ] = $this->get_meta( '_wpinv_subscr_' . $field );
2729
+        foreach ($fields as $field) {
2730
+            $subscription_meta[$field] = $this->get_meta('_wpinv_subscr_' . $field);
2731 2731
         }
2732 2732
         
2733
-        $item = $this->get_recurring( true );
2733
+        $item = $this->get_recurring(true);
2734 2734
         
2735
-        if ( !empty( $item ) ) {
2736
-            if ( empty( $subscription_meta['item_id'] ) ) {
2735
+        if (!empty($item)) {
2736
+            if (empty($subscription_meta['item_id'])) {
2737 2737
                 $subscription_meta['item_id'] = $item->ID;
2738 2738
             }
2739
-            if ( empty( $subscription_meta['period'] ) ) {
2739
+            if (empty($subscription_meta['period'])) {
2740 2740
                 $subscription_meta['period'] = $item->get_recurring_period();
2741 2741
             }
2742
-            if ( empty( $subscription_meta['interval'] ) ) {
2742
+            if (empty($subscription_meta['interval'])) {
2743 2743
                 $subscription_meta['interval'] = $item->get_recurring_interval();
2744 2744
             }
2745
-            if ( $item->has_free_trial() ) {
2746
-                if ( empty( $subscription_meta['trial_period'] ) ) {
2745
+            if ($item->has_free_trial()) {
2746
+                if (empty($subscription_meta['trial_period'])) {
2747 2747
                     $subscription_meta['trial_period'] = $item->get_trial_period();
2748 2748
                 }
2749
-                if ( empty( $subscription_meta['trial_interval'] ) ) {
2749
+                if (empty($subscription_meta['trial_interval'])) {
2750 2750
                     $subscription_meta['trial_interval'] = $item->get_trial_interval();
2751 2751
                 }
2752 2752
             } else {
2753 2753
                 $subscription_meta['trial_period']      = '';
2754 2754
                 $subscription_meta['trial_interval']    = 0;
2755 2755
             }
2756
-            if ( !$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0 ) {
2756
+            if (!$subscription_meta['bill_times'] && $subscription_meta['bill_times'] !== 0) {
2757 2757
                 $subscription_meta['bill_times'] = $item->get_recurring_limit();
2758 2758
             }
2759
-            if ( $subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '' ) {
2760
-                $subscription_meta['initial_amount']    = wpinv_round_amount( $this->get_total() );
2761
-                $subscription_meta['recurring_amount']  = wpinv_round_amount( $this->get_recurring_details( 'total' ) );
2759
+            if ($subscription_meta['initial_amount'] === '' || $subscription_meta['recurring_amount'] === '') {
2760
+                $subscription_meta['initial_amount']    = wpinv_round_amount($this->get_total());
2761
+                $subscription_meta['recurring_amount']  = wpinv_round_amount($this->get_recurring_details('total'));
2762 2762
             }
2763 2763
         }
2764 2764
         
2765
-        if ( $filed === '' ) {
2766
-            return apply_filters( 'wpinv_get_invoice_subscription_data', $subscription_meta, $this );
2765
+        if ($filed === '') {
2766
+            return apply_filters('wpinv_get_invoice_subscription_data', $subscription_meta, $this);
2767 2767
         }
2768 2768
         
2769
-        $value = isset( $subscription_meta[$filed] ) ? $subscription_meta[$filed] : '';
2769
+        $value = isset($subscription_meta[$filed]) ? $subscription_meta[$filed] : '';
2770 2770
         
2771
-        return apply_filters( 'wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this );
2771
+        return apply_filters('wpinv_invoice_subscription_data_value', $value, $subscription_meta, $this);
2772 2772
     }
2773 2773
     
2774 2774
     public function is_paid() {
2775
-        if ( $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
2775
+        if ($this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'))) {
2776 2776
             return true;
2777 2777
         }
2778 2778
         
@@ -2782,15 +2782,15 @@  discard block
 block discarded – undo
2782 2782
     public function is_free() {
2783 2783
         $is_free = false;
2784 2784
         
2785
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2786
-            if ( $this->is_parent() && $this->is_recurring() ) {
2787
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2785
+        if (!((float)wpinv_round_amount($this->get_total()) > 0)) {
2786
+            if ($this->is_parent() && $this->is_recurring()) {
2787
+                $is_free = (float)wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2788 2788
             } else {
2789 2789
                 $is_free = true;
2790 2790
             }
2791 2791
         }
2792 2792
         
2793
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2793
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2794 2794
     }
2795 2795
     
2796 2796
     public function has_vat() {
@@ -2798,40 +2798,40 @@  discard block
 block discarded – undo
2798 2798
         
2799 2799
         $requires_vat = false;
2800 2800
         
2801
-        if ( $this->country ) {
2801
+        if ($this->country) {
2802 2802
             $wpi_country        = $this->country;
2803 2803
             
2804
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2804
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2805 2805
         }
2806 2806
         
2807
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2807
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2808 2808
     }
2809 2809
     
2810 2810
     public function refresh_item_ids() {
2811 2811
         $item_ids = array();
2812 2812
         
2813
-        if ( !empty( $this->cart_details ) ) {
2814
-            foreach ( $this->cart_details as $key => $item ) {
2815
-                if ( !empty( $item['id'] ) ) {
2813
+        if (!empty($this->cart_details)) {
2814
+            foreach ($this->cart_details as $key => $item) {
2815
+                if (!empty($item['id'])) {
2816 2816
                     $item_ids[] = $item['id'];
2817 2817
                 }
2818 2818
             }
2819 2819
         }
2820 2820
         
2821
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2821
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2822 2822
         
2823
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2823
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2824 2824
     }
2825 2825
 
2826 2826
     public function get_invoice_quote_type($post_id) {
2827
-        if ( empty( $post_id ) ) {
2827
+        if (empty($post_id)) {
2828 2828
             return '';
2829 2829
         }
2830 2830
         $post_type = '';
2831 2831
         $type = get_post_type($post_id);
2832
-        if("wpi_invoice" === $type){
2832
+        if ("wpi_invoice" === $type) {
2833 2833
             $post_type = __('Invoice', 'invoicing');
2834
-        } else{
2834
+        } else {
2835 2835
             $post_type = __('Quote', 'invoicing');
2836 2836
         }
2837 2837
 
Please login to merge, or discard this patch.
includes/wpinv-gd-functions.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -740,6 +740,9 @@
 block discarded – undo
740 740
 add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' );
741 741
 remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' );
742 742
 
743
+/**
744
+ * @param string $new_status
745
+ */
743 746
 function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) {
744 747
     if (!defined('GEODIRPAYMENT_VERSION')) {
745 748
         return false;
Please login to merge, or discard this patch.
Spacing   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 function wpinv_gd_active() {
8
-    return (bool)defined( 'GEODIRECTORY_VERSION' );
8
+    return (bool)defined('GEODIRECTORY_VERSION');
9 9
 }
10 10
 
11 11
 function wpinv_pm_active() {
12
-    return (bool)wpinv_gd_active() && (bool)defined( 'GEODIRPAYMENT_VERSION' );
12
+    return (bool)wpinv_gd_active() && (bool)defined('GEODIRPAYMENT_VERSION');
13 13
 }
14 14
 
15
-function wpinv_is_gd_post_type( $post_type ) {
15
+function wpinv_is_gd_post_type($post_type) {
16 16
     global $gd_posttypes;
17 17
     
18
-    $gd_posttypes = !empty( $gd_posttypes ) && is_array( $gd_posttypes ) ? $gd_posttypes : geodir_get_posttypes();
18
+    $gd_posttypes = !empty($gd_posttypes) && is_array($gd_posttypes) ? $gd_posttypes : geodir_get_posttypes();
19 19
     
20
-    if ( !empty( $post_type ) && !empty( $gd_posttypes ) && in_array( $post_type, $gd_posttypes ) ) {
20
+    if (!empty($post_type) && !empty($gd_posttypes) && in_array($post_type, $gd_posttypes)) {
21 21
         return true;
22 22
     }
23 23
     
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
         return;
30 30
     }
31 31
     
32
-    if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
32
+    if (!(defined('DOING_AJAX') && DOING_AJAX)) {
33 33
         // Add  fields for force upgrade
34
-        if ( defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column') ) {
35
-            geodir_add_column_if_not_exist( INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0' );
34
+        if (defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column')) {
35
+            geodir_add_column_if_not_exist(INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0');
36 36
             
37 37
             update_option('wpinv_gdp_column', '1');
38 38
         }
@@ -40,39 +40,39 @@  discard block
 block discarded – undo
40 40
         wpinv_merge_gd_packages_to_items();
41 41
     }
42 42
 }
43
-add_action( 'admin_init', 'wpinv_geodir_integration' );
43
+add_action('admin_init', 'wpinv_geodir_integration');
44 44
 
45
-function wpinv_get_gdp_package_type( $item_types ) {
46
-    if ( wpinv_pm_active() ) {
47
-        $item_types['package'] = __( 'Package', 'invoicing' );
45
+function wpinv_get_gdp_package_type($item_types) {
46
+    if (wpinv_pm_active()) {
47
+        $item_types['package'] = __('Package', 'invoicing');
48 48
     }
49 49
         
50 50
     return $item_types;
51 51
 }
52
-add_filter( 'wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1 );
52
+add_filter('wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1);
53 53
 
54 54
 function wpinv_update_package_item($package_id) {
55 55
     return wpinv_merge_gd_package_to_item($package_id, true);
56 56
 }
57 57
 add_action('geodir_after_save_package', 'wpinv_update_package_item', 10, 1);
58 58
 
59
-function wpinv_merge_gd_packages_to_items( $force = false ) {    
60
-    if ( $merged = get_option( 'wpinv_merge_gd_packages' ) && !$force ) {
59
+function wpinv_merge_gd_packages_to_items($force = false) {    
60
+    if ($merged = get_option('wpinv_merge_gd_packages') && !$force) {
61 61
         return true;
62 62
     }
63 63
 
64
-    if(!function_exists('geodir_package_list_info')){
64
+    if (!function_exists('geodir_package_list_info')) {
65 65
         return false;
66 66
     }
67 67
     
68 68
     $packages = geodir_package_list_info();
69 69
     
70
-    foreach ( $packages as $key => $package ) {
71
-        wpinv_merge_gd_package_to_item( $package->pid, $force, $package );
70
+    foreach ($packages as $key => $package) {
71
+        wpinv_merge_gd_package_to_item($package->pid, $force, $package);
72 72
     }
73 73
     
74
-    if ( !$merged ) {
75
-        update_option( 'wpinv_merge_gd_packages', 1 );
74
+    if (!$merged) {
75
+        update_option('wpinv_merge_gd_packages', 1);
76 76
     }
77 77
     
78 78
     return true;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 
102 102
     $package = empty($package) ? geodir_get_package_info_by_id($package_id, '') : $package;
103 103
 
104
-    if ( empty($package) || !wpinv_is_gd_post_type( $package->post_type ) ) {
104
+    if (empty($package) || !wpinv_is_gd_post_type($package->post_type)) {
105 105
         return false;
106 106
     }
107 107
         
@@ -110,17 +110,17 @@  discard block
 block discarded – undo
110 110
     $meta['custom_id']              = $package_id;
111 111
     $meta['custom_singular_name']   = get_post_type_singular_label($package->post_type);
112 112
     $meta['custom_name']            = get_post_type_plural_label($package->post_type);
113
-    $meta['price']                  = wpinv_round_amount( $package->amount );
113
+    $meta['price']                  = wpinv_round_amount($package->amount);
114 114
     $meta['vat_rule']               = 'digital';
115 115
     $meta['vat_class']              = '_standard';
116 116
     
117
-    if ( !empty( $package->sub_active ) ) {
118
-        $sub_num_trial_days = absint( $package->sub_num_trial_days );
117
+    if (!empty($package->sub_active)) {
118
+        $sub_num_trial_days = absint($package->sub_num_trial_days);
119 119
         
120 120
         $meta['is_recurring']       = 1;
121 121
         $meta['recurring_period']   = $package->sub_units;
122
-        $meta['recurring_interval'] = absint( $package->sub_units_num );
123
-        $meta['recurring_limit']    = absint( $package->sub_units_num_times );
122
+        $meta['recurring_interval'] = absint($package->sub_units_num);
123
+        $meta['recurring_limit']    = absint($package->sub_units_num_times);
124 124
         $meta['free_trial']         = $sub_num_trial_days > 0 ? 1 : 0;
125 125
         $meta['trial_period']       = $package->sub_num_trial_units;
126 126
         $meta['trial_interval']     = $sub_num_trial_days;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         $meta['trial_interval']     = '';
135 135
     }
136 136
     
137
-    $data  = array( 
137
+    $data = array( 
138 138
         'post_title'    => $package->title,
139 139
         'post_excerpt'  => $package->title_desc,
140 140
         'post_status'   => $package->status == 1 ? 'publish' : 'pending',
@@ -151,48 +151,48 @@  discard block
 block discarded – undo
151 151
     return $item;
152 152
 }
153 153
 
154
-function wpinv_gdp_to_wpi_gateway( $payment_method ) {
155
-    switch( $payment_method ) {
154
+function wpinv_gdp_to_wpi_gateway($payment_method) {
155
+    switch ($payment_method) {
156 156
         case 'prebanktransfer':
157 157
             $gateway = 'bank_transfer';
158 158
         break;
159 159
         default:
160
-            $gateway = empty( $payment_method ) ? 'manual' : $payment_method;
160
+            $gateway = empty($payment_method) ? 'manual' : $payment_method;
161 161
         break;
162 162
     }
163 163
     
164
-    return apply_filters( 'wpinv_gdp_to_wpi_gateway', $gateway, $payment_method );
164
+    return apply_filters('wpinv_gdp_to_wpi_gateway', $gateway, $payment_method);
165 165
 }
166 166
 
167
-function wpinv_gdp_to_wpi_gateway_title( $payment_method ) {
168
-    $gateway = wpinv_gdp_to_wpi_gateway( $payment_method );
167
+function wpinv_gdp_to_wpi_gateway_title($payment_method) {
168
+    $gateway = wpinv_gdp_to_wpi_gateway($payment_method);
169 169
     
170
-    $gateway_title = wpinv_get_gateway_checkout_label( $gateway );
170
+    $gateway_title = wpinv_get_gateway_checkout_label($gateway);
171 171
     
172
-    if ( $gateway == $gateway_title ) {
173
-        $gateway_title = geodir_payment_method_title( $gateway );
172
+    if ($gateway == $gateway_title) {
173
+        $gateway_title = geodir_payment_method_title($gateway);
174 174
     }
175 175
     
176
-    return apply_filters( 'wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method );
176
+    return apply_filters('wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method);
177 177
 }
178 178
 
179 179
 function wpinv_print_checkout_errors() {
180 180
     global $wpi_session;
181 181
     wpinv_print_errors();
182 182
 }
183
-add_action( 'geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10 );
183
+add_action('geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10);
184 184
 
185
-function wpinv_cpt_save( $invoice_id, $update = false, $pre_status = NULL ) {
185
+function wpinv_cpt_save($invoice_id, $update = false, $pre_status = NULL) {
186 186
     global $wpi_nosave, $wpi_zero_tax, $wpi_gdp_inv_merge;
187 187
     
188
-    $invoice_info = geodir_get_invoice( $invoice_id );
188
+    $invoice_info = geodir_get_invoice($invoice_id);
189 189
     
190
-    $wpi_invoice_id  = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : 0;
190
+    $wpi_invoice_id  = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : 0;
191 191
     
192 192
     if (!empty($invoice_info)) {
193
-        $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice( $wpi_invoice_id ) : NULL;
193
+        $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice($wpi_invoice_id) : NULL;
194 194
         
195
-        if ( !empty( $wpi_invoice ) ) { // update invoice
195
+        if (!empty($wpi_invoice)) { // update invoice
196 196
             $save = false;
197 197
             if ($invoice_info->coupon_code !== $wpi_invoice->discount_code || (float)$invoice_info->discount < (float)$wpi_invoice->discount || (float)$invoice_info->discount > (float)$wpi_invoice->discount) {
198 198
                 $save = true;
@@ -202,16 +202,16 @@  discard block
 block discarded – undo
202 202
             
203 203
             if ($invoice_info->paymentmethod !== $wpi_invoice->gateway) {
204 204
                 $save = true;
205
-                $gateway = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : '';
206
-                $gateway = wpinv_gdp_to_wpi_gateway( $gateway );
207
-                $gateway_title = wpinv_gdp_to_wpi_gateway_title( $gateway );
208
-                $wpi_invoice->set('gateway', $gateway );
209
-                $wpi_invoice->set('gateway_title', $gateway_title );
205
+                $gateway = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : '';
206
+                $gateway = wpinv_gdp_to_wpi_gateway($gateway);
207
+                $gateway_title = wpinv_gdp_to_wpi_gateway_title($gateway);
208
+                $wpi_invoice->set('gateway', $gateway);
209
+                $wpi_invoice->set('gateway_title', $gateway_title);
210 210
             }
211 211
             
212
-            if ( ( $status = wpinv_gdp_to_wpi_status( $invoice_info->status ) ) !== $wpi_invoice->status ) {
212
+            if (($status = wpinv_gdp_to_wpi_status($invoice_info->status)) !== $wpi_invoice->status) {
213 213
                 $save = true;
214
-                $wpi_invoice->set( 'status', $status );
214
+                $wpi_invoice->set('status', $status);
215 215
             }
216 216
             
217 217
             if ($save) {
@@ -222,16 +222,16 @@  discard block
 block discarded – undo
222 222
             
223 223
             return $wpi_invoice;
224 224
         } else { // create invoice
225
-            $user_info = get_userdata( $invoice_info->user_id );
225
+            $user_info = get_userdata($invoice_info->user_id);
226 226
             
227
-            if ( !empty( $pre_status ) ) {
227
+            if (!empty($pre_status)) {
228 228
                 $invoice_info->status = $pre_status;
229 229
             }
230
-            $status = wpinv_gdp_to_wpi_status( $invoice_info->status );
230
+            $status = wpinv_gdp_to_wpi_status($invoice_info->status);
231 231
             
232 232
             $wpi_zero_tax = false;
233 233
             
234
-            if ( $wpi_gdp_inv_merge && in_array( $status, array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
234
+            if ($wpi_gdp_inv_merge && in_array($status, array('publish', 'wpi-processing', 'wpi-renewal'))) {
235 235
                 $wpi_zero_tax = true;
236 236
             }
237 237
             
@@ -241,13 +241,13 @@  discard block
 block discarded – undo
241 241
             $invoice_data['user_id']        = $invoice_info->user_id;
242 242
             $invoice_data['created_via']    = 'API';
243 243
             
244
-            if ( !empty( $invoice_info->date ) ) {
245
-                $invoice_data['created_date']   = $invoice_info->date;
244
+            if (!empty($invoice_info->date)) {
245
+                $invoice_data['created_date'] = $invoice_info->date;
246 246
             }
247 247
             
248
-            $paymentmethod = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : '';
249
-            $paymentmethod = wpinv_gdp_to_wpi_gateway( $paymentmethod );
250
-            $payment_method_title = wpinv_gdp_to_wpi_gateway_title( $paymentmethod );
248
+            $paymentmethod = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : '';
249
+            $paymentmethod = wpinv_gdp_to_wpi_gateway($paymentmethod);
250
+            $payment_method_title = wpinv_gdp_to_wpi_gateway_title($paymentmethod);
251 251
             
252 252
             $invoice_data['payment_details'] = array( 
253 253
                 'gateway'           => $paymentmethod, 
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
                 'currency'          => geodir_get_currency_type(),
256 256
             );
257 257
             
258
-            $user_address = wpinv_get_user_address( $invoice_info->user_id, false );
258
+            $user_address = wpinv_get_user_address($invoice_info->user_id, false);
259 259
             
260 260
             $invoice_data['user_info'] = array( 
261 261
                 'user_id'       => $invoice_info->user_id, 
@@ -278,8 +278,8 @@  discard block
 block discarded – undo
278 278
             
279 279
             $post_item = wpinv_get_gd_package_item($invoice_info->package_id);
280 280
             
281
-            if ( !empty( $post_item ) ) {
282
-                $cart_details  = array();
281
+            if (!empty($post_item)) {
282
+                $cart_details = array();
283 283
                 $cart_details[] = array(
284 284
                     'id'            => $post_item->ID,
285 285
                     'name'          => $post_item->get_name(),
@@ -293,19 +293,19 @@  discard block
 block discarded – undo
293 293
                     ),
294 294
                 );
295 295
                 
296
-                $invoice_data['cart_details']  = $cart_details;
296
+                $invoice_data['cart_details'] = $cart_details;
297 297
             }
298 298
 
299
-            $data = array( 'invoice' => $invoice_data );
299
+            $data = array('invoice' => $invoice_data);
300 300
 
301 301
             $wpinv_api = new WPInv_API();
302
-            $data = $wpinv_api->insert_invoice( $data );
302
+            $data = $wpinv_api->insert_invoice($data);
303 303
             
304
-            if ( is_wp_error( $data ) ) {
305
-                wpinv_error_log( 'WPInv_Invoice: ' . $data->get_error_message() );
304
+            if (is_wp_error($data)) {
305
+                wpinv_error_log('WPInv_Invoice: ' . $data->get_error_message());
306 306
             } else {
307
-                if ( !empty( $data ) ) {
308
-                    update_post_meta( $data->ID, '_wpinv_gdp_id', $invoice_id );
307
+                if (!empty($data)) {
308
+                    update_post_meta($data->ID, '_wpinv_gdp_id', $invoice_id);
309 309
                     
310 310
                     $update_data = array();
311 311
                     $update_data['tax_amount'] = $data->get_tax();
@@ -313,14 +313,14 @@  discard block
 block discarded – undo
313 313
                     $update_data['invoice_id'] = $data->ID;
314 314
                     
315 315
                     global $wpdb;
316
-                    $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $invoice_id ) );
316
+                    $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $invoice_id));
317 317
                     
318 318
                     return $data;
319 319
                 } else {
320
-                    if ( $update ) {
321
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to update invoice.', 'invoicing' ) );
320
+                    if ($update) {
321
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to update invoice.', 'invoicing'));
322 322
                     } else {
323
-                        wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to create invoice.', 'invoicing' ) );
323
+                        wpinv_error_log('WPInv_Invoice: ' . __('Fail to create invoice.', 'invoicing'));
324 324
                     }
325 325
                 }
326 326
             }
@@ -331,59 +331,59 @@  discard block
 block discarded – undo
331 331
 }
332 332
 add_action('geodir_payment_invoice_created', 'wpinv_cpt_save', 11, 3);
333 333
 
334
-function wpinv_cpt_update( $invoice_id ) {
335
-    return wpinv_cpt_save( $invoice_id, true );
334
+function wpinv_cpt_update($invoice_id) {
335
+    return wpinv_cpt_save($invoice_id, true);
336 336
 }
337 337
 add_action('geodir_payment_invoice_updated', 'wpinv_cpt_update', 11, 1);
338 338
 
339
-function wpinv_payment_status_changed( $invoice_id, $new_status, $old_status = 'pending', $subscription = false ) {
340
-    $invoice_info = geodir_get_invoice( $invoice_id );
341
-    if ( empty( $invoice_info ) ) {
339
+function wpinv_payment_status_changed($invoice_id, $new_status, $old_status = 'pending', $subscription = false) {
340
+    $invoice_info = geodir_get_invoice($invoice_id);
341
+    if (empty($invoice_info)) {
342 342
         return false;
343 343
     }
344 344
 
345
-    $invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
346
-    if ( !empty( $invoice ) ) {
345
+    $invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
346
+    if (!empty($invoice)) {
347 347
         $new_status = wpinv_gdp_to_wpi_status($new_status);
348
-        $invoice    = wpinv_update_payment_status( $invoice->ID, $new_status );
348
+        $invoice    = wpinv_update_payment_status($invoice->ID, $new_status);
349 349
     } else {
350
-        $invoice = wpinv_cpt_save( $invoice_id );
350
+        $invoice = wpinv_cpt_save($invoice_id);
351 351
     }
352 352
     
353 353
     return $invoice;
354 354
 }
355
-add_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
355
+add_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
356 356
 
357
-function wpinv_transaction_details_note( $invoice_id, $html ) {
358
-    $invoice_info = geodir_get_invoice( $invoice_id );
359
-    if ( empty( $invoice_info ) ) {
357
+function wpinv_transaction_details_note($invoice_id, $html) {
358
+    $invoice_info = geodir_get_invoice($invoice_id);
359
+    if (empty($invoice_info)) {
360 360
         return false;
361 361
     }
362 362
 
363
-    $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : NULL;
363
+    $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : NULL;
364 364
     
365
-    if ( !$wpi_invoice_id ) {
366
-        $invoice = wpinv_cpt_save( $invoice_id, false, $old_status );
365
+    if (!$wpi_invoice_id) {
366
+        $invoice = wpinv_cpt_save($invoice_id, false, $old_status);
367 367
         
368
-        if ( !empty( $invoice ) ) {
368
+        if (!empty($invoice)) {
369 369
             $wpi_invoice_id = $invoice->ID;
370 370
         }
371 371
     }
372 372
 
373
-    $invoice = wpinv_get_invoice( $wpi_invoice_id );
373
+    $invoice = wpinv_get_invoice($wpi_invoice_id);
374 374
     
375
-    if ( empty( $invoice ) ) {
375
+    if (empty($invoice)) {
376 376
         return false;
377 377
     }
378 378
     
379
-    return $invoice->add_note( $html, true );
379
+    return $invoice->add_note($html, true);
380 380
 }
381
-add_action( 'geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2 );
381
+add_action('geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2);
382 382
 
383
-function wpinv_gdp_to_wpi_status( $status ) {
383
+function wpinv_gdp_to_wpi_status($status) {
384 384
     $inv_status = $status ? $status : 'pending';
385 385
     
386
-    switch ( $status ) {
386
+    switch ($status) {
387 387
         case 'confirmed':
388 388
             $inv_status = 'publish';
389 389
         break;
@@ -403,10 +403,10 @@  discard block
 block discarded – undo
403 403
     return $inv_status;
404 404
 }
405 405
 
406
-function wpinv_wpi_to_gdp_status( $status ) {
406
+function wpinv_wpi_to_gdp_status($status) {
407 407
     $inv_status = $status ? $status : 'pending';
408 408
     
409
-    switch ( $status ) {
409
+    switch ($status) {
410 410
         case 'publish':
411 411
         case 'wpi-processing':
412 412
         case 'wpi-renewal':
@@ -429,72 +429,72 @@  discard block
 block discarded – undo
429 429
     return $inv_status;
430 430
 }
431 431
 
432
-function wpinv_wpi_to_gdp_id( $invoice_id ) {
432
+function wpinv_wpi_to_gdp_id($invoice_id) {
433 433
     global $wpdb;
434 434
     
435
-    return $wpdb->get_var( $wpdb->prepare( "SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array( (int)$invoice_id ) ) );
435
+    return $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array((int)$invoice_id)));
436 436
 }
437 437
 
438
-function wpinv_gdp_to_wpi_id( $invoice_id ) {
439
-    $invoice = geodir_get_invoice( $invoice_id );    
440
-    return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false);
438
+function wpinv_gdp_to_wpi_id($invoice_id) {
439
+    $invoice = geodir_get_invoice($invoice_id);    
440
+    return (empty($invoice->invoice_id) ? $invoice->invoice_id : false);
441 441
 }
442 442
 
443
-function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) {
443
+function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) {
444 444
     global $wpdb;
445 445
     
446
-    if ( !empty( $wpi_nosave ) ) {
446
+    if (!empty($wpi_nosave)) {
447 447
         return;
448 448
     }
449 449
     
450
-    $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID );
450
+    $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID);
451 451
     
452
-    if ( $gdp_invoice_id > 0 ) {
452
+    if ($gdp_invoice_id > 0) {
453 453
         $update_data = array();
454 454
         $update_data['tax_amount']      = $invoice->tax;
455 455
         $update_data['paied_amount']    = $invoice->total;
456 456
         $update_data['discount']        = $invoice->discount;
457 457
         $update_data['coupon_code']     = $invoice->discount_code;
458 458
         
459
-        $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) );
459
+        $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id));
460 460
     }
461 461
     
462 462
     return;
463 463
 }
464 464
 //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 );
465 465
 
466
-function wpinv_gdp_to_wpi_invoice( $invoice_id ) {
467
-    $invoice = geodir_get_invoice( $invoice_id );
468
-    if ( empty( $invoice->invoice_id ) ) {
466
+function wpinv_gdp_to_wpi_invoice($invoice_id) {
467
+    $invoice = geodir_get_invoice($invoice_id);
468
+    if (empty($invoice->invoice_id)) {
469 469
         return false;
470 470
     }
471 471
     
472
-    return wpinv_get_invoice( $invoice->invoice_id );
472
+    return wpinv_get_invoice($invoice->invoice_id);
473 473
 }
474 474
 
475
-function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) {
476
-    $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id );
477
-    if ( empty( $invoice ) ) {
475
+function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) {
476
+    $invoice = wpinv_gdp_to_wpi_invoice($invoice_id);
477
+    if (empty($invoice)) {
478 478
         return $status;
479 479
     }
480 480
 
481
-    if ( $status === 1 || $status === 0 ) {
482
-        if ( $status === 1 ) {
483
-            $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() );
481
+    if ($status === 1 || $status === 0) {
482
+        if ($status === 1) {
483
+            $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal());
484 484
         } else {
485 485
             $discount = '';
486 486
             $coupon_code = '';
487 487
         }
488 488
         
489
-        $invoice->set( 'discount', $discount );
490
-        $invoice->set( 'discount_code', $coupon_code );
489
+        $invoice->set('discount', $discount);
490
+        $invoice->set('discount_code', $coupon_code);
491 491
         $invoice->save();
492 492
         $invoice->recalculate_total();
493 493
     }
494 494
     
495 495
     return $status;
496 496
 }
497
-add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 );
497
+add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3);
498 498
 
499 499
 function wpinv_merge_gd_invoices() {
500 500
     if (!defined('GEODIRPAYMENT_VERSION')) {
@@ -502,157 +502,157 @@  discard block
 block discarded – undo
502 502
     }
503 503
     ?>
504 504
     <tr>
505
-        <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td>
506
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td>
507
-        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
505
+        <td><?php _e('Merge Price Packages', 'invoicing'); ?></td>
506
+        <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td>
507
+        <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
508 508
     </tr>
509 509
     <tr>
510
-        <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td>
511
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td>
512
-        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
510
+        <td><?php _e('Merge Invoices', 'invoicing'); ?></td>
511
+        <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td>
512
+        <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
513 513
     </tr>
514 514
 	<tr>
515
-        <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td>
516
-        <td><p><?php _e( 'Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing' ); ?></p></td>
517
-        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
515
+        <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td>
516
+        <td><p><?php _e('Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing'); ?></p></td>
517
+        <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
518 518
     </tr>
519 519
     <tr>
520
-        <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td>
521
-        <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td>
522
-        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td>
520
+        <td><?php _e('Merge Coupons', 'invoicing'); ?></td>
521
+        <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td>
522
+        <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td>
523 523
     </tr>
524 524
     <?php
525 525
 }
526
-add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 );
526
+add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10);
527 527
 
528 528
 function wpinv_tool_merge_packages() {
529 529
     $packages = geodir_package_list_info();
530 530
     
531 531
     $count = 0;
532 532
     
533
-    if ( !empty( $packages ) ) {
533
+    if (!empty($packages)) {
534 534
         $success = true;
535 535
         
536
-        foreach ( $packages as $key => $package ) {
536
+        foreach ($packages as $key => $package) {
537 537
             $item = wpinv_get_item_by('custom_id', $package->pid, 'package');
538
-            if ( !empty( $item ) ) {
538
+            if (!empty($item)) {
539 539
                 continue;
540 540
             }
541 541
             
542
-            $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package );
542
+            $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package);
543 543
             
544
-            if ( !empty( $merged ) ) {
545
-                wpinv_error_log( 'Package merge S : ' . $package->pid );
544
+            if (!empty($merged)) {
545
+                wpinv_error_log('Package merge S : ' . $package->pid);
546 546
                 $count++;
547 547
             } else {
548
-                wpinv_error_log( 'Package merge F : ' . $package->pid );
548
+                wpinv_error_log('Package merge F : ' . $package->pid);
549 549
             }
550 550
         }
551 551
         
552
-        if ( $count > 0 ) {
553
-            $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count );
552
+        if ($count > 0) {
553
+            $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count);
554 554
         } else {
555
-            $message = __( 'No price packages merged.', 'invoicing' );
555
+            $message = __('No price packages merged.', 'invoicing');
556 556
         }
557 557
     } else {
558 558
         $success = false;
559
-        $message = __( 'No price packages found to merge!', 'invoicing' );
559
+        $message = __('No price packages found to merge!', 'invoicing');
560 560
     }
561 561
     
562 562
     $response = array();
563 563
     $response['success'] = $success;
564 564
     $response['data']['message'] = $message;
565
-    wp_send_json( $response );
565
+    wp_send_json($response);
566 566
 }
567
-add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' );
567
+add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages');
568 568
 
569 569
 function wpinv_tool_merge_invoices() {
570 570
     global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates;
571 571
     
572 572
     $sql = "SELECT `gdi`.`id`, `gdi`.`date`, `gdi`.`date_updated` FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NULL ORDER BY `gdi`.`id` ASC";
573 573
 
574
-    $items = $wpdb->get_results( $sql );
574
+    $items = $wpdb->get_results($sql);
575 575
     
576 576
     $count = 0;
577 577
     
578
-    if ( !empty( $items ) ) {
578
+    if (!empty($items)) {
579 579
         $success = true;
580 580
         $wpi_gdp_inv_merge = true;
581 581
         
582
-        foreach ( $items as $item ) {
582
+        foreach ($items as $item) {
583 583
             $wpi_tax_rates = NULL;
584 584
             
585
-            $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" );
585
+            $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'");
586 586
             
587
-            $merged = wpinv_cpt_save( $item->id );
587
+            $merged = wpinv_cpt_save($item->id);
588 588
             
589
-            if ( !empty( $merged ) && !empty( $merged->ID ) ) {
589
+            if (!empty($merged) && !empty($merged->ID)) {
590 590
                 $count++;
591 591
                 
592
-                $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' );
593
-                $post_date_gmt = get_gmt_from_date( $post_date );
594
-                $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
595
-                $post_modified_gmt = get_gmt_from_date( $post_modified );
592
+                $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql');
593
+                $post_date_gmt = get_gmt_from_date($post_date);
594
+                $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date;
595
+                $post_modified_gmt = get_gmt_from_date($post_modified);
596 596
                 
597
-                $wpdb->update( $wpdb->posts, array( 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt ), array( 'ID' => $merged->ID ) );
597
+                $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt), array('ID' => $merged->ID));
598 598
                 
599
-                if ( $merged->is_paid() ) {
600
-                    update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified );
599
+                if ($merged->is_paid()) {
600
+                    update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified);
601 601
                 }
602 602
                 
603
-                clean_post_cache( $merged->ID );
603
+                clean_post_cache($merged->ID);
604 604
                 
605
-                wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID );
605
+                wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID);
606 606
             } else {
607
-                wpinv_error_log( 'Invoice merge F : ' . $item->id );
607
+                wpinv_error_log('Invoice merge F : ' . $item->id);
608 608
             }
609 609
         }
610 610
         
611 611
         $wpi_gdp_inv_merge = false;
612 612
         
613
-        if ( $count > 0 ) {
614
-            $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count );
613
+        if ($count > 0) {
614
+            $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count);
615 615
         } else {
616
-            $message = __( 'No invoices merged.', 'invoicing' );
616
+            $message = __('No invoices merged.', 'invoicing');
617 617
         }
618 618
     } else {
619 619
         $success = false;
620
-        $message = __( 'No invoices found to merge!', 'invoicing' );
620
+        $message = __('No invoices found to merge!', 'invoicing');
621 621
     }
622 622
     
623 623
     $response = array();
624 624
     $response['success'] = $success;
625 625
     $response['data']['message'] = $message;
626
-    wp_send_json( $response );
626
+    wp_send_json($response);
627 627
 }
628
-add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' );
628
+add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices');
629 629
 
630 630
 function wpinv_tool_merge_coupons() {
631 631
     global $wpdb;
632 632
     
633 633
     $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC";
634
-    $items = $wpdb->get_results( $sql );
634
+    $items = $wpdb->get_results($sql);
635 635
     $count = 0;
636 636
     
637
-    if ( !empty( $items ) ) {
637
+    if (!empty($items)) {
638 638
         $success = true;
639 639
         
640
-        foreach ( $items as $item ) {
641
-            if ( wpinv_get_discount_by_code( $item->coupon_code ) ) {
640
+        foreach ($items as $item) {
641
+            if (wpinv_get_discount_by_code($item->coupon_code)) {
642 642
                 continue;
643 643
             }
644 644
             
645 645
             $args = array(
646 646
                 'post_type'   => 'wpi_discount',
647 647
                 'post_title'  => $item->coupon_code,
648
-                'post_status' => !empty( $item->status ) ? 'publish' : 'pending'
648
+                'post_status' => !empty($item->status) ? 'publish' : 'pending'
649 649
             );
650 650
 
651
-            $merged = wp_insert_post( $args );
651
+            $merged = wp_insert_post($args);
652 652
             
653 653
             $item_id = $item->cid;
654 654
             
655
-            if ( $merged ) {
655
+            if ($merged) {
656 656
                 $meta = array(
657 657
                     'code'              => $item->coupon_code,
658 658
                     'type'              => $item->discount_type != 'per' ? 'flat' : 'percent',
@@ -660,65 +660,65 @@  discard block
 block discarded – undo
660 660
                     'max_uses'          => (int)$item->usage_limit,
661 661
                     'uses'              => (int)$item->usage_count,
662 662
                 );
663
-                wpinv_store_discount( $merged, $meta, get_post( $merged ) );
663
+                wpinv_store_discount($merged, $meta, get_post($merged));
664 664
                 
665 665
                 $count++;
666 666
                 
667
-                wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged );
667
+                wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged);
668 668
             } else {
669
-                wpinv_error_log( 'Coupon merge F : ' . $item_id );
669
+                wpinv_error_log('Coupon merge F : ' . $item_id);
670 670
             }
671 671
         }
672 672
         
673
-        if ( $count > 0 ) {
674
-            $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count );
673
+        if ($count > 0) {
674
+            $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count);
675 675
         } else {
676
-            $message = __( 'No coupons merged.', 'invoicing' );
676
+            $message = __('No coupons merged.', 'invoicing');
677 677
         }
678 678
     } else {
679 679
         $success = false;
680
-        $message = __( 'No coupons found to merge!', 'invoicing' );
680
+        $message = __('No coupons found to merge!', 'invoicing');
681 681
     }
682 682
     
683 683
     $response = array();
684 684
     $response['success'] = $success;
685 685
     $response['data']['message'] = $message;
686
-    wp_send_json( $response );
686
+    wp_send_json($response);
687 687
 }
688
-add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' );
688
+add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons');
689 689
 
690
-function wpinv_gdp_to_wpi_currency( $value, $option = '' ) {
690
+function wpinv_gdp_to_wpi_currency($value, $option = '') {
691 691
     return wpinv_get_currency();
692 692
 }
693
-add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 );
693
+add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2);
694 694
 
695
-function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) {
695
+function wpinv_gdp_to_wpi_currency_sign($value, $option = '') {
696 696
     return wpinv_currency_symbol();
697 697
 }
698
-add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 );
698
+add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2);
699 699
 
700
-function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) {
701
-    if ( !$display ) {
702
-        $price = wpinv_round_amount( $amount );
700
+function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) {
701
+    if (!$display) {
702
+        $price = wpinv_round_amount($amount);
703 703
     } else {
704
-        $price = wpinv_price( wpinv_format_amount( $amount ) );
704
+        $price = wpinv_price(wpinv_format_amount($amount));
705 705
     }
706 706
     
707 707
     return $price;
708 708
 }
709
-add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 );
709
+add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5);
710 710
 
711
-function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) {
711
+function wpinv_gdp_to_inv_checkout_redirect($redirect_url) {
712 712
     $invoice_id         = geodir_payment_cart_id();
713
-    $invoice_info       = geodir_get_invoice( $invoice_id );
714
-    $wpi_invoice        = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL;
713
+    $invoice_info       = geodir_get_invoice($invoice_id);
714
+    $wpi_invoice        = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL;
715 715
     
716
-    if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) {
717
-        $wpi_invoice_id = wpinv_cpt_save( $invoice_id );
718
-        $wpi_invoice    = wpinv_get_invoice( $wpi_invoice_id );
716
+    if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) {
717
+        $wpi_invoice_id = wpinv_cpt_save($invoice_id);
718
+        $wpi_invoice    = wpinv_get_invoice($wpi_invoice_id);
719 719
     }
720 720
     
721
-    if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) {
721
+    if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) {
722 722
         
723 723
         // Clear cart
724 724
         geodir_payment_clear_cart();
@@ -728,121 +728,121 @@  discard block
 block discarded – undo
728 728
     
729 729
     return $redirect_url;
730 730
 }
731
-add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 );
731
+add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1);
732 732
 
733
-function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) {    
734
-    if ( get_current_user_id() ) {        
735
-        $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url( wpinv_get_history_page_uri() ) . '">' . __( 'My Invoice History', 'invoicing' ) . '</a></li>';
733
+function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) {    
734
+    if (get_current_user_id()) {        
735
+        $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url(wpinv_get_history_page_uri()) . '">' . __('My Invoice History', 'invoicing') . '</a></li>';
736 736
     }
737 737
 
738 738
     return $dashboard_links;
739 739
 }
740
-add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' );
741
-remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' );
740
+add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link');
741
+remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link');
742 742
 
743
-function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) {
743
+function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) {
744 744
     if (!defined('GEODIRPAYMENT_VERSION')) {
745 745
         return false;
746 746
     }
747 747
     
748
-    $invoice    = wpinv_get_invoice( $invoice_id );
749
-    if ( empty( $invoice ) ) {
748
+    $invoice = wpinv_get_invoice($invoice_id);
749
+    if (empty($invoice)) {
750 750
         return false;
751 751
     }
752 752
     
753
-    remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 );
753
+    remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4);
754 754
     
755
-    $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id );
756
-    $new_status = wpinv_wpi_to_gdp_status( $new_status );
755
+    $invoice_id = wpinv_wpi_to_gdp_id($invoice_id);
756
+    $new_status = wpinv_wpi_to_gdp_status($new_status);
757 757
     
758
-    geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() );
758
+    geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring());
759 759
 }
760
-add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 );
760
+add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3);
761 761
 
762
-function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) {
763
-    $item = wpinv_get_item_by( 'custom_id', $gd_package_id, 'package' );
762
+function wpinv_gdp_to_wpi_delete_package($gd_package_id) {
763
+    $item = wpinv_get_item_by('custom_id', $gd_package_id, 'package');
764 764
     
765
-    if ( !empty( $item ) ) {
766
-        wpinv_remove_item( $item, true );
765
+    if (!empty($item)) {
766
+        wpinv_remove_item($item, true);
767 767
     }
768 768
 }
769
-add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ;
769
+add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1);
770 770
 
771
-function wpinv_can_delete_package_item( $return, $post_id ) {
772
-    if ( $return && function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && $package_id = get_post_meta( $post_id, '_wpinv_custom_id', true ) ) {
773
-        $gd_package = geodir_get_package_info_by_id( $package_id, '' );
771
+function wpinv_can_delete_package_item($return, $post_id) {
772
+    if ($return && function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && $package_id = get_post_meta($post_id, '_wpinv_custom_id', true)) {
773
+        $gd_package = geodir_get_package_info_by_id($package_id, '');
774 774
         
775
-        if ( !empty( $gd_package ) ) {
775
+        if (!empty($gd_package)) {
776 776
             $return = false;
777 777
         }
778 778
     }
779 779
 
780 780
     return $return;
781 781
 }
782
-add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 );
782
+add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2);
783 783
 
784
-function wpinv_package_item_classes( $classes, $class, $post_id ) {
784
+function wpinv_package_item_classes($classes, $class, $post_id) {
785 785
     global $typenow;
786 786
 
787
-    if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) {
788
-        if ( wpinv_item_in_use( $post_id ) ) {
787
+    if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) {
788
+        if (wpinv_item_in_use($post_id)) {
789 789
             $classes[] = 'wpi-inuse-pkg';
790
-        } else if ( !( function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && geodir_get_package_info_by_id( (int)get_post_meta( $post_id, '_wpinv_custom_id', true ), '' ) ) ) {
790
+        } else if (!(function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && geodir_get_package_info_by_id((int)get_post_meta($post_id, '_wpinv_custom_id', true), ''))) {
791 791
             $classes[] = 'wpi-delete-pkg';
792 792
         }
793 793
     }
794 794
 
795 795
     return $classes;
796 796
 }
797
-add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 );
797
+add_filter('post_class', 'wpinv_package_item_classes', 10, 3);
798 798
 
799
-function wpinv_gdp_package_type_info( $post ) {
800
-    if ( wpinv_pm_active() ) {
801
-        ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p>
799
+function wpinv_gdp_package_type_info($post) {
800
+    if (wpinv_pm_active()) {
801
+        ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p>
802 802
         <?php
803 803
     }
804 804
 }
805
-add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ;
805
+add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1);
806 806
 
807
-function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) {
807
+function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) {
808 808
     global $wpi_zero_tax;
809 809
 
810
-    if ( $wpi_zero_tax ) {
810
+    if ($wpi_zero_tax) {
811 811
         $is_taxable = false;
812 812
     }
813 813
 
814 814
     return $is_taxable;
815 815
 }
816
-add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ;
816
+add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4);
817 817
 
818 818
 function wpinv_tool_merge_fix_taxes() {
819 819
     global $wpdb;
820 820
     
821 821
 	$sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'";
822
-	$items = $wpdb->get_results( $sql );
822
+	$items = $wpdb->get_results($sql);
823 823
 	
824
-	if ( !empty( $items ) ) {
825
-		foreach ( $items as $item ) {
826
-			if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) {
827
-				update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' );
824
+	if (!empty($items)) {
825
+		foreach ($items as $item) {
826
+			if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') {
827
+				update_post_meta($item->ID, '_wpinv_vat_class', '_standard');
828 828
 			}
829 829
 		}
830 830
 	}
831 831
 		
832 832
     $sql = "SELECT `p`.`ID`, gdi.id AS gdp_id FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NOT NULL AND p.post_status NOT IN( 'publish', 'wpi-processing', 'wpi-renewal' ) ORDER BY `gdi`.`id` ASC";
833
-    $items = $wpdb->get_results( $sql );
833
+    $items = $wpdb->get_results($sql);
834 834
 	
835
-	if ( !empty( $items ) ) {
835
+	if (!empty($items)) {
836 836
 		$success = false;
837
-        $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' );
837
+        $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing');
838 838
 		
839 839
 		global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates;
840 840
 		
841
-		foreach ( $items as $item ) {
841
+		foreach ($items as $item) {
842 842
 			$wpi_tax_rates = NULL;               
843 843
 			$data = wpinv_get_invoice($item->ID);
844 844
 
845
-			if ( empty( $data ) ) {
845
+			if (empty($data)) {
846 846
 				continue;
847 847
 			}
848 848
 			
@@ -850,51 +850,51 @@  discard block
 block discarded – undo
850 850
 			
851 851
 			$data_session                   = array();
852 852
 			$data_session['invoice_id']     = $data->ID;
853
-			$data_session['cart_discounts'] = $data->get_discounts( true );
853
+			$data_session['cart_discounts'] = $data->get_discounts(true);
854 854
 			
855
-			wpinv_set_checkout_session( $data_session );
855
+			wpinv_set_checkout_session($data_session);
856 856
 			
857 857
 			$wpi_userID         = (int)$data->get_user_id();
858 858
 			$_POST['country']   = !empty($data->country) ? $data->country : wpinv_get_default_country();
859 859
 				
860
-			$data->country      = sanitize_text_field( $_POST['country'] );
861
-			$data->set( 'country', sanitize_text_field( $_POST['country'] ) );
860
+			$data->country      = sanitize_text_field($_POST['country']);
861
+			$data->set('country', sanitize_text_field($_POST['country']));
862 862
 			
863 863
 			$wpinv_ip_address_country = $data->country;
864 864
 			
865 865
 			$data->recalculate_totals(true);
866 866
 			
867
-			wpinv_set_checkout_session( $checkout_session );
867
+			wpinv_set_checkout_session($checkout_session);
868 868
 			
869 869
 			$update_data = array();
870 870
 			$update_data['tax_amount'] = $data->get_tax();
871 871
 			$update_data['paied_amount'] = $data->get_total();
872 872
 			$update_data['invoice_id'] = $data->ID;
873 873
 			
874
-			$wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) );
874
+			$wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id));
875 875
 		}
876 876
 	} else {
877 877
         $success = false;
878
-        $message = __( 'No invoices found to fix taxes!', 'invoicing' );
878
+        $message = __('No invoices found to fix taxes!', 'invoicing');
879 879
     }
880 880
 	
881 881
 	$response = array();
882 882
     $response['success'] = $success;
883 883
     $response['data']['message'] = $message;
884
-    wp_send_json( $response );
884
+    wp_send_json($response);
885 885
 }
886
-add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' );
887
-remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 );
886
+add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes');
887
+remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2);
888 888
 
889
-function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) {
890
-    if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) {
891
-        if ( $invoice->is_renewal() ) {
889
+function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) {
890
+    if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) {
891
+        if ($invoice->is_renewal()) {
892 892
             $invoice = $invoice->get_parent_payment();
893 893
         }
894 894
         
895
-        if ( !empty( $invoice ) ) {
896
-            wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() );
895
+        if (!empty($invoice)) {
896
+            wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status());
897 897
         }
898 898
     }
899 899
 }
900
-add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 );
901 900
\ No newline at end of file
901
+add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2);
902 902
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 1 patch
Spacing   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 class WPInv_Item {
6 6
     public $ID = 0;
@@ -33,26 +33,26 @@  discard block
 block discarded – undo
33 33
     public $filter;
34 34
 
35 35
 
36
-    public function __construct( $_id = false, $_args = array() ) {
37
-        $item = WP_Post::get_instance( $_id );
38
-        return $this->setup_item( $item );
36
+    public function __construct($_id = false, $_args = array()) {
37
+        $item = WP_Post::get_instance($_id);
38
+        return $this->setup_item($item);
39 39
     }
40 40
 
41
-    private function setup_item( $item ) {
42
-        if( ! is_object( $item ) ) {
41
+    private function setup_item($item) {
42
+        if (!is_object($item)) {
43 43
             return false;
44 44
         }
45 45
 
46
-        if( ! is_a( $item, 'WP_Post' ) ) {
46
+        if (!is_a($item, 'WP_Post')) {
47 47
             return false;
48 48
         }
49 49
 
50
-        if( 'wpi_item' !== $item->post_type ) {
50
+        if ('wpi_item' !== $item->post_type) {
51 51
             return false;
52 52
         }
53 53
 
54
-        foreach ( $item as $key => $value ) {
55
-            switch ( $key ) {
54
+        foreach ($item as $key => $value) {
55
+            switch ($key) {
56 56
                 default:
57 57
                     $this->$key = $value;
58 58
                     break;
@@ -62,38 +62,38 @@  discard block
 block discarded – undo
62 62
         return true;
63 63
     }
64 64
 
65
-    public function __get( $key ) {
66
-        if ( method_exists( $this, 'get_' . $key ) ) {
67
-            return call_user_func( array( $this, 'get_' . $key ) );
65
+    public function __get($key) {
66
+        if (method_exists($this, 'get_' . $key)) {
67
+            return call_user_func(array($this, 'get_' . $key));
68 68
         } else {
69
-            return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );
69
+            return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key));
70 70
         }
71 71
     }
72 72
 
73
-    public function create( $data = array(), $wp_error = false ) {
74
-        if ( $this->ID != 0 ) {
73
+    public function create($data = array(), $wp_error = false) {
74
+        if ($this->ID != 0) {
75 75
             return false;
76 76
         }
77 77
 
78 78
         $defaults = array(
79 79
             'post_type'   => 'wpi_item',
80 80
             'post_status' => 'draft',
81
-            'post_title'  => __( 'New Invoice Item', 'invoicing' )
81
+            'post_title'  => __('New Invoice Item', 'invoicing')
82 82
         );
83 83
 
84
-        $args = wp_parse_args( $data, $defaults );
84
+        $args = wp_parse_args($data, $defaults);
85 85
 
86
-        do_action( 'wpinv_item_pre_create', $args );
86
+        do_action('wpinv_item_pre_create', $args);
87 87
 
88
-        $id = wp_insert_post( $args, $wp_error );
88
+        $id = wp_insert_post($args, $wp_error);
89 89
         if ($wp_error && is_wp_error($id)) {
90 90
             return $id;
91 91
         }
92
-        if ( !$id ) {
92
+        if (!$id) {
93 93
             return false;
94 94
         }
95 95
         
96
-        $item = WP_Post::get_instance( $id );
96
+        $item = WP_Post::get_instance($id);
97 97
         
98 98
         if (!empty($item) && !empty($data['meta'])) {
99 99
             $this->ID = $item->ID;
@@ -101,47 +101,47 @@  discard block
 block discarded – undo
101 101
         }
102 102
         
103 103
         // Set custom id if not set.
104
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
105
-            $item->save_metas( array( 'custom_id' => $id ) );
104
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
105
+            $item->save_metas(array('custom_id' => $id));
106 106
         }
107 107
 
108
-        do_action( 'wpinv_item_create', $id, $args );
108
+        do_action('wpinv_item_create', $id, $args);
109 109
 
110
-        return $this->setup_item( $item );
110
+        return $this->setup_item($item);
111 111
     }
112 112
     
113
-    public function update( $data = array(), $wp_error = false ) {
114
-        if ( !$this->ID > 0 ) {
113
+    public function update($data = array(), $wp_error = false) {
114
+        if (!$this->ID > 0) {
115 115
             return false;
116 116
         }
117 117
         
118 118
         $data['ID'] = $this->ID;
119 119
 
120
-        do_action( 'wpinv_item_pre_update', $data );
120
+        do_action('wpinv_item_pre_update', $data);
121 121
         
122
-        $id = wp_update_post( $data, $wp_error );
122
+        $id = wp_update_post($data, $wp_error);
123 123
         if ($wp_error && is_wp_error($id)) {
124 124
             return $id;
125 125
         }
126 126
         
127
-        if ( !$id ) {
127
+        if (!$id) {
128 128
             return false;
129 129
         }
130 130
 
131
-        $item = WP_Post::get_instance( $id );
131
+        $item = WP_Post::get_instance($id);
132 132
         if (!empty($item) && !empty($data['meta'])) {
133 133
             $this->ID = $item->ID;
134 134
             $this->save_metas($data['meta']);
135 135
         }
136 136
         
137 137
         // Set custom id if not set.
138
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
139
-            $item->save_metas( array( 'custom_id' => $id ) );
138
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
139
+            $item->save_metas(array('custom_id' => $id));
140 140
         }
141 141
 
142
-        do_action( 'wpinv_item_update', $id, $data );
142
+        do_action('wpinv_item_update', $id, $data);
143 143
 
144
-        return $this->setup_item( $item );
144
+        return $this->setup_item($item);
145 145
     }
146 146
 
147 147
     public function get_ID() {
@@ -149,105 +149,105 @@  discard block
 block discarded – undo
149 149
     }
150 150
 
151 151
     public function get_name() {
152
-        return get_the_title( $this->ID );
152
+        return get_the_title($this->ID);
153 153
     }
154 154
     
155 155
     public function get_summary() {
156
-        return get_the_excerpt( $this->ID );
156
+        return get_the_excerpt($this->ID);
157 157
     }
158 158
 
159 159
     public function get_price() {
160
-        if ( ! isset( $this->price ) ) {
161
-            $this->price = get_post_meta( $this->ID, '_wpinv_price', true );
160
+        if (!isset($this->price)) {
161
+            $this->price = get_post_meta($this->ID, '_wpinv_price', true);
162 162
             
163
-            if ( $this->price ) {
164
-                $this->price = wpinv_sanitize_amount( $this->price );
163
+            if ($this->price) {
164
+                $this->price = wpinv_sanitize_amount($this->price);
165 165
             } else {
166 166
                 $this->price = 0;
167 167
             }
168 168
         }
169 169
         
170
-        return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID );
170
+        return apply_filters('wpinv_get_item_price', $this->price, $this->ID);
171 171
     }
172 172
     
173 173
     public function get_the_price() {
174
-        $item_price = wpinv_price( wpinv_format_amount( $this->price ) );
174
+        $item_price = wpinv_price(wpinv_format_amount($this->price));
175 175
         
176
-        return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );
176
+        return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID);
177 177
     }
178 178
     
179 179
     public function get_vat_rule() {
180 180
         global $wpinv_euvat;
181 181
         
182
-        if( !isset( $this->vat_rule ) ) {
183
-            $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true );
182
+        if (!isset($this->vat_rule)) {
183
+            $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true);
184 184
 
185
-            if ( empty( $this->vat_rule ) ) {        
185
+            if (empty($this->vat_rule)) {        
186 186
                 $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical';
187 187
             }
188 188
         }
189 189
         
190
-        return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID );
190
+        return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID);
191 191
     }
192 192
     
193 193
     public function get_vat_class() {
194
-        if( !isset( $this->vat_class ) ) {
195
-            $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true );
194
+        if (!isset($this->vat_class)) {
195
+            $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true);
196 196
 
197
-            if ( empty( $this->vat_class ) ) {        
197
+            if (empty($this->vat_class)) {        
198 198
                 $this->vat_class = '_standard';
199 199
             }
200 200
         }
201 201
         
202
-        return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID );
202
+        return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID);
203 203
     }
204 204
 
205 205
     public function get_type() {
206
-        if( ! isset( $this->type ) ) {
207
-            $this->type = get_post_meta( $this->ID, '_wpinv_type', true );
206
+        if (!isset($this->type)) {
207
+            $this->type = get_post_meta($this->ID, '_wpinv_type', true);
208 208
 
209
-            if ( empty( $this->type ) ) {
209
+            if (empty($this->type)) {
210 210
                 $this->type = 'custom';
211 211
             }
212 212
         }
213 213
 
214
-        return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID );
214
+        return apply_filters('wpinv_get_item_type', $this->type, $this->ID);
215 215
     }
216 216
     
217 217
     public function get_custom_id() {
218
-        $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true );
218
+        $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true);
219 219
 
220
-        return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID );
220
+        return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID);
221 221
     }
222 222
     
223 223
     public function get_custom_name() {
224
-        $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true );
224
+        $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true);
225 225
 
226
-        return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID );
226
+        return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID);
227 227
     }
228 228
     
229 229
     public function get_custom_singular_name() {
230
-        $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true );
230
+        $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true);
231 231
 
232
-        return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID );
232
+        return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID);
233 233
     }
234 234
     
235 235
     public function is_recurring() {
236
-        $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true );
236
+        $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true);
237 237
 
238
-        return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID );
238
+        return (bool)apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID);
239 239
 
240 240
     }
241 241
     
242
-    public function get_recurring_period( $full = false ) {
243
-        $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true );
242
+    public function get_recurring_period($full = false) {
243
+        $period = get_post_meta($this->ID, '_wpinv_recurring_period', true);
244 244
         
245
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
245
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
246 246
             $period = 'D';
247 247
         }
248 248
         
249
-        if ( $full ) {
250
-            switch( $period ) {
249
+        if ($full) {
250
+            switch ($period) {
251 251
                 case 'D':
252 252
                     $period = 'day';
253 253
                 break;
@@ -263,45 +263,45 @@  discard block
 block discarded – undo
263 263
             }
264 264
         }
265 265
 
266
-        return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID );
266
+        return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID);
267 267
 
268 268
     }
269 269
     
270 270
     public function get_recurring_interval() {
271
-        $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true );
271
+        $interval = (int)get_post_meta($this->ID, '_wpinv_recurring_interval', true);
272 272
         
273
-        if ( !$interval > 0 ) {
273
+        if (!$interval > 0) {
274 274
             $interval = 1;
275 275
         }
276 276
 
277
-        return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID );
277
+        return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID);
278 278
 
279 279
     }
280 280
     
281 281
     public function get_recurring_limit() {
282
-        $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true );
282
+        $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true);
283 283
 
284
-        return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID );
284
+        return (int)apply_filters('wpinv_item_recurring_limit', $limit, $this->ID);
285 285
 
286 286
     }
287 287
     
288 288
     public function has_free_trial() {
289
-        $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true );
290
-        $free_trial = $this->is_recurring() && !empty( $free_trial ) ? true : false;
289
+        $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true);
290
+        $free_trial = $this->is_recurring() && !empty($free_trial) ? true : false;
291 291
 
292
-        return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID );
292
+        return (bool)apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID);
293 293
 
294 294
     }
295 295
     
296
-    public function get_trial_period( $full = false ) {
297
-        $period = get_post_meta( $this->ID, '_wpinv_trial_period', true );
296
+    public function get_trial_period($full = false) {
297
+        $period = get_post_meta($this->ID, '_wpinv_trial_period', true);
298 298
         
299
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
299
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
300 300
             $period = 'D';
301 301
         }
302 302
         
303
-        if ( $full ) {
304
-            switch( $period ) {
303
+        if ($full) {
304
+            switch ($period) {
305 305
                 case 'D':
306 306
                     $period = 'day';
307 307
                 break;
@@ -317,47 +317,47 @@  discard block
 block discarded – undo
317 317
             }
318 318
         }
319 319
 
320
-        return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID );
320
+        return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID);
321 321
 
322 322
     }
323 323
     
324 324
     public function get_trial_interval() {
325
-        $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) );
325
+        $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true));
326 326
         
327
-        if ( !$interval > 0 ) {
327
+        if (!$interval > 0) {
328 328
             $interval = 1;
329 329
         }
330 330
 
331
-        return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID );
331
+        return apply_filters('wpinv_item_trial_interval', $interval, $this->ID);
332 332
 
333 333
     }
334 334
 
335 335
     public function is_free() {
336 336
         $is_free = false;
337 337
         
338
-        $price = get_post_meta( $this->ID, '_wpinv_price', true );
338
+        $price = get_post_meta($this->ID, '_wpinv_price', true);
339 339
 
340
-        if ( (float)$price == 0 ) {
340
+        if ((float)$price == 0) {
341 341
             $is_free = true;
342 342
         }
343 343
 
344
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID );
344
+        return (bool)apply_filters('wpinv_is_free_item', $is_free, $this->ID);
345 345
 
346 346
     }
347 347
     
348 348
     public function is_package() {
349 349
         $is_package = $this->get_type() == 'package' ? true : false;
350 350
 
351
-        return (bool) apply_filters( 'wpinv_is_package_item', $is_package, $this->ID );
351
+        return (bool)apply_filters('wpinv_is_package_item', $is_package, $this->ID);
352 352
 
353 353
     }
354 354
     
355
-    public function save_metas( $metas = array() ) {
356
-        if ( empty( $metas ) ) {
355
+    public function save_metas($metas = array()) {
356
+        if (empty($metas)) {
357 357
             return false;
358 358
         }
359 359
         
360
-        foreach ( $metas as $meta_key => $meta_value ) {
360
+        foreach ($metas as $meta_key => $meta_value) {
361 361
             $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key;
362 362
             
363 363
             $this->update_meta($meta_key, $meta_value);
@@ -366,66 +366,66 @@  discard block
 block discarded – undo
366 366
         return true;
367 367
     }
368 368
 
369
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
370
-        if ( empty( $meta_key ) ) {
369
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
370
+        if (empty($meta_key)) {
371 371
             return false;
372 372
         }
373 373
         
374
-        $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID );
374
+        $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID);
375 375
 
376
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
376
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
377 377
     }
378 378
     
379
-    public function get_fees( $type = 'fee', $item_id = 0 ) {
379
+    public function get_fees($type = 'fee', $item_id = 0) {
380 380
         global $wpi_session;
381 381
         
382
-        $fees = $wpi_session->get( 'wpi_cart_fees' );
382
+        $fees = $wpi_session->get('wpi_cart_fees');
383 383
 
384
-        if ( ! wpinv_get_cart_contents() ) {
384
+        if (!wpinv_get_cart_contents()) {
385 385
             // We can only get item type fees when the cart is empty
386 386
             $type = 'custom';
387 387
         }
388 388
 
389
-        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
390
-            foreach( $fees as $key => $fee ) {
391
-                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
392
-                    unset( $fees[ $key ] );
389
+        if (!empty($fees) && !empty($type) && 'all' !== $type) {
390
+            foreach ($fees as $key => $fee) {
391
+                if (!empty($fee['type']) && $type != $fee['type']) {
392
+                    unset($fees[$key]);
393 393
                 }
394 394
             }
395 395
         }
396 396
 
397
-        if ( ! empty( $fees ) && ! empty( $item_id ) ) {
397
+        if (!empty($fees) && !empty($item_id)) {
398 398
             // Remove fees that don't belong to the specified Item
399
-            foreach ( $fees as $key => $fee ) {
400
-                if ( (int) $item_id !== (int)$fee['custom_id'] ) {
401
-                    unset( $fees[ $key ] );
399
+            foreach ($fees as $key => $fee) {
400
+                if ((int)$item_id !== (int)$fee['custom_id']) {
401
+                    unset($fees[$key]);
402 402
                 }
403 403
             }
404 404
         }
405 405
 
406
-        if ( ! empty( $fees ) ) {
406
+        if (!empty($fees)) {
407 407
             // Remove fees that belong to a specific item but are not in the cart
408
-            foreach( $fees as $key => $fee ) {
409
-                if( empty( $fee['custom_id'] ) ) {
408
+            foreach ($fees as $key => $fee) {
409
+                if (empty($fee['custom_id'])) {
410 410
                     continue;
411 411
                 }
412 412
 
413
-                if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) {
414
-                    unset( $fees[ $key ] );
413
+                if (!wpinv_item_in_cart($fee['custom_id'])) {
414
+                    unset($fees[$key]);
415 415
                 }
416 416
             }
417 417
         }
418 418
 
419
-        return ! empty( $fees ) ? $fees : array();
419
+        return !empty($fees) ? $fees : array();
420 420
     }
421 421
     
422 422
     public function can_purchase() {
423 423
         $can_purchase = true;
424 424
 
425
-        if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
425
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
426 426
             $can_purchase = false;
427 427
         }
428 428
 
429
-        return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
429
+        return (bool)apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
430 430
     }
431 431
 }
Please login to merge, or discard this patch.
includes/wpinv-general-functions.php 1 patch
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -7,195 +7,195 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_is_checkout() {
15 15
     global $wp_query;
16 16
 
17
-    $is_object_set    = isset( $wp_query->queried_object );
18
-    $is_object_id_set = isset( $wp_query->queried_object_id );
19
-    $is_checkout      = is_page( wpinv_get_option( 'checkout_page' ) );
17
+    $is_object_set    = isset($wp_query->queried_object);
18
+    $is_object_id_set = isset($wp_query->queried_object_id);
19
+    $is_checkout      = is_page(wpinv_get_option('checkout_page'));
20 20
 
21
-    if ( !$is_object_set ) {
22
-        unset( $wp_query->queried_object );
21
+    if (!$is_object_set) {
22
+        unset($wp_query->queried_object);
23 23
     }
24 24
 
25
-    if ( !$is_object_id_set ) {
26
-        unset( $wp_query->queried_object_id );
25
+    if (!$is_object_id_set) {
26
+        unset($wp_query->queried_object_id);
27 27
     }
28 28
 
29
-    return apply_filters( 'wpinv_is_checkout', $is_checkout );
29
+    return apply_filters('wpinv_is_checkout', $is_checkout);
30 30
 }
31 31
 
32 32
 function wpinv_can_checkout() {
33 33
 	$can_checkout = true; // Always true for now
34 34
 
35
-	return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
35
+	return (bool)apply_filters('wpinv_can_checkout', $can_checkout);
36 36
 }
37 37
 
38 38
 function wpinv_get_success_page_uri() {
39
-	$page_id = wpinv_get_option( 'success_page', 0 );
40
-	$page_id = absint( $page_id );
39
+	$page_id = wpinv_get_option('success_page', 0);
40
+	$page_id = absint($page_id);
41 41
 
42
-	return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
42
+	return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id));
43 43
 }
44 44
 
45 45
 function wpinv_get_history_page_uri() {
46
-	$page_id = wpinv_get_option( 'invoice_history_page', 0 );
47
-	$page_id = absint( $page_id );
46
+	$page_id = wpinv_get_option('invoice_history_page', 0);
47
+	$page_id = absint($page_id);
48 48
 
49
-	return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) );
49
+	return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id));
50 50
 }
51 51
 
52 52
 function wpinv_is_success_page() {
53
-	$is_success_page = wpinv_get_option( 'success_page', false );
54
-	$is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false;
53
+	$is_success_page = wpinv_get_option('success_page', false);
54
+	$is_success_page = isset($is_success_page) ? is_page($is_success_page) : false;
55 55
 
56
-	return apply_filters( 'wpinv_is_success_page', $is_success_page );
56
+	return apply_filters('wpinv_is_success_page', $is_success_page);
57 57
 }
58 58
 
59 59
 function wpinv_is_invoice_history_page() {
60
-	$ret = wpinv_get_option( 'invoice_history_page', false );
61
-	$ret = $ret ? is_page( $ret ) : false;
62
-	return apply_filters( 'wpinv_is_invoice_history_page', $ret );
60
+	$ret = wpinv_get_option('invoice_history_page', false);
61
+	$ret = $ret ? is_page($ret) : false;
62
+	return apply_filters('wpinv_is_invoice_history_page', $ret);
63 63
 }
64 64
 
65
-function wpinv_send_to_success_page( $args = null ) {
65
+function wpinv_send_to_success_page($args = null) {
66 66
 	$redirect = wpinv_get_success_page_uri();
67 67
     
68
-    if ( !empty( $args ) ) {
68
+    if (!empty($args)) {
69 69
         // Check for backward compatibility
70
-        if ( is_string( $args ) )
71
-            $args = str_replace( '?', '', $args );
70
+        if (is_string($args))
71
+            $args = str_replace('?', '', $args);
72 72
 
73
-        $args = wp_parse_args( $args );
73
+        $args = wp_parse_args($args);
74 74
 
75
-        $redirect = add_query_arg( $args, $redirect );
75
+        $redirect = add_query_arg($args, $redirect);
76 76
     }
77 77
 
78
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
78
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
79 79
     
80
-    $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args );
81
-    wp_redirect( $redirect );
80
+    $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args);
81
+    wp_redirect($redirect);
82 82
     exit;
83 83
 }
84 84
 
85
-function wpinv_send_to_failed_page( $args = null ) {
85
+function wpinv_send_to_failed_page($args = null) {
86 86
 	$redirect = wpinv_get_failed_transaction_uri();
87 87
     
88
-    if ( !empty( $args ) ) {
88
+    if (!empty($args)) {
89 89
         // Check for backward compatibility
90
-        if ( is_string( $args ) )
91
-            $args = str_replace( '?', '', $args );
90
+        if (is_string($args))
91
+            $args = str_replace('?', '', $args);
92 92
 
93
-        $args = wp_parse_args( $args );
93
+        $args = wp_parse_args($args);
94 94
 
95
-        $redirect = add_query_arg( $args, $redirect );
95
+        $redirect = add_query_arg($args, $redirect);
96 96
     }
97 97
 
98
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
98
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
99 99
     
100
-    $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );
101
-    wp_redirect( $redirect );
100
+    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args);
101
+    wp_redirect($redirect);
102 102
     exit;
103 103
 }
104 104
 
105
-function wpinv_get_checkout_uri( $args = array() ) {
106
-	$uri = wpinv_get_option( 'checkout_page', false );
107
-	$uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
105
+function wpinv_get_checkout_uri($args = array()) {
106
+	$uri = wpinv_get_option('checkout_page', false);
107
+	$uri = isset($uri) ? get_permalink($uri) : NULL;
108 108
 
109
-	if ( !empty( $args ) ) {
109
+	if (!empty($args)) {
110 110
 		// Check for backward compatibility
111
-		if ( is_string( $args ) )
112
-			$args = str_replace( '?', '', $args );
111
+		if (is_string($args))
112
+			$args = str_replace('?', '', $args);
113 113
 
114
-		$args = wp_parse_args( $args );
114
+		$args = wp_parse_args($args);
115 115
 
116
-		$uri = add_query_arg( $args, $uri );
116
+		$uri = add_query_arg($args, $uri);
117 117
 	}
118 118
 
119
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
119
+	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin';
120 120
 
121
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
121
+	$ajax_url = admin_url('admin-ajax.php', $scheme);
122 122
 
123
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
124
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
123
+	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) {
124
+		$uri = preg_replace('/^http:/', 'https:', $uri);
125 125
 	}
126 126
 
127
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
127
+	return apply_filters('wpinv_get_checkout_uri', $uri);
128 128
 }
129 129
 
130
-function wpinv_send_back_to_checkout( $args = array() ) {
130
+function wpinv_send_back_to_checkout($args = array()) {
131 131
 	$redirect = wpinv_get_checkout_uri();
132 132
 
133
-	if ( ! empty( $args ) ) {
133
+	if (!empty($args)) {
134 134
 		// Check for backward compatibility
135
-		if ( is_string( $args ) )
136
-			$args = str_replace( '?', '', $args );
135
+		if (is_string($args))
136
+			$args = str_replace('?', '', $args);
137 137
 
138
-		$args = wp_parse_args( $args );
138
+		$args = wp_parse_args($args);
139 139
 
140
-		$redirect = add_query_arg( $args, $redirect );
140
+		$redirect = add_query_arg($args, $redirect);
141 141
 	}
142 142
 
143
-	wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );
143
+	wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args));
144 144
 	exit;
145 145
 }
146 146
 
147
-function wpinv_get_success_page_url( $query_string = null ) {
148
-	$success_page = wpinv_get_option( 'success_page', 0 );
149
-	$success_page = get_permalink( $success_page );
147
+function wpinv_get_success_page_url($query_string = null) {
148
+	$success_page = wpinv_get_option('success_page', 0);
149
+	$success_page = get_permalink($success_page);
150 150
 
151
-	if ( $query_string )
151
+	if ($query_string)
152 152
 		$success_page .= $query_string;
153 153
 
154
-	return apply_filters( 'wpinv_success_page_url', $success_page );
154
+	return apply_filters('wpinv_success_page_url', $success_page);
155 155
 }
156 156
 
157
-function wpinv_get_failed_transaction_uri( $extras = false ) {
158
-	$uri = wpinv_get_option( 'failure_page', '' );
159
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
157
+function wpinv_get_failed_transaction_uri($extras = false) {
158
+	$uri = wpinv_get_option('failure_page', '');
159
+	$uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();
160 160
 
161
-	if ( $extras )
161
+	if ($extras)
162 162
 		$uri .= $extras;
163 163
 
164
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
164
+	return apply_filters('wpinv_get_failed_transaction_uri', $uri);
165 165
 }
166 166
 
167 167
 function wpinv_is_failed_transaction_page() {
168
-	$ret = wpinv_get_option( 'failure_page', false );
169
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
168
+	$ret = wpinv_get_option('failure_page', false);
169
+	$ret = isset($ret) ? is_page($ret) : false;
170 170
 
171
-	return apply_filters( 'wpinv_is_failure_page', $ret );
171
+	return apply_filters('wpinv_is_failure_page', $ret);
172 172
 }
173 173
 
174
-function wpinv_transaction_query( $type = 'start' ) {
174
+function wpinv_transaction_query($type = 'start') {
175 175
     global $wpdb;
176 176
 
177 177
     $wpdb->hide_errors();
178 178
 
179
-    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) {
180
-        define( 'WPINV_USE_TRANSACTIONS', true );
179
+    if (!defined('WPINV_USE_TRANSACTIONS')) {
180
+        define('WPINV_USE_TRANSACTIONS', true);
181 181
     }
182 182
 
183
-    if ( WPINV_USE_TRANSACTIONS ) {
184
-        switch ( $type ) {
183
+    if (WPINV_USE_TRANSACTIONS) {
184
+        switch ($type) {
185 185
             case 'commit' :
186
-                $wpdb->query( 'COMMIT' );
186
+                $wpdb->query('COMMIT');
187 187
                 break;
188 188
             case 'rollback' :
189
-                $wpdb->query( 'ROLLBACK' );
189
+                $wpdb->query('ROLLBACK');
190 190
                 break;
191 191
             default :
192
-                $wpdb->query( 'START TRANSACTION' );
192
+                $wpdb->query('START TRANSACTION');
193 193
             break;
194 194
         }
195 195
     }
196 196
 }
197 197
 
198
-function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) {
198
+function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) {
199 199
     $default_args = array(
200 200
         'status'        => '',
201 201
         'user_id'       => null,
@@ -205,72 +205,72 @@  discard block
 block discarded – undo
205 205
         'parent'        => 0
206 206
     );
207 207
 
208
-    $args           = wp_parse_args( $args, $default_args );
208
+    $args           = wp_parse_args($args, $default_args);
209 209
     $invoice_data   = array();
210 210
 
211
-    if ( $args['invoice_id'] > 0 ) {
212
-        $updating           = true;
211
+    if ($args['invoice_id'] > 0) {
212
+        $updating = true;
213 213
         $invoice_data['post_type']  = 'wpi_invoice';
214 214
         $invoice_data['ID']         = $args['invoice_id'];
215 215
     } else {
216 216
         $updating                       = false;
217 217
         $invoice_data['post_type']      = 'wpi_invoice';
218
-        $invoice_data['post_status']    = apply_filters( 'wpinv_default_invoice_status', 'pending' );
218
+        $invoice_data['post_status']    = apply_filters('wpinv_default_invoice_status', 'pending');
219 219
         $invoice_data['ping_status']    = 'closed';
220
-        $invoice_data['post_author']    = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();
221
-        $invoice_data['post_title']     = wpinv_format_invoice_number( '0' );
222
-        $invoice_data['post_parent']    = absint( $args['parent'] );
223
-        if ( !empty( $args['created_date'] ) ) {
220
+        $invoice_data['post_author']    = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id();
221
+        $invoice_data['post_title']     = wpinv_format_invoice_number('0');
222
+        $invoice_data['post_parent']    = absint($args['parent']);
223
+        if (!empty($args['created_date'])) {
224 224
             $invoice_data['post_date']      = $args['created_date'];
225
-            $invoice_data['post_date_gmt']  = get_gmt_from_date( $args['created_date'] );
225
+            $invoice_data['post_date_gmt']  = get_gmt_from_date($args['created_date']);
226 226
         }
227 227
     }
228 228
 
229
-    if ( $args['status'] ) {
230
-        if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) ) {
231
-            return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) );
229
+    if ($args['status']) {
230
+        if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses()))) {
231
+            return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status']));
232 232
         }
233
-        $invoice_data['post_status']    = $args['status'];
233
+        $invoice_data['post_status'] = $args['status'];
234 234
     }
235 235
 
236
-    if ( ! is_null( $args['user_note'] ) ) {
237
-        $invoice_data['post_excerpt']   = $args['user_note'];
236
+    if (!is_null($args['user_note'])) {
237
+        $invoice_data['post_excerpt'] = $args['user_note'];
238 238
     }
239 239
 
240
-    if ( $updating ) {
241
-        $invoice_id = wp_update_post( $invoice_data, true );
240
+    if ($updating) {
241
+        $invoice_id = wp_update_post($invoice_data, true);
242 242
     } else {
243
-        $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true );
243
+        $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true);
244 244
     }
245 245
 
246
-    if ( is_wp_error( $invoice_id ) ) {
246
+    if (is_wp_error($invoice_id)) {
247 247
         return $wp_error ? $invoice_id : 0;
248 248
     } else {
249
-        if ( !$updating ) {
250
-            $invoice_number = wpinv_format_invoice_number( $invoice_id );
249
+        if (!$updating) {
250
+            $invoice_number = wpinv_format_invoice_number($invoice_id);
251 251
             
252
-            $update = array( 'ID' => $invoice_id, 'post_title' => $invoice_number, 'post_name' => sanitize_title( $invoice_number ) );
253
-            wp_update_post( $update );
252
+            $update = array('ID' => $invoice_id, 'post_title' => $invoice_number, 'post_name' => sanitize_title($invoice_number));
253
+            wp_update_post($update);
254 254
             
255
-            update_post_meta( $invoice_id, '_wpinv_number', $invoice_number );
255
+            update_post_meta($invoice_id, '_wpinv_number', $invoice_number);
256 256
         }
257 257
     }
258 258
     
259
-    $invoice = wpinv_get_invoice( $invoice_id );
260
-
261
-    if ( !$updating ) {
262
-        update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) );
263
-        update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() );
264
-        update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) );
265
-        update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() );
266
-        update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() );
267
-        update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) );
259
+    $invoice = wpinv_get_invoice($invoice_id);
260
+
261
+    if (!$updating) {
262
+        update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_')));
263
+        update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency());
264
+        update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax'));
265
+        update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip());
266
+        update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent());
267
+        update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via']));
268 268
         
269 269
         // Add invoice note
270
-        $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
270
+        $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status)));
271 271
     }
272 272
 
273
-    update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION );
273
+    update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION);
274 274
 
275 275
     return $invoice;
276 276
 }
@@ -278,118 +278,118 @@  discard block
 block discarded – undo
278 278
 function wpinv_get_prefix() {
279 279
     $invoice_prefix = 'INV-';
280 280
     
281
-    return apply_filters( 'wpinv_get_prefix', $invoice_prefix );
281
+    return apply_filters('wpinv_get_prefix', $invoice_prefix);
282 282
 }
283 283
 
284 284
 function wpinv_get_business_logo() {
285
-    $business_logo = wpinv_get_option( 'logo' );
286
-    return apply_filters( 'wpinv_get_business_logo', $business_logo );
285
+    $business_logo = wpinv_get_option('logo');
286
+    return apply_filters('wpinv_get_business_logo', $business_logo);
287 287
 }
288 288
 
289 289
 function wpinv_get_business_name() {
290 290
     $business_name = wpinv_get_option('store_name');
291
-    return apply_filters( 'wpinv_get_business_name', $business_name );
291
+    return apply_filters('wpinv_get_business_name', $business_name);
292 292
 }
293 293
 
294 294
 function wpinv_get_blogname() {
295
-    return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
295
+    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
296 296
 }
297 297
 
298 298
 function wpinv_get_admin_email() {
299
-    $admin_email = get_option( 'admin_email' );
300
-    return apply_filters( 'wpinv_admin_email', $admin_email );
299
+    $admin_email = get_option('admin_email');
300
+    return apply_filters('wpinv_admin_email', $admin_email);
301 301
 }
302 302
 
303 303
 function wpinv_get_business_website() {
304
-    $business_website = home_url( '/' );
305
-    return apply_filters( 'wpinv_get_business_website', $business_website );
304
+    $business_website = home_url('/');
305
+    return apply_filters('wpinv_get_business_website', $business_website);
306 306
 }
307 307
 
308
-function wpinv_get_terms_text( $invoice_id = 0 ) {
308
+function wpinv_get_terms_text($invoice_id = 0) {
309 309
     $terms_text = '';
310
-    return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );
310
+    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id);
311 311
 }
312 312
 
313 313
 function wpinv_get_business_footer() {
314
-    $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';
315
-    $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );
316
-    return apply_filters( 'wpinv_get_business_footer', $business_footer );
314
+    $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';
315
+    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link);
316
+    return apply_filters('wpinv_get_business_footer', $business_footer);
317 317
 }
318 318
 
319 319
 function wpinv_checkout_required_fields() {
320 320
     $required_fields = array();
321 321
     
322 322
     // Let payment gateways and other extensions determine if address fields should be required
323
-    $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
323
+    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes());
324 324
     
325
-    if ( $require_billing_details ) {
325
+    if ($require_billing_details) {
326 326
         ///$required_fields['email'] = array(
327 327
                 ///'error_id' => 'invalid_email',
328 328
                 ///'error_message' => __( 'Please enter a valid email address', 'invoicing' )
329 329
             ///);
330 330
         $required_fields['first_name'] = array(
331 331
                 'error_id' => 'invalid_first_name',
332
-                'error_message' => __( 'Please enter your first name', 'invoicing' )
332
+                'error_message' => __('Please enter your first name', 'invoicing')
333 333
             );
334 334
         $required_fields['address'] = array(
335 335
                 'error_id' => 'invalid_address',
336
-                'error_message' => __( 'Please enter your address', 'invoicing' )
336
+                'error_message' => __('Please enter your address', 'invoicing')
337 337
             );
338 338
         $required_fields['city'] = array(
339 339
                 'error_id' => 'invalid_city',
340
-                'error_message' => __( 'Please enter your billing city', 'invoicing' )
340
+                'error_message' => __('Please enter your billing city', 'invoicing')
341 341
             );
342 342
         $required_fields['state'] = array(
343 343
                 'error_id' => 'invalid_state',
344
-                'error_message' => __( 'Please enter billing state / province', 'invoicing' )
344
+                'error_message' => __('Please enter billing state / province', 'invoicing')
345 345
             );
346 346
         $required_fields['country'] = array(
347 347
                 'error_id' => 'invalid_country',
348
-                'error_message' => __( 'Please select your billing country', 'invoicing' )
348
+                'error_message' => __('Please select your billing country', 'invoicing')
349 349
             );
350 350
     }
351 351
 
352
-    return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
352
+    return apply_filters('wpinv_checkout_required_fields', $required_fields);
353 353
 }
354 354
 
355 355
 function wpinv_is_ssl_enforced() {
356
-    $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );
357
-    return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );
356
+    $ssl_enforced = wpinv_get_option('enforce_ssl', false);
357
+    return (bool)apply_filters('wpinv_is_ssl_enforced', $ssl_enforced);
358 358
 }
359 359
 
360
-function wpinv_user_can_print_invoice( $post ) {
360
+function wpinv_user_can_print_invoice($post) {
361 361
     $allow = false;
362 362
     
363
-    if ( !( $user_id = get_current_user_id() ) ) {
363
+    if (!($user_id = get_current_user_id())) {
364 364
         return $allow;
365 365
     }
366 366
     
367
-    if ( is_int( $post ) ) {
368
-        $post = get_post( $post );
367
+    if (is_int($post)) {
368
+        $post = get_post($post);
369 369
     }
370 370
     
371 371
     // Allow to owner.
372
-    if ( is_object( $post ) && !empty( $post->post_author ) && $post->post_author == $user_id ) {
372
+    if (is_object($post) && !empty($post->post_author) && $post->post_author == $user_id) {
373 373
         $allow = true;
374 374
     }
375 375
     
376 376
     // Allow to admin user.
377
-    if ( current_user_can( 'manage_options' ) ) {
377
+    if (current_user_can('manage_options')) {
378 378
         $allow = true;
379 379
     }
380 380
     
381
-    return apply_filters( 'wpinv_can_print_invoice', $allow, $post );
381
+    return apply_filters('wpinv_can_print_invoice', $allow, $post);
382 382
 }
383 383
 
384 384
 function wpinv_schedule_events() {
385 385
     // hourly, daily and twicedaily
386
-    if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) {
387
-        wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' );
386
+    if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) {
387
+        wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily');
388 388
     }
389 389
 }
390
-add_action( 'wp', 'wpinv_schedule_events' );
390
+add_action('wp', 'wpinv_schedule_events');
391 391
 
392 392
 function wpinv_schedule_event_twicedaily() {
393 393
     wpinv_email_payment_reminders();
394 394
 }
395
-add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' );
396 395
\ No newline at end of file
396
+add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily');
397 397
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -14,73 +14,73 @@  discard block
 block discarded – undo
14 14
     }
15 15
     
16 16
     public function init() {
17
-        do_action( 'wpinv_class_notes_init', $this );
17
+        do_action('wpinv_class_notes_init', $this);
18 18
     }
19 19
     
20 20
     public function includes() {
21
-        do_action( 'wpinv_class_notes_includes', $this );
21
+        do_action('wpinv_class_notes_includes', $this);
22 22
     }
23 23
     
24 24
     public function actions() {
25 25
         // Secure inovice notes
26
-        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
26
+        add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1);
27 27
         
28 28
         // Count comments
29
-        add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 );
29
+        add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2);
30 30
         
31 31
         // Delete comments count cache whenever there is a new comment or a comment status changes
32
-        add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
33
-        add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
32
+        add_action('wp_insert_comment', array($this, 'delete_comments_count_cache'));
33
+        add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache'));
34 34
         
35
-        do_action( 'wpinv_class_notes_actions', $this );
35
+        do_action('wpinv_class_notes_actions', $this);
36 36
     }
37 37
         
38
-    public function set_invoice_note_type( $query ) {
39
-        $post_ID        = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
38
+    public function set_invoice_note_type($query) {
39
+        $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
40 40
         
41
-        if ( $post_ID && get_post_type( $post_ID ) == $this->invoice_post_type ) {
41
+        if ($post_ID && get_post_type($post_ID) == $this->invoice_post_type) {
42 42
             $query->query_vars['type__in']      = $this->comment_type;
43 43
             $query->query_vars['type__not_in']  = '';
44 44
         } else {        
45
-            if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) {
46
-                if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) {
47
-                    $key = array_search( $this->comment_type, $type_in );
48
-                    unset( $query->query_vars['type__in'][$key] );
49
-                } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) {
45
+            if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) {
46
+                if (is_array($type_in) && in_array($this->comment_type, $type_in)) {
47
+                    $key = array_search($this->comment_type, $type_in);
48
+                    unset($query->query_vars['type__in'][$key]);
49
+                } else if (!is_array($type_in) && $type_in == $this->comment_type) {
50 50
                     $query->query_vars['type__in'] = '';
51 51
                 }
52 52
             }
53 53
             
54
-            if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) {
55
-                if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) {
54
+            if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) {
55
+                if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) {
56 56
                     $query->query_vars['type__not_in'][] = $this->comment_type;
57
-                } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) {
57
+                } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) {
58 58
                     $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in'];
59 59
                     $query->query_vars['type__not_in'][] = $this->comment_type;
60 60
                 }
61 61
             } else {
62
-                $query->query_vars['type__not_in']  = $this->comment_type;
62
+                $query->query_vars['type__not_in'] = $this->comment_type;
63 63
             }
64 64
         }
65 65
         
66 66
         return $query;
67 67
     }
68 68
     
69
-    public function get_invoice_notes( $invoice_id = 0, $type = '' ) {
69
+    public function get_invoice_notes($invoice_id = 0, $type = '') {
70 70
         $args = array( 
71 71
             'post_id'   => $invoice_id,
72 72
             'orderby'   => 'comment_ID',
73 73
             'order'     => 'DESC',
74 74
         );
75 75
         
76
-        if ( $type == 'customer' ) {
76
+        if ($type == 'customer') {
77 77
             $args['meta_key']   = '_wpi_customer_note';
78 78
             $args['meta_value'] = 1;
79 79
         }
80 80
         
81
-        $args   = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
81
+        $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
82 82
         
83
-        return get_comments( $args );
83
+        return get_comments($args);
84 84
     }
85 85
     
86 86
     /**
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      * @return void
92 92
      */
93 93
     public function delete_comments_count_cache() {
94
-        delete_transient( 'wpinv_count_comments' );
94
+        delete_transient('wpinv_count_comments');
95 95
     }
96 96
     
97 97
     /**
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
      * @param  int    $post_id Post ID.
103 103
      * @return object
104 104
      */
105
-    public function wp_count_comments( $stats, $post_id ) {
105
+    public function wp_count_comments($stats, $post_id) {
106 106
         global $wpdb;
107 107
 
108
-        if ( 0 === $post_id ) {
109
-            $stats = get_transient( 'wpinv_count_comments' );
108
+        if (0 === $post_id) {
109
+            $stats = get_transient('wpinv_count_comments');
110 110
 
111
-            if ( ! $stats ) {
111
+            if (!$stats) {
112 112
                 $stats = array();
113 113
 
114
-                $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A );
114
+                $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A);
115 115
 
116 116
                 $total = 0;
117 117
                 $approved = array(
@@ -122,26 +122,26 @@  discard block
 block discarded – undo
122 122
                     'post-trashed' => 'post-trashed',
123 123
                 );
124 124
 
125
-                foreach ( (array) $count as $row ) {
125
+                foreach ((array)$count as $row) {
126 126
                     // Do not count post-trashed toward totals.
127
-                    if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) {
127
+                    if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) {
128 128
                         $total += $row['num_comments'];
129 129
                     }
130
-                    if ( isset( $approved[ $row['comment_approved'] ] ) ) {
131
-                        $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
130
+                    if (isset($approved[$row['comment_approved']])) {
131
+                        $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
132 132
                     }
133 133
                 }
134 134
 
135 135
                 $stats['total_comments'] = $total;
136 136
                 $stats['all'] = $total;
137
-                foreach ( $approved as $key ) {
138
-                    if ( empty( $stats[ $key ] ) ) {
139
-                        $stats[ $key ] = 0;
137
+                foreach ($approved as $key) {
138
+                    if (empty($stats[$key])) {
139
+                        $stats[$key] = 0;
140 140
                     }
141 141
                 }
142 142
 
143
-                $stats = (object) $stats;
144
-                set_transient( 'wpinv_count_comments', $stats );
143
+                $stats = (object)$stats;
144
+                set_transient('wpinv_count_comments', $stats);
145 145
             }
146 146
         }
147 147
 
Please login to merge, or discard this patch.
includes/admin/wpinv-upgrade-functions.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -11,37 +11,37 @@
 block discarded – undo
11 11
  * @since 1.0.0
12 12
 */
13 13
 function wpinv_automatic_upgrade() {
14
-    $wpi_version = get_option( 'wpinv_version' );
14
+    $wpi_version = get_option('wpinv_version');
15 15
     
16
-    if ( $wpi_version == WPINV_VERSION ) {
16
+    if ($wpi_version == WPINV_VERSION) {
17 17
         return;
18 18
     }
19 19
     
20
-    if ( version_compare( $wpi_version, '0.0.5', '<' ) ) {
20
+    if (version_compare($wpi_version, '0.0.5', '<')) {
21 21
         wpinv_v005_upgrades();
22 22
     }
23 23
     
24
-    update_option( 'wpinv_version', WPINV_VERSION );
24
+    update_option('wpinv_version', WPINV_VERSION);
25 25
 }
26
-add_action( 'admin_init', 'wpinv_automatic_upgrade' );
26
+add_action('admin_init', 'wpinv_automatic_upgrade');
27 27
 
28 28
 function wpinv_v005_upgrades() {
29 29
     global $wpdb;
30 30
     
31 31
     // Invoices status
32
-    $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
32
+    $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
33 33
     
34 34
     // Item meta key changes
35 35
     $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
36
-    $results = $wpdb->get_results( $query );
36
+    $results = $wpdb->get_results($query);
37 37
     
38
-    if ( !empty( $results ) ) {
39
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
40
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
41
-        $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
38
+    if (!empty($results)) {
39
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
40
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
41
+        $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
42 42
         
43
-        foreach ( $results as $row ) {
44
-            clean_post_cache( $row->post_id );
43
+        foreach ($results as $row) {
44
+            clean_post_cache($row->post_id);
45 45
         }
46 46
     }
47 47
 }
48 48
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Items {
8
-    public static function output( $post ) {        
8
+    public static function output($post) {        
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
         
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22 22
         $item_types         = wpinv_get_item_types();
@@ -29,17 +29,17 @@  discard block
 block discarded – undo
29 29
         }
30 30
         
31 31
         $cols = 5;
32
-        if ( $item_quantities ) {
32
+        if ($item_quantities) {
33 33
             $cols++;
34 34
         }
35
-        if ( $use_taxes ) {
35
+        if ($use_taxes) {
36 36
             $cols++;
37 37
         }
38 38
         $class = '';
39
-        if ( $invoice->is_paid() ) {
39
+        if ($invoice->is_paid()) {
40 40
             $class .= ' wpinv-paid';
41 41
         }
42
-        if ( $is_recurring ) {
42
+        if ($is_recurring) {
43 43
             $class .= ' wpi-recurring';
44 44
         }
45 45
         ?>
@@ -47,21 +47,21 @@  discard block
 block discarded – undo
47 47
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
48 48
                 <thead>
49 49
                     <tr>
50
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
51
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
52
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
53
-                        <?php if ( $item_quantities ) { ?>
54
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
50
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
51
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
52
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
53
+                        <?php if ($item_quantities) { ?>
54
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
55 55
                         <?php } ?>
56
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
57
-                        <?php if ( $use_taxes ) { ?>
58
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
56
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
57
+                        <?php if ($use_taxes) { ?>
58
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
59 59
                         <?php } ?>
60 60
                         <th class="action"></th>
61 61
                     </tr>
62 62
                 </thead>
63 63
                 <tbody class="wpinv-line-items">
64
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
64
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
65 65
                 </tbody>
66 66
                 <tfoot class="wpinv-totals">
67 67
                     <tr>
@@ -73,44 +73,44 @@  discard block
 block discarded – undo
73 73
                                         </td>
74 74
                                         <td class="title">
75 75
                                             <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]">
76
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
76
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
77 77
                                             <div class="wp-clearfix">
78 78
                                                 <label class="wpi-vat-rule">
79
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
79
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
80 80
                                                     <span class="input-text-wrap">
81
-                                                        <?php echo wpinv_html_select( array(
81
+                                                        <?php echo wpinv_html_select(array(
82 82
                                                             'options'          => $wpinv_euvat->get_rules(),
83 83
                                                             'name'             => '_wpinv_quick[vat_rule]',
84 84
                                                             'id'               => '_wpinv_quick_vat_rule',
85 85
                                                             'show_option_all'  => false,
86 86
                                                             'show_option_none' => false,
87 87
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
88
-                                                        ) ); ?>
88
+                                                        )); ?>
89 89
                                                     </span>
90 90
                                                 </label>
91 91
                                             </div>
92
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
92
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
93 93
                                             <div class="wp-clearfix">
94 94
                                                 <label class="wpi-vat-class">
95
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
95
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
96 96
                                                     <span class="input-text-wrap">
97
-                                                        <?php echo wpinv_html_select( array(
97
+                                                        <?php echo wpinv_html_select(array(
98 98
                                                             'options'          => $wpinv_euvat->get_all_classes(),
99 99
                                                             'name'             => '_wpinv_quick[vat_class]',
100 100
                                                             'id'               => '_wpinv_quick_vat_class',
101 101
                                                             'show_option_all'  => false,
102 102
                                                             'show_option_none' => false,
103 103
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
104
-                                                        ) ); ?>
104
+                                                        )); ?>
105 105
                                                     </span>
106 106
                                                 </label>
107 107
                                             </div>
108 108
                                             <?php } ?>
109 109
                                             <div class="wp-clearfix">
110 110
                                                 <label class="wpi-item-type">
111
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
111
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
112 112
                                                     <span class="input-text-wrap">
113
-                                                        <?php echo wpinv_html_select( array(
113
+                                                        <?php echo wpinv_html_select(array(
114 114
                                                             'options'          => $item_types,
115 115
                                                             'name'             => '_wpinv_quick[type]',
116 116
                                                             'id'               => '_wpinv_quick_type',
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
                                                             'show_option_all'  => false,
119 119
                                                             'show_option_none' => false,
120 120
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type',
121
-                                                        ) ); ?>
121
+                                                        )); ?>
122 122
                                                     </span>
123 123
                                                 </label>
124 124
                                             </div>
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
                                             </div>
132 132
                                         </td>
133 133
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
134
-                                        <?php if ( $item_quantities ) { ?>
134
+                                        <?php if ($item_quantities) { ?>
135 135
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
136 136
                                         <?php } ?>
137 137
                                         <td class="total"></td>
138
-                                        <?php if ( $use_taxes ) { ?>
138
+                                        <?php if ($use_taxes) { ?>
139 139
                                         <td class="tax"></td>
140 140
                                         <?php } ?>
141 141
                                         <td class="action"></td>
@@ -148,29 +148,29 @@  discard block
 block discarded – undo
148 148
                         <td colspan="<?php echo $cols; ?>"></td>
149 149
                     </tr>
150 150
                     <tr class="totals">
151
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
151
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
152 152
                         <td colspan="4">
153 153
                             <table cellspacing="0" cellpadding="0">
154 154
                                 <tr class="subtotal">
155
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
156
-                                    <td class="total"><?php echo $subtotal;?></td>
155
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
156
+                                    <td class="total"><?php echo $subtotal; ?></td>
157 157
                                     <td class="action"></td>
158 158
                                 </tr>
159 159
                                 <tr class="discount">
160
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
161
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
160
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
161
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
162 162
                                     <td class="action"></td>
163 163
                                 </tr>
164
-                                <?php if ( $use_taxes ) { ?>
164
+                                <?php if ($use_taxes) { ?>
165 165
                                 <tr class="tax">
166
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
167
-                                    <td class="total"><?php echo $tax;?></td>
166
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
167
+                                    <td class="total"><?php echo $tax; ?></td>
168 168
                                     <td class="action"></td>
169 169
                                 </tr>
170 170
                                 <?php } ?>
171 171
                                 <tr class="total">
172
-                                    <td class="name"><?php _e( 'Invoice Total:', 'invoicing' );?></td>
173
-                                    <td class="total"><?php echo $total;?></td>
172
+                                    <td class="name"><?php _e('Invoice Total:', 'invoicing'); ?></td>
173
+                                    <td class="total"><?php echo $total; ?></td>
174 174
                                     <td class="action"></td>
175 175
                                 </tr>
176 176
                             </table>
@@ -180,89 +180,89 @@  discard block
 block discarded – undo
180 180
             </table>
181 181
             <div class="wpinv-actions">
182 182
                 <?php
183
-                    if ( !$invoice->is_paid() ) {
184
-                    if ( !$invoice->is_recurring() ) {
185
-                    echo wpinv_item_dropdown( array(
183
+                    if (!$invoice->is_paid()) {
184
+                    if (!$invoice->is_recurring()) {
185
+                    echo wpinv_item_dropdown(array(
186 186
                         'name'             => 'wpinv_invoice_item',
187 187
                         'id'               => 'wpinv_invoice_item',
188 188
                         'with_packages'    => false,
189 189
                         'show_recurring'   => true,
190
-                    ) );
190
+                    ));
191 191
                     ?>
192
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
192
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
193 193
                     <?php } ?>
194
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
194
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
195 195
             </div>
196 196
         </div>
197 197
         <?php
198 198
     }
199 199
     
200
-    public static function prices( $post ) {        
200
+    public static function prices($post) {        
201 201
         $symbol         = wpinv_currency_symbol();
202 202
         $position       = wpinv_currency_position();
203
-        $item           = new WPInv_Item( $post->ID );
203
+        $item           = new WPInv_Item($post->ID);
204 204
         
205 205
         $price          = $item->get_price();
206 206
         $is_recurring   = $item->is_recurring();
207 207
         $period         = $item->get_recurring_period();
208
-        $interval       = absint( $item->get_recurring_interval() );
209
-        $times          = absint( $item->get_recurring_limit() );
208
+        $interval       = absint($item->get_recurring_interval());
209
+        $times          = absint($item->get_recurring_limit());
210 210
         $free_trial     = $item->has_free_trial();
211 211
         $trial_interval = $item->get_trial_interval();
212 212
         $trial_period   = $item->get_trial_period();
213 213
         
214 214
         $intervals      = array();
215
-        for ( $i = 1; $i <= 90; $i++ ) {
215
+        for ($i = 1; $i <= 90; $i++) {
216 216
             $intervals[$i] = $i;
217 217
         }
218 218
         
219
-        $interval       = $interval > 0 ? $interval : 1;
219
+        $interval = $interval > 0 ? $interval : 1;
220 220
         
221 221
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
222 222
         ?>
223
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_package(), true ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
224
-        <?php if ( $item->is_package() ) { ?>
225
-        <span class="description"><?php _e( 'GD package item price can be edited only from GD payment manager.', 'invoicing' ); ?></span>
223
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_package(), true); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
224
+        <?php if ($item->is_package()) { ?>
225
+        <span class="description"><?php _e('GD package item price can be edited only from GD payment manager.', 'invoicing'); ?></span>
226 226
         <?php } ?>
227 227
         </p>
228 228
         <p class="wpinv-row-is-recurring">
229 229
             <label for="wpinv_is_recurring">
230
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
231
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
230
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
231
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
232 232
             </label>
233 233
         </p>
234
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
235
-                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
236
-                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
234
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
235
+                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
236
+                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
237 237
                     'options'          => $intervals,
238 238
                     'name'             => 'wpinv_recurring_interval',
239 239
                     'id'               => 'wpinv_recurring_interval',
240 240
                     'selected'         => $interval,
241 241
                     'show_option_all'  => false,
242 242
                     'show_option_none' => false
243
-                ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
244
-                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
243
+                )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
244
+                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
245 245
                 <span class="clear wpi-trial-clr"></span>
246 246
                 <label class="wpinv-free-trial" for="wpinv_free_trial">
247
-                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
248
-                    <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
247
+                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> 
248
+                    <?php echo __('Offer free trial for', 'invoicing'); ?>
249 249
                 </label>
250 250
                 <label class="wpinv-trial-interval" for="wpinv_trial_interval">
251
-                    <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
251
+                    <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
252 252
                 </label>
253 253
         </p>
254
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
255
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
254
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
255
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
256 256
         <?php
257 257
     }
258 258
     
259
-    public static function vat_rules( $post ) {
259
+    public static function vat_rules($post) {
260 260
         global $wpinv_euvat;
261 261
         
262
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
262
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
263 263
         ?>
264
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
265
-        <?php echo wpinv_html_select( array(
264
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
265
+        <?php echo wpinv_html_select(array(
266 266
                     'options'          => $wpinv_euvat->get_rules(),
267 267
                     'name'             => 'wpinv_vat_rules',
268 268
                     'id'               => 'wpinv_vat_rules',
@@ -270,19 +270,19 @@  discard block
 block discarded – undo
270 270
                     'show_option_all'  => false,
271 271
                     'show_option_none' => false,
272 272
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
273
-                ) ); ?>
273
+                )); ?>
274 274
         </p>
275
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
276
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
275
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
276
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
277 277
         <?php
278 278
     }
279 279
     
280
-    public static function vat_classes( $post ) {
280
+    public static function vat_classes($post) {
281 281
         global $wpinv_euvat;
282 282
         
283
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
283
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
284 284
         ?>
285
-        <p><?php echo wpinv_html_select( array(
285
+        <p><?php echo wpinv_html_select(array(
286 286
                     'options'          => $wpinv_euvat->get_all_classes(),
287 287
                     'name'             => 'wpinv_vat_class',
288 288
                     'id'               => 'wpinv_vat_class',
@@ -290,18 +290,18 @@  discard block
 block discarded – undo
290 290
                     'show_option_all'  => false,
291 291
                     'show_option_none' => false,
292 292
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class',
293
-                ) ); ?>
293
+                )); ?>
294 294
         </p>
295
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
295
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
296 296
         <?php
297 297
     }
298 298
     
299
-    public static function item_info( $post ) {
300
-        $item_type = wpinv_get_item_type( $post->ID );
301
-        do_action( 'wpinv_item_info_metabox_before', $post );
299
+    public static function item_info($post) {
300
+        $item_type = wpinv_get_item_type($post->ID);
301
+        do_action('wpinv_item_info_metabox_before', $post);
302 302
         ?>
303
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
304
-        <?php echo wpinv_html_select( array(
303
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
304
+        <?php echo wpinv_html_select(array(
305 305
                     'options'          => wpinv_get_item_types(),
306 306
                     'name'             => 'wpinv_item_type',
307 307
                     'id'               => 'wpinv_item_type',
@@ -310,114 +310,114 @@  discard block
 block discarded – undo
310 310
                     'show_option_none' => false,
311 311
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
312 312
                     //'disabled'         => $item_type == 'package' ? true : false,
313
-                ) ); ?>
313
+                )); ?>
314 314
         </p>
315
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( 'Standard: standard item type', 'invoicing' );?><br><?php _e( 'Fee: like Registration Fee, Signup Fee etc.', 'invoicing' );?></p>
315
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('Standard: standard item type', 'invoicing'); ?><br><?php _e('Fee: like Registration Fee, Signup Fee etc.', 'invoicing'); ?></p>
316 316
         <?php
317
-        do_action( 'wpinv_item_info_metabox_after', $post );
317
+        do_action('wpinv_item_info_metabox_after', $post);
318 318
     }
319 319
     
320
-    public static function meta_values( $post ) {
321
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
320
+    public static function meta_values($post) {
321
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
322 322
             'type',
323 323
             'custom_id'
324
-        ) );
324
+        ));
325 325
         
326
-        if ( empty( $meta_keys ) ) {
326
+        if (empty($meta_keys)) {
327 327
             return;
328 328
         }
329 329
         
330
-        do_action( 'wpinv_meta_values_metabox_before', $post );
330
+        do_action('wpinv_meta_values_metabox_before', $post);
331 331
         
332
-        foreach ( $meta_keys as $meta_key ) {
332
+        foreach ($meta_keys as $meta_key) {
333 333
             ?>
334
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
334
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
335 335
             <?php 
336 336
         }
337 337
         
338
-        do_action( 'wpinv_meta_values_metabox_after', $post );
338
+        do_action('wpinv_meta_values_metabox_after', $post);
339 339
     }
340 340
     
341
-    public static function save( $post_id, $data, $post ) {
342
-        $invoice        = new WPInv_Invoice( $post_id );
341
+    public static function save($post_id, $data, $post) {
342
+        $invoice        = new WPInv_Invoice($post_id);
343 343
         
344 344
         // Billing
345
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
346
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
347
-        $company        = sanitize_text_field( $data['wpinv_company'] );
348
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
349
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
350
-        $address        = sanitize_text_field( $data['wpinv_address'] );
351
-        $city           = sanitize_text_field( $data['wpinv_city'] );
352
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
353
-        $country        = sanitize_text_field( $data['wpinv_country'] );
354
-        $state          = sanitize_text_field( $data['wpinv_state'] );
345
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
346
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
347
+        $company        = sanitize_text_field($data['wpinv_company']);
348
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
349
+        $phone          = sanitize_text_field($data['wpinv_phone']);
350
+        $address        = sanitize_text_field($data['wpinv_address']);
351
+        $city           = sanitize_text_field($data['wpinv_city']);
352
+        $zip            = sanitize_text_field($data['wpinv_zip']);
353
+        $country        = sanitize_text_field($data['wpinv_country']);
354
+        $state          = sanitize_text_field($data['wpinv_state']);
355 355
         
356 356
         // Details
357
-        $status         = sanitize_text_field( $data['wpinv_status'] );
358
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
359
-        $number         = sanitize_text_field( $data['wpinv_number'] );
360
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
357
+        $status         = sanitize_text_field($data['wpinv_status']);
358
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
359
+        $number         = sanitize_text_field($data['wpinv_number']);
360
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
361 361
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
362 362
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
363 363
         
364
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
364
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
365 365
         
366
-        $invoice->set( 'due_date', $due_date );
367
-        $invoice->set( 'first_name', $first_name );
368
-        $invoice->set( 'last_name', $last_name );
369
-        $invoice->set( 'company', $company );
370
-        $invoice->set( 'vat_number', $vat_number );
371
-        $invoice->set( 'phone', $phone );
372
-        $invoice->set( 'address', $address );
373
-        $invoice->set( 'city', $city );
374
-        $invoice->set( 'zip', $zip );
375
-        $invoice->set( 'country', $country );
376
-        $invoice->set( 'state', $state );
377
-        $invoice->set( 'status', $status );
378
-        $invoice->set( 'number', $number );
366
+        $invoice->set('due_date', $due_date);
367
+        $invoice->set('first_name', $first_name);
368
+        $invoice->set('last_name', $last_name);
369
+        $invoice->set('company', $company);
370
+        $invoice->set('vat_number', $vat_number);
371
+        $invoice->set('phone', $phone);
372
+        $invoice->set('address', $address);
373
+        $invoice->set('city', $city);
374
+        $invoice->set('zip', $zip);
375
+        $invoice->set('country', $country);
376
+        $invoice->set('state', $state);
377
+        $invoice->set('status', $status);
378
+        $invoice->set('number', $number);
379 379
         //$invoice->set( 'discounts', $discounts );
380 380
         //$invoice->set( 'discount', $discount );
381
-        $invoice->set( 'ip', $ip );
381
+        $invoice->set('ip', $ip);
382 382
         $invoice->old_status = $_POST['original_post_status'];
383 383
         $invoice->currency = wpinv_get_currency();
384
-        if ( !empty( $data['wpinv_gateway'] ) ) {
385
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
384
+        if (!empty($data['wpinv_gateway'])) {
385
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
386 386
         }
387 387
         $saved = $invoice->save();
388 388
         
389 389
         // Check for payment notes
390
-        if ( !empty( $data['invoice_note'] ) ) {
391
-            $note               = wp_kses( $data['invoice_note'], array() );
392
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
390
+        if (!empty($data['invoice_note'])) {
391
+            $note               = wp_kses($data['invoice_note'], array());
392
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
393 393
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
394 394
         
395
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
395
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
396 396
         }
397 397
         
398 398
         // Update user address if empty.
399
-        if ( $saved && !empty( $invoice ) ) {
400
-            if ( $user_id = $invoice->get_user_id() ) {
401
-                $user_address = wpinv_get_user_address( $user_id, false );
399
+        if ($saved && !empty($invoice)) {
400
+            if ($user_id = $invoice->get_user_id()) {
401
+                $user_address = wpinv_get_user_address($user_id, false);
402 402
                 
403 403
                 if (empty($user_address['first_name'])) {
404
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
405
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
404
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
405
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
406 406
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
407
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
407
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
408 408
                 }
409 409
                 
410 410
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
411
-                    update_user_meta( $user_id, '_wpinv_address', $address );
412
-                    update_user_meta( $user_id, '_wpinv_city', $city );
413
-                    update_user_meta( $user_id, '_wpinv_state', $state );
414
-                    update_user_meta( $user_id, '_wpinv_country', $country );
415
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
416
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
411
+                    update_user_meta($user_id, '_wpinv_address', $address);
412
+                    update_user_meta($user_id, '_wpinv_city', $city);
413
+                    update_user_meta($user_id, '_wpinv_state', $state);
414
+                    update_user_meta($user_id, '_wpinv_country', $country);
415
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
416
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
417 417
                 }
418 418
             }
419 419
             
420
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
420
+            do_action('wpinv_invoice_metabox_saved', $invoice);
421 421
         }
422 422
         
423 423
         return $saved;
Please login to merge, or discard this patch.
includes/admin/admin-meta-boxes.php 1 patch
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -1,65 +1,65 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-function wpinv_add_meta_boxes( $post_type, $post ) {
7
+function wpinv_add_meta_boxes($post_type, $post) {
8 8
     global $wpi_mb_invoice;
9
-    if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) {
10
-        $wpi_mb_invoice = wpinv_get_invoice( $post->ID );
9
+    if ($post_type == 'wpi_invoice' && !empty($post->ID)) {
10
+        $wpi_mb_invoice = wpinv_get_invoice($post->ID);
11 11
     }
12 12
     
13
-    if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) {
14
-        add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' );
13
+    if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) {
14
+        add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high');
15 15
     }
16 16
     
17
-    if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) {
18
-        add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' );
17
+    if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) {
18
+        add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high');
19 19
     }
20 20
     
21
-    if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) {
22
-        add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' );
21
+    if (wpinv_is_subscription_payment($wpi_mb_invoice)) {
22
+        add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high');
23 23
     }
24 24
     
25
-    add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' );
26
-    add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' );
25
+    add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default');
26
+    add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default');
27 27
    
28
-    add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' );
29
-    add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' );
30
-    add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' );
28
+    add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high');
29
+    add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high');
30
+    add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high');
31 31
 }
32
-add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 );
32
+add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2);
33 33
 
34
-function wpinv_save_meta_boxes( $post_id, $post, $update = false ) {
35
-    remove_action( 'save_post', __FUNCTION__ );
34
+function wpinv_save_meta_boxes($post_id, $post, $update = false) {
35
+    remove_action('save_post', __FUNCTION__);
36 36
     
37 37
     // $post_id and $post are required
38
-    if ( empty( $post_id ) || empty( $post ) ) {
38
+    if (empty($post_id) || empty($post)) {
39 39
         return;
40 40
     }
41 41
         
42
-    if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) {
42
+    if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) {
43 43
         return;
44 44
     }
45 45
     
46 46
     // Dont' save meta boxes for revisions or autosaves
47
-    if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
47
+    if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
48 48
         return;
49 49
     }
50 50
         
51
-    if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) {
52
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
51
+    if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') {
52
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
53 53
             return;
54 54
         }
55 55
     
56
-        if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) {
57
-            WPInv_Meta_Box_Items::save( $post_id, $_POST, $post );
56
+        if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) {
57
+            WPInv_Meta_Box_Items::save($post_id, $_POST, $post);
58 58
         }
59
-    } else if ( $post->post_type == 'wpi_item' ) {
59
+    } else if ($post->post_type == 'wpi_item') {
60 60
         // verify nonce
61
-        if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) {
62
-            $fields                                 = array();
61
+        if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) {
62
+            $fields = array();
63 63
             $fields['_wpinv_price']              = 'wpinv_item_price';
64 64
             $fields['_wpinv_vat_class']          = 'wpinv_vat_class';
65 65
             $fields['_wpinv_vat_rule']           = 'wpinv_vat_rules';
@@ -72,296 +72,296 @@  discard block
 block discarded – undo
72 72
             $fields['_wpinv_trial_period']       = 'wpinv_trial_period';
73 73
             $fields['_wpinv_trial_interval']     = 'wpinv_trial_interval';
74 74
             
75
-            if ( !isset( $_POST['wpinv_is_recurring'] ) ) {
75
+            if (!isset($_POST['wpinv_is_recurring'])) {
76 76
                 $_POST['wpinv_is_recurring'] = 0;
77 77
             }
78 78
             
79
-            if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) {
79
+            if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) {
80 80
                 $_POST['wpinv_free_trial'] = 0;
81 81
             }
82 82
             
83
-            foreach ( $fields as $field => $name ) {
84
-                if ( isset( $_POST[ $name ] ) ) {
85
-                    if ( $field == '_wpinv_price' ) {
86
-                        if ( get_post_meta( $post_id, '_wpinv_type', true ) === 'package' ) {
87
-                            $value = wpinv_sanitize_amount( get_post_meta( $post_id, '_wpinv_price', true ) ); // Don't allow edit GD package item price.
83
+            foreach ($fields as $field => $name) {
84
+                if (isset($_POST[$name])) {
85
+                    if ($field == '_wpinv_price') {
86
+                        if (get_post_meta($post_id, '_wpinv_type', true) === 'package') {
87
+                            $value = wpinv_sanitize_amount(get_post_meta($post_id, '_wpinv_price', true)); // Don't allow edit GD package item price.
88 88
                         } else {
89
-                            $value = wpinv_sanitize_amount( $_POST[ $name ] );
89
+                            $value = wpinv_sanitize_amount($_POST[$name]);
90 90
                         }
91 91
                     } else {
92
-                        $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ];
92
+                        $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name];
93 93
                     }
94 94
                     
95
-                    $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name );
96
-                    update_post_meta( $post_id, $field, $value );
95
+                    $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name);
96
+                    update_post_meta($post_id, $field, $value);
97 97
                 }
98 98
             }
99 99
             
100
-            if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) {
101
-                update_post_meta( $post_id, '_wpinv_custom_id', $post_id );
100
+            if (!get_post_meta($post_id, '_wpinv_custom_id', true)) {
101
+                update_post_meta($post_id, '_wpinv_custom_id', $post_id);
102 102
             }
103 103
         }
104 104
     }
105 105
 }
106
-add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 );
106
+add_action('save_post', 'wpinv_save_meta_boxes', 10, 3);
107 107
 
108
-function wpinv_bulk_and_quick_edit_save( $post_id, $post, $update = false ) {
109
-    if ( !( !empty( $_POST['action'] ) && $_POST['action'] == 'inline-save' ) ) {
108
+function wpinv_bulk_and_quick_edit_save($post_id, $post, $update = false) {
109
+    if (!(!empty($_POST['action']) && $_POST['action'] == 'inline-save')) {
110 110
         return;
111 111
     }
112 112
     
113 113
     // $post_id and $post are required
114
-    if ( empty( $post_id ) || empty( $post ) ) {
114
+    if (empty($post_id) || empty($post)) {
115 115
         return;
116 116
     }
117 117
         
118
-    if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) {
118
+    if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) {
119 119
         return;
120 120
     }
121 121
     
122 122
     // Dont' save meta boxes for revisions or autosaves
123
-    if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
123
+    if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
124 124
         return;
125 125
     }
126 126
 
127
-    if ( $post->post_type == 'wpi_item' ) {
127
+    if ($post->post_type == 'wpi_item') {
128 128
         // verify nonce
129
-        if ( isset( $_POST['_wpinv_item_price'] ) && get_post_meta( $post->ID, '_wpinv_type', true ) !== 'package' ) {
130
-            update_post_meta( $post_id, '_wpinv_price', wpinv_sanitize_amount( $_POST['_wpinv_item_price'] ) );
129
+        if (isset($_POST['_wpinv_item_price']) && get_post_meta($post->ID, '_wpinv_type', true) !== 'package') {
130
+            update_post_meta($post_id, '_wpinv_price', wpinv_sanitize_amount($_POST['_wpinv_item_price']));
131 131
         }
132 132
         
133
-        if ( isset( $_POST['_wpinv_vat_class'] ) ) {
134
-            update_post_meta( $post_id, '_wpinv_vat_class', sanitize_text_field( $_POST['_wpinv_vat_class'] ) );
133
+        if (isset($_POST['_wpinv_vat_class'])) {
134
+            update_post_meta($post_id, '_wpinv_vat_class', sanitize_text_field($_POST['_wpinv_vat_class']));
135 135
         }
136 136
 
137
-        if ( isset( $_POST['_wpinv_vat_rules'] ) ) {
138
-            update_post_meta( $post_id, '_wpinv_vat_rule', sanitize_text_field( $_POST['_wpinv_vat_rules'] ) );
137
+        if (isset($_POST['_wpinv_vat_rules'])) {
138
+            update_post_meta($post_id, '_wpinv_vat_rule', sanitize_text_field($_POST['_wpinv_vat_rules']));
139 139
         }
140 140
         
141
-        if ( isset( $_POST['_wpinv_item_type'] ) ) {
142
-            update_post_meta( $post_id, '_wpinv_type', sanitize_text_field( $_POST['_wpinv_item_type'] ) );
141
+        if (isset($_POST['_wpinv_item_type'])) {
142
+            update_post_meta($post_id, '_wpinv_type', sanitize_text_field($_POST['_wpinv_item_type']));
143 143
         }
144 144
     }
145 145
 }
146
-add_action( 'save_post', 'wpinv_bulk_and_quick_edit_save', 10, 3 );
146
+add_action('save_post', 'wpinv_bulk_and_quick_edit_save', 10, 3);
147 147
 
148 148
 function wpinv_register_item_meta_boxes() {    
149 149
     global $wpinv_euvat;
150 150
     
151
-    add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' );
151
+    add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high');
152 152
 
153
-    if ( $wpinv_euvat->allow_vat_rules() ) {
154
-        add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' );
153
+    if ($wpinv_euvat->allow_vat_rules()) {
154
+        add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high');
155 155
     }
156 156
     
157
-    if ( $wpinv_euvat->allow_vat_classes() ) {
158
-        add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' );
157
+    if ($wpinv_euvat->allow_vat_classes()) {
158
+        add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high');
159 159
     }
160 160
     
161
-    add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' );
162
-    add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' );
161
+    add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core');
162
+    add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core');
163 163
 }
164 164
 
165 165
 function wpinv_register_discount_meta_boxes() {
166
-    add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' );
166
+    add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high');
167 167
 }
168 168
 
169
-function wpinv_discount_metabox_details( $post ) {
169
+function wpinv_discount_metabox_details($post) {
170 170
     $discount_id    = $post->ID;
171
-    $discount       = wpinv_get_discount( $discount_id );
171
+    $discount       = wpinv_get_discount($discount_id);
172 172
     
173
-    $type           = wpinv_get_discount_type( $discount_id );
174
-    $item_reqs      = wpinv_get_discount_item_reqs( $discount_id );
175
-    $excluded_items = wpinv_get_discount_excluded_items( $discount_id );
176
-    $min_total      = wpinv_get_discount_min_total( $discount_id );
177
-    $max_total      = wpinv_get_discount_max_total( $discount_id );
178
-    $max_uses       = wpinv_get_discount_max_uses( $discount_id );
179
-    $single_use     = wpinv_discount_is_single_use( $discount_id );
180
-    $recurring      = (bool)wpinv_discount_is_recurring( $discount_id );
173
+    $type           = wpinv_get_discount_type($discount_id);
174
+    $item_reqs      = wpinv_get_discount_item_reqs($discount_id);
175
+    $excluded_items = wpinv_get_discount_excluded_items($discount_id);
176
+    $min_total      = wpinv_get_discount_min_total($discount_id);
177
+    $max_total      = wpinv_get_discount_max_total($discount_id);
178
+    $max_uses       = wpinv_get_discount_max_uses($discount_id);
179
+    $single_use     = wpinv_discount_is_single_use($discount_id);
180
+    $recurring      = (bool)wpinv_discount_is_recurring($discount_id);
181 181
     
182 182
     $min_total      = $min_total > 0 ? $min_total : '';
183 183
     $max_total      = $max_total > 0 ? $max_total : '';
184 184
     $max_uses       = $max_uses > 0 ? $max_uses : '';
185 185
 ?>
186
-<?php do_action( 'wpinv_discount_form_top', $post ); ?>
187
-<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?>
186
+<?php do_action('wpinv_discount_form_top', $post); ?>
187
+<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?>
188 188
 <table class="form-table wpi-form-table">
189 189
     <tbody>
190
-        <?php do_action( 'wpinv_discount_form_first', $post ); ?>
191
-        <?php do_action( 'wpinv_discount_form_before_code', $post ); ?>
190
+        <?php do_action('wpinv_discount_form_first', $post); ?>
191
+        <?php do_action('wpinv_discount_form_before_code', $post); ?>
192 192
         <tr>
193 193
             <th valign="top" scope="row">
194
-                <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label>
194
+                <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label>
195 195
             </th>
196 196
             <td>
197
-                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required>
198
-                <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p>
197
+                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required>
198
+                <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p>
199 199
             </td>
200 200
         </tr>
201
-        <?php do_action( 'wpinv_discount_form_before_type', $post ); ?>
201
+        <?php do_action('wpinv_discount_form_before_type', $post); ?>
202 202
         <tr>
203 203
             <th valign="top" scope="row">
204
-                <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label>
204
+                <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label>
205 205
             </th>
206 206
             <td>
207 207
                 <select id="wpinv_discount_type" name="type" class="medium-text">
208
-                    <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?>
209
-                    <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option>
208
+                    <?php foreach (wpinv_get_discount_types() as $value => $label) { ?>
209
+                    <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option>
210 210
                     <?php } ?>
211 211
                 </select>
212
-                <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p>
212
+                <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p>
213 213
             </td>
214 214
         </tr>
215
-        <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?>
215
+        <?php do_action('wpinv_discount_form_before_amount', $post); ?>
216 216
         <tr>
217 217
             <th valign="top" scope="row">
218
-                <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label>
218
+                <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label>
219 219
             </th>
220 220
             <td>
221
-                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font>
222
-                <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p>
223
-                <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p>
221
+                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font>
222
+                <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p>
223
+                <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p>
224 224
             </td>
225 225
         </tr>
226
-        <?php do_action( 'wpinv_discount_form_before_items', $post ); ?>
226
+        <?php do_action('wpinv_discount_form_before_items', $post); ?>
227 227
         <tr>
228 228
             <th valign="top" scope="row">
229
-                <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label>
229
+                <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label>
230 230
             </th>
231 231
             <td>
232
-                <p><?php echo wpinv_item_dropdown( array(
232
+                <p><?php echo wpinv_item_dropdown(array(
233 233
                         'name'              => 'items[]',
234 234
                         'id'                => 'items',
235 235
                         'selected'          => $item_reqs,
236 236
                         'multiple'          => true,
237 237
                         'chosen'            => true,
238 238
                         'class'             => 'medium-text',
239
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
239
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
240 240
                         'show_recurring'    => true,
241
-                    ) ); ?>
241
+                    )); ?>
242 242
                 </p>
243
-                <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p>
243
+                <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p>
244 244
             </td>
245 245
         </tr>
246
-        <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?>
246
+        <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?>
247 247
         <tr>
248 248
             <th valign="top" scope="row">
249
-                <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label>
249
+                <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label>
250 250
             </th>
251 251
             <td>
252
-                <p><?php echo wpinv_item_dropdown( array(
252
+                <p><?php echo wpinv_item_dropdown(array(
253 253
                         'name'              => 'excluded_items[]',
254 254
                         'id'                => 'excluded_items',
255 255
                         'selected'          => $excluded_items,
256 256
                         'multiple'          => true,
257 257
                         'chosen'            => true,
258 258
                         'class'             => 'medium-text',
259
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
259
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
260 260
                         'show_recurring'    => true,
261
-                    ) ); ?>
261
+                    )); ?>
262 262
                 </p>
263
-                <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p>
263
+                <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p>
264 264
             </td>
265 265
         </tr>
266
-        <?php do_action( 'wpinv_discount_form_before_start', $post ); ?>
266
+        <?php do_action('wpinv_discount_form_before_start', $post); ?>
267 267
         <tr>
268 268
             <th valign="top" scope="row">
269
-                <label for="wpinv_discount_start"><?php _e( 'Start date', 'invoicing' ); ?></label>
269
+                <label for="wpinv_discount_start"><?php _e('Start date', 'invoicing'); ?></label>
270 270
             </th>
271 271
             <td>
272
-                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( wpinv_get_discount_start_date( $discount_id ) ); ?>">
273
-                <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p>
272
+                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr(wpinv_get_discount_start_date($discount_id)); ?>">
273
+                <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p>
274 274
             </td>
275 275
         </tr>
276
-        <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?>
276
+        <?php do_action('wpinv_discount_form_before_expiration', $post); ?>
277 277
         <tr>
278 278
             <th valign="top" scope="row">
279
-                <label for="wpinv_discount_expiration"><?php _e( 'Expiration date', 'invoicing' ); ?></label>
279
+                <label for="wpinv_discount_expiration"><?php _e('Expiration date', 'invoicing'); ?></label>
280 280
             </th>
281 281
             <td>
282
-                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( wpinv_get_discount_expiration( $discount_id ) ); ?>">
283
-                <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p>
282
+                <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr(wpinv_get_discount_expiration($discount_id)); ?>">
283
+                <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p>
284 284
             </td>
285 285
         </tr>
286
-        <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?>
286
+        <?php do_action('wpinv_discount_form_before_min_total', $post); ?>
287 287
         <tr>
288 288
             <th valign="top" scope="row">
289
-                <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label>
289
+                <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label>
290 290
             </th>
291 291
             <td>
292 292
                 <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>">
293
-                <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
293
+                <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
294 294
             </td>
295 295
         </tr>
296
-        <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?>
296
+        <?php do_action('wpinv_discount_form_before_max_total', $post); ?>
297 297
         <tr>
298 298
             <th valign="top" scope="row">
299
-                <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label>
299
+                <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label>
300 300
             </th>
301 301
             <td>
302 302
                 <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>">
303
-                <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
303
+                <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
304 304
             </td>
305 305
         </tr>
306
-        <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?>
306
+        <?php do_action('wpinv_discount_form_before_recurring', $post); ?>
307 307
         <tr>
308 308
             <th valign="top" scope="row">
309
-                <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label>
309
+                <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label>
310 310
             </th>
311 311
             <td>
312 312
                 <select id="wpinv_discount_recurring" name="recurring" class="medium-text">
313
-                    <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option>
314
-                    <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option>
313
+                    <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option>
314
+                    <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option>
315 315
                 </select>
316
-                <p class="description"><?php _e( '<b>All payments:</b> apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p>
316
+                <p class="description"><?php _e('<b>All payments:</b> apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p>
317 317
             </td>
318 318
         </tr>
319
-        <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?>
319
+        <?php do_action('wpinv_discount_form_before_max_uses', $post); ?>
320 320
         <tr>
321 321
             <th valign="top" scope="row">
322
-                <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label>
322
+                <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label>
323 323
             </th>
324 324
             <td>
325 325
                 <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>">
326
-                <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p>
326
+                <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p>
327 327
             </td>
328 328
         </tr>
329
-        <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?>
329
+        <?php do_action('wpinv_discount_form_before_single_use', $post); ?>
330 330
         <tr>
331 331
             <th valign="top" scope="row">
332
-                <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label>
332
+                <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label>
333 333
             </th>
334 334
             <td>
335
-                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>>
336
-                <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span>
335
+                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>>
336
+                <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span>
337 337
             </td>
338 338
         </tr>
339
-        <?php do_action( 'wpinv_discount_form_last', $post ); ?>
339
+        <?php do_action('wpinv_discount_form_last', $post); ?>
340 340
     </tbody>
341 341
 </table>
342
-<?php do_action( 'wpinv_discount_form_bottom', $post ); ?>
342
+<?php do_action('wpinv_discount_form_bottom', $post); ?>
343 343
     <?php
344 344
 }
345 345
 
346
-function wpinv_discount_metabox_save( $post_id, $post, $update = false ) {
347
-    $post_type = !empty( $post ) ? $post->post_type : '';
346
+function wpinv_discount_metabox_save($post_id, $post, $update = false) {
347
+    $post_type = !empty($post) ? $post->post_type : '';
348 348
     
349
-    if ( $post_type != 'wpi_discount' ) {
349
+    if ($post_type != 'wpi_discount') {
350 350
         return;
351 351
     }
352 352
     
353
-    if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) {
353
+    if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) {
354 354
         return;
355 355
     }
356 356
     
357
-    if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
357
+    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
358 358
         return;
359 359
     }
360 360
     
361
-    if ( !current_user_can( 'manage_options', $post_id ) ) {
361
+    if (!current_user_can('manage_options', $post_id)) {
362 362
         return;
363 363
     }
364 364
     
365
-    return wpinv_store_discount( $post_id, $_POST, $post, $update );
365
+    return wpinv_store_discount($post_id, $_POST, $post, $update);
366 366
 }
367
-add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 );
368 367
\ No newline at end of file
368
+add_action('save_post', 'wpinv_discount_metabox_save', 10, 3);
369 369
\ No newline at end of file
Please login to merge, or discard this patch.