@@ -7,14 +7,14 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function wpinv_get_invoice_cart_id() { |
| 15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
| 16 | 16 | |
| 17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
| 17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
| 18 | 18 | return $wpinv_checkout['invoice_id']; |
| 19 | 19 | } |
| 20 | 20 | |
@@ -28,27 +28,27 @@ discard block |
||
| 28 | 28 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
| 29 | 29 | * @return mixed The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
| 30 | 30 | */ |
| 31 | -function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) { |
|
| 32 | - if ( empty( $invoice_data ) ) { |
|
| 31 | +function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) { |
|
| 32 | + if (empty($invoice_data)) { |
|
| 33 | 33 | return false; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
| 37 | - return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0; |
|
| 36 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
| 37 | + return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // If no user id is provided, default to the current user id |
| 41 | - if ( empty( $invoice_data['user_id'] ) ) { |
|
| 41 | + if (empty($invoice_data['user_id'])) { |
|
| 42 | 42 | $invoice_data['user_id'] = get_current_user_id(); |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0; |
|
| 45 | + $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0; |
|
| 46 | 46 | |
| 47 | - if ( empty( $invoice_data['status'] ) ) { |
|
| 47 | + if (empty($invoice_data['status'])) { |
|
| 48 | 48 | $invoice_data['status'] = 'wpi-pending'; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - if ( empty( $invoice_data['ip'] ) ) { |
|
| 51 | + if (empty($invoice_data['ip'])) { |
|
| 52 | 52 | $invoice_data['ip'] = wpinv_get_ip(); |
| 53 | 53 | } |
| 54 | 54 | |
@@ -59,12 +59,12 @@ discard block |
||
| 59 | 59 | 'status' => $invoice_data['status'], |
| 60 | 60 | ); |
| 61 | 61 | |
| 62 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data, true ); |
|
| 63 | - if ( is_wp_error( $invoice ) ) { |
|
| 62 | + $invoice = wpinv_create_invoice($default_args, $invoice_data, true); |
|
| 63 | + if (is_wp_error($invoice)) { |
|
| 64 | 64 | return $wp_error ? $invoice : 0; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if ( empty( $invoice_data['invoice_id'] ) ) { |
|
| 67 | + if (empty($invoice_data['invoice_id'])) { |
|
| 68 | 68 | //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -87,24 +87,24 @@ discard block |
||
| 87 | 87 | 'discount' => array(), |
| 88 | 88 | ); |
| 89 | 89 | |
| 90 | - if ( $user_id = (int)$invoice->get_user_id() ) { |
|
| 91 | - if ( $user_address = wpinv_get_user_address( $user_id ) ) { |
|
| 92 | - $default_user_info = wp_parse_args( $user_address, $default_user_info ); |
|
| 90 | + if ($user_id = (int)$invoice->get_user_id()) { |
|
| 91 | + if ($user_address = wpinv_get_user_address($user_id)) { |
|
| 92 | + $default_user_info = wp_parse_args($user_address, $default_user_info); |
|
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if ( empty( $invoice_data['user_info'] ) ) { |
|
| 96 | + if (empty($invoice_data['user_info'])) { |
|
| 97 | 97 | $invoice_data['user_info'] = array(); |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info ); |
|
| 100 | + $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info); |
|
| 101 | 101 | |
| 102 | - if ( empty( $user_info['first_name'] ) ) { |
|
| 102 | + if (empty($user_info['first_name'])) { |
|
| 103 | 103 | $user_info['first_name'] = $default_user_info['first_name']; |
| 104 | 104 | $user_info['last_name'] = $default_user_info['last_name']; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - if ( empty( $user_info['country'] ) ) { |
|
| 107 | + if (empty($user_info['country'])) { |
|
| 108 | 108 | $user_info['country'] = $default_user_info['country']; |
| 109 | 109 | $user_info['state'] = $default_user_info['state']; |
| 110 | 110 | $user_info['city'] = $default_user_info['city']; |
@@ -113,13 +113,13 @@ discard block |
||
| 113 | 113 | $user_info['phone'] = $default_user_info['phone']; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) { |
|
| 116 | + if (!empty($user_info['discount']) && !is_array($user_info['discount'])) { |
|
| 117 | 117 | $user_info['discount'] = (array)$user_info['discount']; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | // Payment details |
| 121 | 121 | $payment_details = array(); |
| 122 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
| 122 | + if (!empty($invoice_data['payment_details'])) { |
|
| 123 | 123 | $default_payment_details = array( |
| 124 | 124 | 'gateway' => 'manual', |
| 125 | 125 | 'gateway_title' => '', |
@@ -127,56 +127,56 @@ discard block |
||
| 127 | 127 | 'transaction_id' => '', |
| 128 | 128 | ); |
| 129 | 129 | |
| 130 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details ); |
|
| 130 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details); |
|
| 131 | 131 | |
| 132 | - if ( empty( $payment_details['gateway'] ) ) { |
|
| 132 | + if (empty($payment_details['gateway'])) { |
|
| 133 | 133 | $payment_details['gateway'] = 'manual'; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if ( empty( $payment_details['currency'] ) ) { |
|
| 136 | + if (empty($payment_details['currency'])) { |
|
| 137 | 137 | $payment_details['currency'] = wpinv_get_default_country(); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if ( empty( $payment_details['gateway_title'] ) ) { |
|
| 141 | - $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] ); |
|
| 140 | + if (empty($payment_details['gateway_title'])) { |
|
| 141 | + $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']); |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) ); |
|
| 146 | - |
|
| 147 | - if ( !empty( $payment_details ) ) { |
|
| 148 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
| 149 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
| 150 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
| 151 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - $invoice->set( 'user_info', $user_info ); |
|
| 155 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
| 156 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
| 157 | - $invoice->set( 'address', $user_info['address'] ); |
|
| 158 | - $invoice->set( 'company', $user_info['company'] ); |
|
| 159 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
| 160 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
| 161 | - $invoice->set( 'city', $user_info['city'] ); |
|
| 162 | - $invoice->set( 'country', $user_info['country'] ); |
|
| 163 | - $invoice->set( 'state', $user_info['state'] ); |
|
| 164 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
| 165 | - $invoice->set( 'discounts', $user_info['discount'] ); |
|
| 166 | - $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) ); |
|
| 167 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
| 168 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
| 169 | - |
|
| 170 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
| 171 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
| 172 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 173 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 174 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
| 175 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
| 145 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending')); |
|
| 146 | + |
|
| 147 | + if (!empty($payment_details)) { |
|
| 148 | + $invoice->set('currency', $payment_details['currency']); |
|
| 149 | + $invoice->set('gateway', $payment_details['gateway']); |
|
| 150 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
| 151 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + $invoice->set('user_info', $user_info); |
|
| 155 | + $invoice->set('first_name', $user_info['first_name']); |
|
| 156 | + $invoice->set('last_name', $user_info['last_name']); |
|
| 157 | + $invoice->set('address', $user_info['address']); |
|
| 158 | + $invoice->set('company', $user_info['company']); |
|
| 159 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
| 160 | + $invoice->set('phone', $user_info['phone']); |
|
| 161 | + $invoice->set('city', $user_info['city']); |
|
| 162 | + $invoice->set('country', $user_info['country']); |
|
| 163 | + $invoice->set('state', $user_info['state']); |
|
| 164 | + $invoice->set('zip', $user_info['zip']); |
|
| 165 | + $invoice->set('discounts', $user_info['discount']); |
|
| 166 | + $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip())); |
|
| 167 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
| 168 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
| 169 | + |
|
| 170 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
| 171 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
| 172 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 173 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 174 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
| 175 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
| 176 | 176 | |
| 177 | - $post_item = new WPInv_Item( $item_id ); |
|
| 178 | - if ( !empty( $post_item ) ) { |
|
| 179 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
| 177 | + $post_item = new WPInv_Item($item_id); |
|
| 178 | + if (!empty($post_item)) { |
|
| 179 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
| 180 | 180 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
| 181 | 181 | } else { |
| 182 | 182 | continue; |
@@ -186,253 +186,253 @@ discard block |
||
| 186 | 186 | 'name' => $name, |
| 187 | 187 | 'quantity' => $quantity, |
| 188 | 188 | 'item_price' => $item_price, |
| 189 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 190 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
| 191 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
| 192 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 193 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
| 189 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 190 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
| 191 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
| 192 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 193 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
| 194 | 194 | ); |
| 195 | 195 | |
| 196 | - $invoice->add_item( $item_id, $args ); |
|
| 196 | + $invoice->add_item($item_id, $args); |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
| 200 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
| 201 | 201 | |
| 202 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
| 203 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
| 202 | + if (isset($invoice_data['post_date'])) { |
|
| 203 | + $invoice->set('date', $invoice_data['post_date']); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | // Invoice due date |
| 207 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
| 208 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
| 207 | + if (isset($invoice_data['due_date'])) { |
|
| 208 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | $invoice->save(); |
| 212 | 212 | |
| 213 | 213 | // Add notes |
| 214 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
| 215 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
| 214 | + if (!empty($invoice_data['private_note'])) { |
|
| 215 | + $invoice->add_note($invoice_data['private_note']); |
|
| 216 | 216 | } |
| 217 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
| 218 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
| 217 | + if (!empty($invoice_data['user_note'])) { |
|
| 218 | + $invoice->add_note($invoice_data['user_note'], true); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
| 221 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
| 222 | 222 | |
| 223 | - if ( ! empty( $invoice->ID ) ) { |
|
| 223 | + if (!empty($invoice->ID)) { |
|
| 224 | 224 | global $wpi_userID, $wpinv_ip_address_country; |
| 225 | 225 | |
| 226 | 226 | $checkout_session = wpinv_get_checkout_session(); |
| 227 | 227 | |
| 228 | 228 | $data_session = array(); |
| 229 | 229 | $data_session['invoice_id'] = $invoice->ID; |
| 230 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 230 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
| 231 | 231 | |
| 232 | - wpinv_set_checkout_session( $data_session ); |
|
| 232 | + wpinv_set_checkout_session($data_session); |
|
| 233 | 233 | |
| 234 | 234 | $wpi_userID = (int)$invoice->get_user_id(); |
| 235 | 235 | |
| 236 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
| 236 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
| 237 | 237 | $_POST['state'] = $invoice->state; |
| 238 | 238 | |
| 239 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 240 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 239 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 240 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 241 | 241 | |
| 242 | 242 | $wpinv_ip_address_country = $invoice->country; |
| 243 | 243 | |
| 244 | - $invoice = $invoice->recalculate_totals( true ); |
|
| 244 | + $invoice = $invoice->recalculate_totals(true); |
|
| 245 | 245 | |
| 246 | - wpinv_set_checkout_session( $checkout_session ); |
|
| 246 | + wpinv_set_checkout_session($checkout_session); |
|
| 247 | 247 | |
| 248 | 248 | return $invoice; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - if ( $wp_error ) { |
|
| 252 | - if ( is_wp_error( $invoice ) ) { |
|
| 251 | + if ($wp_error) { |
|
| 252 | + if (is_wp_error($invoice)) { |
|
| 253 | 253 | return $invoice; |
| 254 | 254 | } else { |
| 255 | - return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) ); |
|
| 255 | + return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing')); |
|
| 256 | 256 | } |
| 257 | 257 | } else { |
| 258 | 258 | return 0; |
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | -function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) { |
|
| 263 | - $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL; |
|
| 262 | +function wpinv_update_invoice($invoice_data = array(), $wp_error = false) { |
|
| 263 | + $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL; |
|
| 264 | 264 | |
| 265 | - if ( !$invoice_ID ) { |
|
| 266 | - if ( $wp_error ) { |
|
| 267 | - return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ); |
|
| 265 | + if (!$invoice_ID) { |
|
| 266 | + if ($wp_error) { |
|
| 267 | + return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')); |
|
| 268 | 268 | } |
| 269 | 269 | return 0; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - $invoice = wpinv_get_invoice( $invoice_ID ); |
|
| 272 | + $invoice = wpinv_get_invoice($invoice_ID); |
|
| 273 | 273 | |
| 274 | - $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL; |
|
| 274 | + $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL; |
|
| 275 | 275 | |
| 276 | - if ( empty( $invoice->ID ) ) { |
|
| 277 | - if ( $wp_error ) { |
|
| 278 | - return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) ); |
|
| 276 | + if (empty($invoice->ID)) { |
|
| 277 | + if ($wp_error) { |
|
| 278 | + return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing')); |
|
| 279 | 279 | } |
| 280 | 280 | return 0; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if ( !$invoice->has_status( array( 'wpi-pending' ) ) ) { |
|
| 284 | - if ( $wp_error ) { |
|
| 285 | - return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) ); |
|
| 283 | + if (!$invoice->has_status(array('wpi-pending'))) { |
|
| 284 | + if ($wp_error) { |
|
| 285 | + return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing')); |
|
| 286 | 286 | } |
| 287 | 287 | return 0; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | // Invoice status |
| 291 | - if ( !empty( $invoice_data['status'] ) ) { |
|
| 292 | - $invoice->set( 'status', $invoice_data['status'] ); |
|
| 291 | + if (!empty($invoice_data['status'])) { |
|
| 292 | + $invoice->set('status', $invoice_data['status']); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | // Invoice date |
| 296 | - if ( !empty( $invoice_data['post_date'] ) ) { |
|
| 297 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
| 296 | + if (!empty($invoice_data['post_date'])) { |
|
| 297 | + $invoice->set('date', $invoice_data['post_date']); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | // Invoice due date |
| 301 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
| 302 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
| 301 | + if (isset($invoice_data['due_date'])) { |
|
| 302 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | // Invoice IP address |
| 306 | - if ( !empty( $invoice_data['ip'] ) ) { |
|
| 307 | - $invoice->set( 'ip', $invoice_data['ip'] ); |
|
| 306 | + if (!empty($invoice_data['ip'])) { |
|
| 307 | + $invoice->set('ip', $invoice_data['ip']); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | // User info |
| 311 | - if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) { |
|
| 312 | - $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info ); |
|
| 311 | + if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) { |
|
| 312 | + $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info); |
|
| 313 | 313 | |
| 314 | - if ( $discounts = $invoice->get_discounts() ) { |
|
| 314 | + if ($discounts = $invoice->get_discounts()) { |
|
| 315 | 315 | $set_discount = $discounts; |
| 316 | 316 | } else { |
| 317 | 317 | $set_discount = ''; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | // Manage discount |
| 321 | - if ( !empty( $invoice_data['user_info']['discount'] ) ) { |
|
| 321 | + if (!empty($invoice_data['user_info']['discount'])) { |
|
| 322 | 322 | // Remove discount |
| 323 | - if ( $invoice_data['user_info']['discount'] == 'none' ) { |
|
| 323 | + if ($invoice_data['user_info']['discount'] == 'none') { |
|
| 324 | 324 | $set_discount = ''; |
| 325 | 325 | } else { |
| 326 | 326 | $set_discount = $invoice_data['user_info']['discount']; |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - $invoice->set( 'discounts', $set_discount ); |
|
| 329 | + $invoice->set('discounts', $set_discount); |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | $user_info['discount'] = $set_discount; |
| 333 | 333 | |
| 334 | - $invoice->set( 'user_info', $user_info ); |
|
| 334 | + $invoice->set('user_info', $user_info); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) { |
|
| 338 | - $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array(); |
|
| 337 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) { |
|
| 338 | + $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array(); |
|
| 339 | 339 | |
| 340 | - if ( !empty( $remove_items[0]['id'] ) ) { |
|
| 341 | - foreach ( $remove_items as $item ) { |
|
| 342 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 343 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 344 | - if ( empty( $item_id ) ) { |
|
| 340 | + if (!empty($remove_items[0]['id'])) { |
|
| 341 | + foreach ($remove_items as $item) { |
|
| 342 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 343 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 344 | + if (empty($item_id)) { |
|
| 345 | 345 | continue; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - foreach ( $invoice->cart_details as $cart_index => $cart_item ) { |
|
| 349 | - if ( $item_id == $cart_item['id'] ) { |
|
| 348 | + foreach ($invoice->cart_details as $cart_index => $cart_item) { |
|
| 349 | + if ($item_id == $cart_item['id']) { |
|
| 350 | 350 | $args = array( |
| 351 | 351 | 'id' => $item_id, |
| 352 | 352 | 'quantity' => $quantity, |
| 353 | 353 | 'cart_index' => $cart_index |
| 354 | 354 | ); |
| 355 | 355 | |
| 356 | - $invoice->remove_item( $item_id, $args ); |
|
| 356 | + $invoice->remove_item($item_id, $args); |
|
| 357 | 357 | break; |
| 358 | 358 | } |
| 359 | 359 | } |
| 360 | 360 | } |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array(); |
|
| 363 | + $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array(); |
|
| 364 | 364 | |
| 365 | - if ( !empty( $add_items[0]['id'] ) ) { |
|
| 366 | - foreach ( $add_items as $item ) { |
|
| 367 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
| 368 | - $post_item = new WPInv_Item( $item_id ); |
|
| 369 | - if ( empty( $post_item ) ) { |
|
| 365 | + if (!empty($add_items[0]['id'])) { |
|
| 366 | + foreach ($add_items as $item) { |
|
| 367 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
| 368 | + $post_item = new WPInv_Item($item_id); |
|
| 369 | + if (empty($post_item)) { |
|
| 370 | 370 | continue; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | $valid_item = true; |
| 374 | - if ( !empty( $recurring_item ) ) { |
|
| 375 | - if ( $recurring_item->ID != $item_id ) { |
|
| 374 | + if (!empty($recurring_item)) { |
|
| 375 | + if ($recurring_item->ID != $item_id) { |
|
| 376 | 376 | $valid_item = false; |
| 377 | 377 | } |
| 378 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
| 378 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
| 379 | 379 | $valid_item = false; |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - if ( !$valid_item ) { |
|
| 383 | - if ( $wp_error ) { |
|
| 384 | - return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) ); |
|
| 382 | + if (!$valid_item) { |
|
| 383 | + if ($wp_error) { |
|
| 384 | + return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing')); |
|
| 385 | 385 | } |
| 386 | 386 | return 0; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
| 390 | - $name = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name(); |
|
| 391 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price(); |
|
| 389 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
| 390 | + $name = !empty($item['name']) ? $item['name'] : $post_item->get_name(); |
|
| 391 | + $item_price = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price(); |
|
| 392 | 392 | |
| 393 | 393 | $args = array( |
| 394 | 394 | 'name' => $name, |
| 395 | 395 | 'quantity' => $quantity, |
| 396 | 396 | 'item_price' => $item_price, |
| 397 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 398 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0, |
|
| 399 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
| 400 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 401 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
| 397 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 398 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0, |
|
| 399 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
| 400 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 401 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
| 402 | 402 | ); |
| 403 | 403 | |
| 404 | - $invoice->add_item( $item_id, $args ); |
|
| 404 | + $invoice->add_item($item_id, $args); |
|
| 405 | 405 | } |
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | // Payment details |
| 410 | - if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) { |
|
| 411 | - if ( !empty( $payment_details['gateway'] ) ) { |
|
| 412 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
| 410 | + if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) { |
|
| 411 | + if (!empty($payment_details['gateway'])) { |
|
| 412 | + $invoice->set('gateway', $payment_details['gateway']); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - if ( !empty( $payment_details['transaction_id'] ) ) { |
|
| 416 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
| 415 | + if (!empty($payment_details['transaction_id'])) { |
|
| 416 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | 419 | |
| 420 | - do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data ); |
|
| 420 | + do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data); |
|
| 421 | 421 | |
| 422 | 422 | // Parent invoice |
| 423 | - if ( !empty( $invoice_data['parent'] ) ) { |
|
| 424 | - $invoice->set( 'parent_invoice', $invoice_data['parent'] ); |
|
| 423 | + if (!empty($invoice_data['parent'])) { |
|
| 424 | + $invoice->set('parent_invoice', $invoice_data['parent']); |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | // Save invoice data. |
| 428 | 428 | $invoice->save(); |
| 429 | 429 | |
| 430 | - if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) { |
|
| 431 | - if ( $wp_error ) { |
|
| 432 | - if ( is_wp_error( $invoice ) ) { |
|
| 430 | + if (empty($invoice->ID) || is_wp_error($invoice)) { |
|
| 431 | + if ($wp_error) { |
|
| 432 | + if (is_wp_error($invoice)) { |
|
| 433 | 433 | return $invoice; |
| 434 | 434 | } else { |
| 435 | - return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) ); |
|
| 435 | + return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing')); |
|
| 436 | 436 | } |
| 437 | 437 | } else { |
| 438 | 438 | return 0; |
@@ -440,13 +440,13 @@ discard block |
||
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | // Add private note |
| 443 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
| 444 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
| 443 | + if (!empty($invoice_data['private_note'])) { |
|
| 444 | + $invoice->add_note($invoice_data['private_note']); |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | // Add user note |
| 448 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
| 449 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
| 448 | + if (!empty($invoice_data['user_note'])) { |
|
| 449 | + $invoice->add_note($invoice_data['user_note'], true); |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | global $wpi_userID, $wpinv_ip_address_country; |
@@ -455,450 +455,450 @@ discard block |
||
| 455 | 455 | |
| 456 | 456 | $data_session = array(); |
| 457 | 457 | $data_session['invoice_id'] = $invoice->ID; |
| 458 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 458 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
| 459 | 459 | |
| 460 | - wpinv_set_checkout_session( $data_session ); |
|
| 460 | + wpinv_set_checkout_session($data_session); |
|
| 461 | 461 | |
| 462 | 462 | $wpi_userID = (int)$invoice->get_user_id(); |
| 463 | 463 | |
| 464 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
| 464 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
| 465 | 465 | $_POST['state'] = $invoice->state; |
| 466 | 466 | |
| 467 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 468 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
| 467 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
| 468 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
| 469 | 469 | |
| 470 | 470 | $wpinv_ip_address_country = $invoice->country; |
| 471 | 471 | |
| 472 | - $invoice = $invoice->recalculate_totals( true ); |
|
| 472 | + $invoice = $invoice->recalculate_totals(true); |
|
| 473 | 473 | |
| 474 | - do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data ); |
|
| 474 | + do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data); |
|
| 475 | 475 | |
| 476 | - wpinv_set_checkout_session( $checkout_session ); |
|
| 476 | + wpinv_set_checkout_session($checkout_session); |
|
| 477 | 477 | |
| 478 | 478 | return $invoice; |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
| 482 | - if ( $cart && empty( $invoice_id ) ) { |
|
| 481 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
| 482 | + if ($cart && empty($invoice_id)) { |
|
| 483 | 483 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 486 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 487 | 487 | |
| 488 | - if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) { |
|
| 488 | + if (!empty($invoice) && !empty($invoice->ID)) { |
|
| 489 | 489 | return $invoice; |
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | return NULL; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
| 496 | - return wpinv_get_invoice( $invoice_id, true ); |
|
| 495 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
| 496 | + return wpinv_get_invoice($invoice_id, true); |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
| 500 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 499 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
| 500 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 501 | 501 | return $invoice->get_description(); |
| 502 | 502 | } |
| 503 | 503 | |
| 504 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
| 505 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 504 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
| 505 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 506 | 506 | return $invoice->get_currency(); |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
| 510 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 509 | +function wpinv_get_payment_user_email($invoice_id) { |
|
| 510 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 511 | 511 | return $invoice->get_email(); |
| 512 | 512 | } |
| 513 | 513 | |
| 514 | -function wpinv_get_user_id( $invoice_id ) { |
|
| 515 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 514 | +function wpinv_get_user_id($invoice_id) { |
|
| 515 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 516 | 516 | return $invoice->get_user_id(); |
| 517 | 517 | } |
| 518 | 518 | |
| 519 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
| 520 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 519 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
| 520 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 521 | 521 | |
| 522 | - return $invoice->get_status( $return_label ); |
|
| 522 | + return $invoice->get_status($return_label); |
|
| 523 | 523 | } |
| 524 | 524 | |
| 525 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
| 526 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 525 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
| 526 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 527 | 527 | |
| 528 | - return $invoice->get_gateway( $return_label ); |
|
| 528 | + return $invoice->get_gateway($return_label); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
| 532 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 531 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
| 532 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 533 | 533 | |
| 534 | 534 | return $invoice->get_gateway_title(); |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
| 538 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 537 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
| 538 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 539 | 539 | |
| 540 | 540 | return $invoice->get_transaction_id(); |
| 541 | 541 | } |
| 542 | 542 | |
| 543 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
| 543 | +function wpinv_get_id_by_transaction_id($key) { |
|
| 544 | 544 | global $wpdb; |
| 545 | 545 | |
| 546 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 546 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
| 547 | 547 | |
| 548 | - if ( $invoice_id != NULL ) |
|
| 548 | + if ($invoice_id != NULL) |
|
| 549 | 549 | return $invoice_id; |
| 550 | 550 | |
| 551 | 551 | return 0; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
| 555 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 554 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
| 555 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 556 | 556 | |
| 557 | - return $invoice->get_meta( $meta_key, $single ); |
|
| 557 | + return $invoice->get_meta($meta_key, $single); |
|
| 558 | 558 | } |
| 559 | 559 | |
| 560 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
| 561 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 560 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
| 561 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 562 | 562 | |
| 563 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
| 563 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
| 567 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 566 | +function wpinv_get_items($invoice_id = 0) { |
|
| 567 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 568 | 568 | |
| 569 | 569 | $items = $invoice->get_items(); |
| 570 | 570 | $invoice_currency = $invoice->get_currency(); |
| 571 | 571 | |
| 572 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
| 573 | - foreach ( $items as $key => $item ) { |
|
| 572 | + if (!empty($items) && is_array($items)) { |
|
| 573 | + foreach ($items as $key => $item) { |
|
| 574 | 574 | $items[$key]['currency'] = $invoice_currency; |
| 575 | 575 | |
| 576 | - if ( !isset( $item['subtotal'] ) ) { |
|
| 576 | + if (!isset($item['subtotal'])) { |
|
| 577 | 577 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
| 578 | 578 | } |
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | |
| 582 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
| 582 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
| 586 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 585 | +function wpinv_get_fees($invoice_id = 0) { |
|
| 586 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 587 | 587 | $fees = $invoice->get_fees(); |
| 588 | 588 | |
| 589 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
| 589 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
| 593 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 592 | +function wpinv_get_invoice_ip($invoice_id) { |
|
| 593 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 594 | 594 | return $invoice->get_ip(); |
| 595 | 595 | } |
| 596 | 596 | |
| 597 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
| 598 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 597 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
| 598 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 599 | 599 | return $invoice->get_user_info(); |
| 600 | 600 | } |
| 601 | 601 | |
| 602 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
| 603 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 602 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
| 603 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 604 | 604 | |
| 605 | - return $invoice->get_subtotal( $currency ); |
|
| 605 | + return $invoice->get_subtotal($currency); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
| 609 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 608 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
| 609 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 610 | 610 | |
| 611 | - return $invoice->get_tax( $currency ); |
|
| 611 | + return $invoice->get_tax($currency); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
| 615 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 614 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
| 615 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 616 | 616 | |
| 617 | - return $invoice->get_discount( $currency, $dash ); |
|
| 617 | + return $invoice->get_discount($currency, $dash); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
| 621 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 620 | +function wpinv_discount_code($invoice_id = 0) { |
|
| 621 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 622 | 622 | |
| 623 | 623 | return $invoice->get_discount_code(); |
| 624 | 624 | } |
| 625 | 625 | |
| 626 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
| 627 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 626 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
| 627 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 628 | 628 | |
| 629 | - return $invoice->get_total( $currency ); |
|
| 629 | + return $invoice->get_total($currency); |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | -function wpinv_get_date_created( $invoice_id = 0, $format = '' ) { |
|
| 633 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 632 | +function wpinv_get_date_created($invoice_id = 0, $format = '') { |
|
| 633 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 634 | 634 | |
| 635 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
| 635 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
| 636 | 636 | $date_created = $invoice->get_created_date(); |
| 637 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
| 637 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
| 638 | 638 | |
| 639 | 639 | return $date_created; |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) { |
|
| 643 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 642 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) { |
|
| 643 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 644 | 644 | |
| 645 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
| 645 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
| 646 | 646 | $date_completed = $invoice->get_completed_date(); |
| 647 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
| 648 | - if ( $invoice_date == '' && $default ) { |
|
| 649 | - $invoice_date = wpinv_get_date_created( $invoice_id, $format ); |
|
| 647 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
| 648 | + if ($invoice_date == '' && $default) { |
|
| 649 | + $invoice_date = wpinv_get_date_created($invoice_id, $format); |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | return $invoice_date; |
| 653 | 653 | } |
| 654 | 654 | |
| 655 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
| 656 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 655 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
| 656 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 657 | 657 | |
| 658 | 658 | return $invoice->vat_number; |
| 659 | 659 | } |
| 660 | 660 | |
| 661 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
| 662 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 661 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
| 662 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 663 | 663 | |
| 664 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
| 664 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
| 667 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
| 668 | 668 | global $invoicing; |
| 669 | 669 | |
| 670 | - if ( empty( $invoice_id ) ) { |
|
| 670 | + if (empty($invoice_id)) { |
|
| 671 | 671 | return NULL; |
| 672 | 672 | } |
| 673 | 673 | |
| 674 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
| 674 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
| 675 | 675 | |
| 676 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
| 676 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
| 680 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 679 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
| 680 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 681 | 681 | return $invoice->get_key(); |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
| 685 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 684 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
| 685 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 686 | 686 | return $invoice->get_number(); |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
| 689 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
| 690 | 690 | $cart_items = wpinv_get_cart_content_details(); |
| 691 | 691 | $items = array(); |
| 692 | 692 | |
| 693 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
| 693 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
| 694 | 694 | |
| 695 | - if( $cart_items ) { |
|
| 695 | + if ($cart_items) { |
|
| 696 | 696 | |
| 697 | - foreach( $cart_items as $item ) { |
|
| 697 | + foreach ($cart_items as $item) { |
|
| 698 | 698 | |
| 699 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
| 700 | - $items[] = $item; |
|
| 699 | + if (!in_array($item['id'], $excluded_items)) { |
|
| 700 | + $items[] = $item; |
|
| 701 | 701 | } |
| 702 | 702 | } |
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
| 705 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
| 706 | 706 | |
| 707 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
| 707 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
| 708 | 708 | } |
| 709 | 709 | |
| 710 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
| 710 | +function wpinv_get_cart_items_subtotal($items) { |
|
| 711 | 711 | $subtotal = 0.00; |
| 712 | 712 | |
| 713 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
| 714 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
| 713 | + if (is_array($items) && !empty($items)) { |
|
| 714 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
| 715 | 715 | |
| 716 | - if( is_array( $prices ) ) { |
|
| 717 | - $subtotal = array_sum( $prices ); |
|
| 716 | + if (is_array($prices)) { |
|
| 717 | + $subtotal = array_sum($prices); |
|
| 718 | 718 | } else { |
| 719 | 719 | $subtotal = 0.00; |
| 720 | 720 | } |
| 721 | 721 | |
| 722 | - if( $subtotal < 0 ) { |
|
| 722 | + if ($subtotal < 0) { |
|
| 723 | 723 | $subtotal = 0.00; |
| 724 | 724 | } |
| 725 | 725 | } |
| 726 | 726 | |
| 727 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
| 727 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
| 731 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 732 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
| 730 | +function wpinv_get_cart_subtotal($items = array()) { |
|
| 731 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 732 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
| 733 | 733 | |
| 734 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
| 734 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | -function wpinv_cart_subtotal( $items = array() ) { |
|
| 738 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) ); |
|
| 737 | +function wpinv_cart_subtotal($items = array()) { |
|
| 738 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items))); |
|
| 739 | 739 | |
| 740 | 740 | return $price; |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
| 744 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
| 745 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
| 746 | - $cart_tax = (float)wpinv_get_cart_tax( $items ); |
|
| 743 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
| 744 | + $subtotal = (float)wpinv_get_cart_subtotal($items); |
|
| 745 | + $discounts = (float)wpinv_get_cart_discounted_amount($items); |
|
| 746 | + $cart_tax = (float)wpinv_get_cart_tax($items); |
|
| 747 | 747 | $fees = (float)wpinv_get_cart_fee_total(); |
| 748 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
| 748 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
| 749 | 749 | $total = 0; |
| 750 | 750 | } else { |
| 751 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
| 751 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | - if ( $total < 0 ) { |
|
| 754 | + if ($total < 0) { |
|
| 755 | 755 | $total = 0.00; |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
| 758 | + $total = (float)apply_filters('wpinv_get_cart_total', $total, $items); |
|
| 759 | 759 | |
| 760 | - return wpinv_sanitize_amount( $total ); |
|
| 760 | + return wpinv_sanitize_amount($total); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
| 763 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
| 764 | 764 | global $cart_total; |
| 765 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) ); |
|
| 766 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
| 765 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice))); |
|
| 766 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
| 767 | 767 | |
| 768 | 768 | $cart_total = $total; |
| 769 | 769 | |
| 770 | - if ( !$echo ) { |
|
| 770 | + if (!$echo) { |
|
| 771 | 771 | return $total; |
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | echo $total; |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | -function wpinv_get_cart_tax( $items = array() ) { |
|
| 777 | +function wpinv_get_cart_tax($items = array()) { |
|
| 778 | 778 | $cart_tax = 0; |
| 779 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
| 779 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
| 780 | 780 | |
| 781 | - if ( $items ) { |
|
| 782 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
| 781 | + if ($items) { |
|
| 782 | + $taxes = wp_list_pluck($items, 'tax'); |
|
| 783 | 783 | |
| 784 | - if( is_array( $taxes ) ) { |
|
| 785 | - $cart_tax = array_sum( $taxes ); |
|
| 784 | + if (is_array($taxes)) { |
|
| 785 | + $cart_tax = array_sum($taxes); |
|
| 786 | 786 | } |
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | $cart_tax += wpinv_get_cart_fee_tax(); |
| 790 | 790 | |
| 791 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
| 791 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | -function wpinv_cart_tax( $items = array(), $echo = false ) { |
|
| 795 | - $cart_tax = wpinv_get_cart_tax( $items ); |
|
| 796 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) ); |
|
| 794 | +function wpinv_cart_tax($items = array(), $echo = false) { |
|
| 795 | + $cart_tax = wpinv_get_cart_tax($items); |
|
| 796 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax)); |
|
| 797 | 797 | |
| 798 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
| 798 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
| 799 | 799 | |
| 800 | - if ( !$echo ) { |
|
| 800 | + if (!$echo) { |
|
| 801 | 801 | return $tax; |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | echo $tax; |
| 805 | 805 | } |
| 806 | 806 | |
| 807 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
| 807 | +function wpinv_get_cart_discount_code($items = array()) { |
|
| 808 | 808 | $invoice = wpinv_get_invoice_cart(); |
| 809 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
| 809 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
| 810 | 810 | |
| 811 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
| 811 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
| 815 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
| 814 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
| 815 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
| 816 | 816 | |
| 817 | - if ( $cart_discount_code != '' ) { |
|
| 817 | + if ($cart_discount_code != '') { |
|
| 818 | 818 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
| 819 | 819 | } |
| 820 | 820 | |
| 821 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
| 821 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
| 822 | 822 | |
| 823 | - if ( !$echo ) { |
|
| 823 | + if (!$echo) { |
|
| 824 | 824 | return $discount_code; |
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | echo $discount_code; |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | -function wpinv_get_cart_discount( $items = array() ) { |
|
| 830 | +function wpinv_get_cart_discount($items = array()) { |
|
| 831 | 831 | $invoice = wpinv_get_invoice_cart(); |
| 832 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
| 832 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
| 833 | 833 | |
| 834 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
| 834 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
| 835 | 835 | } |
| 836 | 836 | |
| 837 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
| 838 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
| 839 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
| 837 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
| 838 | + $cart_discount = wpinv_get_cart_discount($items); |
|
| 839 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
| 840 | 840 | |
| 841 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
| 841 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
| 842 | 842 | |
| 843 | - if ( !$echo ) { |
|
| 843 | + if (!$echo) { |
|
| 844 | 844 | return $discount; |
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | echo $discount; |
| 848 | 848 | } |
| 849 | 849 | |
| 850 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
| 851 | - $item = new WPInv_Item( $item_id ); |
|
| 850 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
| 851 | + $item = new WPInv_Item($item_id); |
|
| 852 | 852 | |
| 853 | - return $item->get_fees( $type, $item_id ); |
|
| 853 | + return $item->get_fees($type, $item_id); |
|
| 854 | 854 | } |
| 855 | 855 | |
| 856 | 856 | function wpinv_get_cart_fee_total() { |
| 857 | - $total = 0; |
|
| 857 | + $total = 0; |
|
| 858 | 858 | $fees = wpinv_get_cart_fees(); |
| 859 | 859 | |
| 860 | - if ( $fees ) { |
|
| 861 | - foreach ( $fees as $fee_id => $fee ) { |
|
| 860 | + if ($fees) { |
|
| 861 | + foreach ($fees as $fee_id => $fee) { |
|
| 862 | 862 | $total += $fee['amount']; |
| 863 | 863 | } |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
| 866 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
| 867 | 867 | } |
| 868 | 868 | |
| 869 | 869 | function wpinv_get_cart_fee_tax() { |
| 870 | 870 | $tax = 0; |
| 871 | 871 | $fees = wpinv_get_cart_fees(); |
| 872 | 872 | |
| 873 | - if ( $fees ) { |
|
| 874 | - foreach ( $fees as $fee_id => $fee ) { |
|
| 875 | - if( ! empty( $fee['no_tax'] ) ) { |
|
| 873 | + if ($fees) { |
|
| 874 | + foreach ($fees as $fee_id => $fee) { |
|
| 875 | + if (!empty($fee['no_tax'])) { |
|
| 876 | 876 | continue; |
| 877 | 877 | } |
| 878 | 878 | |
| 879 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
| 879 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
| 880 | 880 | } |
| 881 | 881 | } |
| 882 | 882 | |
| 883 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
| 883 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | function wpinv_cart_has_recurring_item() { |
| 887 | 887 | $cart_items = wpinv_get_cart_contents(); |
| 888 | 888 | |
| 889 | - if ( empty( $cart_items ) ) { |
|
| 889 | + if (empty($cart_items)) { |
|
| 890 | 890 | return false; |
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | $has_subscription = false; |
| 894 | - foreach( $cart_items as $cart_item ) { |
|
| 895 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
| 894 | + foreach ($cart_items as $cart_item) { |
|
| 895 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
| 896 | 896 | $has_subscription = true; |
| 897 | 897 | break; |
| 898 | 898 | } |
| 899 | 899 | } |
| 900 | 900 | |
| 901 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
| 901 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | function wpinv_cart_has_free_trial() { |
@@ -906,97 +906,97 @@ discard block |
||
| 906 | 906 | |
| 907 | 907 | $free_trial = false; |
| 908 | 908 | |
| 909 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
| 909 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
| 910 | 910 | $free_trial = true; |
| 911 | 911 | } |
| 912 | 912 | |
| 913 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
| 913 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
| 914 | 914 | } |
| 915 | 915 | |
| 916 | 916 | function wpinv_get_cart_contents() { |
| 917 | 917 | $cart_details = wpinv_get_cart_details(); |
| 918 | 918 | |
| 919 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
| 919 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | function wpinv_get_cart_content_details() { |
| 923 | 923 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
| 924 | 924 | $cart_items = wpinv_get_cart_contents(); |
| 925 | 925 | |
| 926 | - if ( empty( $cart_items ) ) { |
|
| 926 | + if (empty($cart_items)) { |
|
| 927 | 927 | return false; |
| 928 | 928 | } |
| 929 | 929 | $invoice = wpinv_get_invoice_cart(); |
| 930 | - if ( empty( $invoice ) ) { |
|
| 930 | + if (empty($invoice)) { |
|
| 931 | 931 | return false; |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | $details = array(); |
| 935 | - $length = count( $cart_items ) - 1; |
|
| 935 | + $length = count($cart_items) - 1; |
|
| 936 | 936 | |
| 937 | - if ( empty( $_POST['country'] ) ) { |
|
| 937 | + if (empty($_POST['country'])) { |
|
| 938 | 938 | $_POST['country'] = $invoice->country; |
| 939 | 939 | } |
| 940 | - if ( !isset( $_POST['state'] ) ) { |
|
| 940 | + if (!isset($_POST['state'])) { |
|
| 941 | 941 | $_POST['state'] = $invoice->state; |
| 942 | 942 | } |
| 943 | 943 | |
| 944 | - foreach( $cart_items as $key => $item ) { |
|
| 945 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
| 946 | - if ( empty( $item_id ) ) { |
|
| 944 | + foreach ($cart_items as $key => $item) { |
|
| 945 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
| 946 | + if (empty($item_id)) { |
|
| 947 | 947 | continue; |
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | $wpi_current_id = $invoice->ID; |
| 951 | 951 | $wpi_item_id = $item_id; |
| 952 | 952 | |
| 953 | - if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) { |
|
| 953 | + if (isset($item['custom_price']) && $item['custom_price'] !== '') { |
|
| 954 | 954 | $item_price = $item['custom_price']; |
| 955 | 955 | } else { |
| 956 | - if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) { |
|
| 956 | + if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) { |
|
| 957 | 957 | $item_price = $item['item_price']; |
| 958 | 958 | } else { |
| 959 | - $item_price = wpinv_get_item_price( $item_id ); |
|
| 959 | + $item_price = wpinv_get_item_price($item_id); |
|
| 960 | 960 | } |
| 961 | 961 | } |
| 962 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
| 963 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
| 964 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
| 965 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
| 962 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
| 963 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
| 964 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
| 965 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
| 966 | 966 | |
| 967 | 967 | $subtotal = $item_price * $quantity; |
| 968 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
| 969 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
| 970 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
| 968 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
| 969 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
| 970 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
| 971 | 971 | |
| 972 | - if ( wpinv_prices_include_tax() ) { |
|
| 973 | - $subtotal -= wpinv_round_amount( $tax ); |
|
| 972 | + if (wpinv_prices_include_tax()) { |
|
| 973 | + $subtotal -= wpinv_round_amount($tax); |
|
| 974 | 974 | } |
| 975 | 975 | |
| 976 | - $total = $subtotal - $discount + $tax; |
|
| 976 | + $total = $subtotal - $discount + $tax; |
|
| 977 | 977 | |
| 978 | 978 | // Do not allow totals to go negatve |
| 979 | - if( $total < 0 ) { |
|
| 979 | + if ($total < 0) { |
|
| 980 | 980 | $total = 0; |
| 981 | 981 | } |
| 982 | 982 | |
| 983 | - $details[ $key ] = array( |
|
| 983 | + $details[$key] = array( |
|
| 984 | 984 | 'id' => $item_id, |
| 985 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
| 986 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
| 987 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
| 985 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
| 986 | + 'item_price' => wpinv_round_amount($item_price), |
|
| 987 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
| 988 | 988 | 'quantity' => $quantity, |
| 989 | - 'discount' => wpinv_round_amount( $discount ), |
|
| 990 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
| 991 | - 'tax' => wpinv_round_amount( $tax ), |
|
| 992 | - 'price' => wpinv_round_amount( $total ), |
|
| 989 | + 'discount' => wpinv_round_amount($discount), |
|
| 990 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
| 991 | + 'tax' => wpinv_round_amount($tax), |
|
| 992 | + 'price' => wpinv_round_amount($total), |
|
| 993 | 993 | 'vat_rates_class' => $tax_class, |
| 994 | 994 | 'vat_rate' => $tax_rate, |
| 995 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
| 995 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
| 996 | 996 | 'fees' => $fees, |
| 997 | 997 | ); |
| 998 | 998 | |
| 999 | - if ( $wpinv_is_last_cart_item ) { |
|
| 999 | + if ($wpinv_is_last_cart_item) { |
|
| 1000 | 1000 | $wpinv_is_last_cart_item = false; |
| 1001 | 1001 | $wpinv_flat_discount_total = 0.00; |
| 1002 | 1002 | } |
@@ -1005,67 +1005,67 @@ discard block |
||
| 1005 | 1005 | return $details; |
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
| 1008 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
| 1009 | 1009 | global $ajax_cart_details; |
| 1010 | 1010 | |
| 1011 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
| 1011 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
| 1012 | 1012 | $cart_details = $ajax_cart_details; |
| 1013 | - if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) { |
|
| 1013 | + if (empty($cart_details) && !empty($invoice->cart_details)) { |
|
| 1014 | 1014 | $cart_details = $invoice->cart_details; |
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
| 1018 | - $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country(); |
|
| 1017 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
| 1018 | + $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country(); |
|
| 1019 | 1019 | |
| 1020 | - foreach ( $cart_details as $key => $cart_item ) { |
|
| 1021 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
| 1020 | + foreach ($cart_details as $key => $cart_item) { |
|
| 1021 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
| 1022 | 1022 | |
| 1023 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
| 1024 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
| 1023 | + if (!isset($cart_item['subtotal'])) { |
|
| 1024 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
| 1025 | 1025 | } |
| 1026 | 1026 | } |
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
| 1029 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
| 1033 | - if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) { |
|
| 1032 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
| 1033 | + if ('wpi_invoice' != get_post_type($invoice_id)) { |
|
| 1034 | 1034 | return; |
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | - if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) { |
|
| 1037 | + if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) { |
|
| 1038 | 1038 | return; |
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 1041 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 1042 | 1042 | |
| 1043 | - $old_status = wpinv_status_nicename( $old_status ); |
|
| 1044 | - $new_status = wpinv_status_nicename( $new_status ); |
|
| 1043 | + $old_status = wpinv_status_nicename($old_status); |
|
| 1044 | + $new_status = wpinv_status_nicename($new_status); |
|
| 1045 | 1045 | |
| 1046 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
| 1046 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
| 1047 | 1047 | |
| 1048 | 1048 | // Add note |
| 1049 | - return $invoice->add_note( $status_change, false, false, true ); |
|
| 1049 | + return $invoice->add_note($status_change, false, false, true); |
|
| 1050 | 1050 | } |
| 1051 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
| 1051 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
| 1052 | 1052 | |
| 1053 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
| 1053 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
| 1054 | 1054 | global $wpi_has_free_trial; |
| 1055 | 1055 | |
| 1056 | 1056 | $wpi_has_free_trial = false; |
| 1057 | 1057 | |
| 1058 | - if ( $old_status == 'publish' ) { |
|
| 1058 | + if ($old_status == 'publish') { |
|
| 1059 | 1059 | return; // Make sure that payments are only paid once |
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | 1062 | // Make sure the payment completion is only processed when new status is paid |
| 1063 | - if ( $new_status != 'publish' ) { |
|
| 1063 | + if ($new_status != 'publish') { |
|
| 1064 | 1064 | return; |
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
| 1068 | - if ( empty( $invoice ) ) { |
|
| 1067 | + $invoice = new WPInv_Invoice($invoice_id); |
|
| 1068 | + if (empty($invoice)) { |
|
| 1069 | 1069 | return; |
| 1070 | 1070 | } |
| 1071 | 1071 | |
@@ -1073,58 +1073,58 @@ discard block |
||
| 1073 | 1073 | $completed_date = $invoice->completed_date; |
| 1074 | 1074 | $cart_details = $invoice->cart_details; |
| 1075 | 1075 | |
| 1076 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
| 1076 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
| 1077 | 1077 | |
| 1078 | - if ( is_array( $cart_details ) ) { |
|
| 1078 | + if (is_array($cart_details)) { |
|
| 1079 | 1079 | // Increase purchase count and earnings |
| 1080 | - foreach ( $cart_details as $cart_index => $item ) { |
|
| 1080 | + foreach ($cart_details as $cart_index => $item) { |
|
| 1081 | 1081 | // Ensure these actions only run once, ever |
| 1082 | - if ( empty( $completed_date ) ) { |
|
| 1083 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
| 1082 | + if (empty($completed_date)) { |
|
| 1083 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
| 1084 | 1084 | } |
| 1085 | 1085 | } |
| 1086 | 1086 | } |
| 1087 | 1087 | |
| 1088 | 1088 | // Check for discount codes and increment their use counts |
| 1089 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
| 1090 | - if( ! empty( $discounts ) ) { |
|
| 1091 | - foreach( $discounts as $code ) { |
|
| 1092 | - wpinv_increase_discount_usage( $code ); |
|
| 1089 | + if ($discounts = $invoice->get_discounts(true)) { |
|
| 1090 | + if (!empty($discounts)) { |
|
| 1091 | + foreach ($discounts as $code) { |
|
| 1092 | + wpinv_increase_discount_usage($code); |
|
| 1093 | 1093 | } |
| 1094 | 1094 | } |
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | 1097 | // Ensure this action only runs once ever |
| 1098 | - if( empty( $completed_date ) ) { |
|
| 1098 | + if (empty($completed_date)) { |
|
| 1099 | 1099 | // Save the completed date |
| 1100 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
| 1100 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
| 1101 | 1101 | $invoice->save(); |
| 1102 | 1102 | |
| 1103 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
| 1103 | + do_action('wpinv_complete_payment', $invoice_id); |
|
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | 1106 | // Empty the shopping cart |
| 1107 | 1107 | wpinv_empty_cart(); |
| 1108 | 1108 | } |
| 1109 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
| 1109 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
| 1110 | 1110 | |
| 1111 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
| 1112 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
| 1111 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
| 1112 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id); |
|
| 1113 | 1113 | |
| 1114 | - if ( empty( $invoice ) ) { |
|
| 1114 | + if (empty($invoice)) { |
|
| 1115 | 1115 | return false; |
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | - return $invoice->update_status( $new_status ); |
|
| 1118 | + return $invoice->update_status($new_status); |
|
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
| 1121 | +function wpinv_cart_has_fees($type = 'all') { |
|
| 1122 | 1122 | return false; |
| 1123 | 1123 | } |
| 1124 | 1124 | |
| 1125 | 1125 | function wpinv_validate_checkout_fields() { |
| 1126 | 1126 | // Check if there is $_POST |
| 1127 | - if ( empty( $_POST ) ) { |
|
| 1127 | + if (empty($_POST)) { |
|
| 1128 | 1128 | return false; |
| 1129 | 1129 | } |
| 1130 | 1130 | |
@@ -1136,11 +1136,11 @@ discard block |
||
| 1136 | 1136 | ); |
| 1137 | 1137 | |
| 1138 | 1138 | // Validate agree to terms |
| 1139 | - $page = wpinv_get_option( 'tandc_page' ); |
|
| 1140 | - if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){ |
|
| 1139 | + $page = wpinv_get_option('tandc_page'); |
|
| 1140 | + if (isset($page) && (int)$page > 0 && apply_filters('wpinv_checkout_show_terms', true)) { |
|
| 1141 | 1141 | // Validate agree to terms |
| 1142 | - if ( ! isset( $_POST['wpi_terms'] ) || !$_POST['wpi_terms'] ) { |
|
| 1143 | - wpinv_set_error( 'accept_terms', apply_filters( 'wpinv_accept_terms_error_text', __( 'You must accept terms and conditions', 'invoicing' ) ) ); |
|
| 1142 | + if (!isset($_POST['wpi_terms']) || !$_POST['wpi_terms']) { |
|
| 1143 | + wpinv_set_error('accept_terms', apply_filters('wpinv_accept_terms_error_text', __('You must accept terms and conditions', 'invoicing'))); |
|
| 1144 | 1144 | } |
| 1145 | 1145 | } |
| 1146 | 1146 | |
@@ -1156,26 +1156,26 @@ discard block |
||
| 1156 | 1156 | |
| 1157 | 1157 | $invoice = wpinv_get_invoice_cart(); |
| 1158 | 1158 | $has_subscription = $invoice->is_recurring(); |
| 1159 | - if ( empty( $invoice ) ) { |
|
| 1160 | - wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) ); |
|
| 1159 | + if (empty($invoice)) { |
|
| 1160 | + wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing')); |
|
| 1161 | 1161 | return $gateway; |
| 1162 | 1162 | } |
| 1163 | 1163 | |
| 1164 | 1164 | // Check if a gateway value is present |
| 1165 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
| 1166 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
| 1165 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
| 1166 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
| 1167 | 1167 | |
| 1168 | - if ( $invoice->is_free() ) { |
|
| 1168 | + if ($invoice->is_free()) { |
|
| 1169 | 1169 | $gateway = 'manual'; |
| 1170 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
| 1171 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
| 1172 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
| 1173 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) ); |
|
| 1170 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
| 1171 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
| 1172 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
| 1173 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing')); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
| 1178 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
| 1177 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
| 1178 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | 1181 | return $gateway; |
@@ -1189,10 +1189,10 @@ discard block |
||
| 1189 | 1189 | |
| 1190 | 1190 | $error = false; |
| 1191 | 1191 | // If we have discounts, loop through them |
| 1192 | - if ( ! empty( $discounts ) ) { |
|
| 1193 | - foreach ( $discounts as $discount ) { |
|
| 1192 | + if (!empty($discounts)) { |
|
| 1193 | + foreach ($discounts as $discount) { |
|
| 1194 | 1194 | // Check if valid |
| 1195 | - if ( !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) { |
|
| 1195 | + if (!wpinv_is_discount_valid($discount, (int)$wpi_cart->get_user_id())) { |
|
| 1196 | 1196 | // Discount is not valid |
| 1197 | 1197 | $error = true; |
| 1198 | 1198 | } |
@@ -1202,20 +1202,20 @@ discard block |
||
| 1202 | 1202 | return NULL; |
| 1203 | 1203 | } |
| 1204 | 1204 | |
| 1205 | - if ( $error && !wpinv_get_errors() ) { |
|
| 1206 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
| 1205 | + if ($error && !wpinv_get_errors()) { |
|
| 1206 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | - return implode( ',', $discounts ); |
|
| 1209 | + return implode(',', $discounts); |
|
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | 1212 | function wpinv_checkout_validate_cc() { |
| 1213 | 1213 | $card_data = wpinv_checkout_get_cc_info(); |
| 1214 | 1214 | |
| 1215 | 1215 | // Validate the card zip |
| 1216 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
| 1217 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
| 1218 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
| 1216 | + if (!empty($card_data['wpinv_zip'])) { |
|
| 1217 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
| 1218 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
| 1219 | 1219 | } |
| 1220 | 1220 | } |
| 1221 | 1221 | |
@@ -1225,28 +1225,28 @@ discard block |
||
| 1225 | 1225 | |
| 1226 | 1226 | function wpinv_checkout_get_cc_info() { |
| 1227 | 1227 | $cc_info = array(); |
| 1228 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
| 1229 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
| 1230 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
| 1231 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
| 1232 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
| 1233 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
| 1234 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
| 1235 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
| 1236 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
| 1237 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
| 1228 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
| 1229 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
| 1230 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
| 1231 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
| 1232 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
| 1233 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
| 1234 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
| 1235 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
| 1236 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
| 1237 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
| 1238 | 1238 | |
| 1239 | 1239 | // Return cc info |
| 1240 | 1240 | return $cc_info; |
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
| 1243 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
| 1244 | 1244 | $ret = false; |
| 1245 | 1245 | |
| 1246 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
| 1246 | + if (empty($zip) || empty($country_code)) |
|
| 1247 | 1247 | return $ret; |
| 1248 | 1248 | |
| 1249 | - $country_code = strtoupper( $country_code ); |
|
| 1249 | + $country_code = strtoupper($country_code); |
|
| 1250 | 1250 | |
| 1251 | 1251 | $zip_regex = array( |
| 1252 | 1252 | "AD" => "AD\d{3}", |
@@ -1406,24 +1406,24 @@ discard block |
||
| 1406 | 1406 | "ZM" => "\d{5}" |
| 1407 | 1407 | ); |
| 1408 | 1408 | |
| 1409 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
| 1409 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
| 1410 | 1410 | $ret = true; |
| 1411 | 1411 | |
| 1412 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
| 1412 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
| 1413 | 1413 | } |
| 1414 | 1414 | |
| 1415 | 1415 | function wpinv_checkout_validate_agree_to_terms() { |
| 1416 | 1416 | // Validate agree to terms |
| 1417 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
| 1417 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
| 1418 | 1418 | // User did not agree |
| 1419 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
| 1419 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
| 1420 | 1420 | } |
| 1421 | 1421 | } |
| 1422 | 1422 | |
| 1423 | 1423 | function wpinv_checkout_validate_invoice_user() { |
| 1424 | 1424 | global $wpi_cart, $user_ID; |
| 1425 | 1425 | |
| 1426 | - if(empty($wpi_cart)){ |
|
| 1426 | + if (empty($wpi_cart)) { |
|
| 1427 | 1427 | $wpi_cart = wpinv_get_invoice_cart(); |
| 1428 | 1428 | } |
| 1429 | 1429 | |
@@ -1433,45 +1433,45 @@ discard block |
||
| 1433 | 1433 | ); |
| 1434 | 1434 | |
| 1435 | 1435 | // If guest checkout allowed |
| 1436 | - if ( !wpinv_require_login_to_checkout() ) { |
|
| 1436 | + if (!wpinv_require_login_to_checkout()) { |
|
| 1437 | 1437 | return $valid_user_data; |
| 1438 | 1438 | } |
| 1439 | 1439 | |
| 1440 | 1440 | // Verify there is a user_ID |
| 1441 | - if ( $user_ID == $invoice_user ) { |
|
| 1441 | + if ($user_ID == $invoice_user) { |
|
| 1442 | 1442 | // Get the logged in user data |
| 1443 | - $user_data = get_userdata( $user_ID ); |
|
| 1444 | - $required_fields = wpinv_checkout_required_fields(); |
|
| 1443 | + $user_data = get_userdata($user_ID); |
|
| 1444 | + $required_fields = wpinv_checkout_required_fields(); |
|
| 1445 | 1445 | |
| 1446 | 1446 | // Loop through required fields and show error messages |
| 1447 | - if ( !empty( $required_fields ) ) { |
|
| 1448 | - foreach ( $required_fields as $field_name => $value ) { |
|
| 1449 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
| 1450 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
| 1447 | + if (!empty($required_fields)) { |
|
| 1448 | + foreach ($required_fields as $field_name => $value) { |
|
| 1449 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
| 1450 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
| 1451 | 1451 | } |
| 1452 | 1452 | } |
| 1453 | 1453 | } |
| 1454 | 1454 | |
| 1455 | 1455 | // Verify data |
| 1456 | - if ( $user_data ) { |
|
| 1456 | + if ($user_data) { |
|
| 1457 | 1457 | // Collected logged in user data |
| 1458 | 1458 | $valid_user_data = array( |
| 1459 | 1459 | 'user_id' => $user_ID, |
| 1460 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
| 1461 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
| 1462 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
| 1460 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
| 1461 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
| 1462 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
| 1463 | 1463 | ); |
| 1464 | 1464 | |
| 1465 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
| 1466 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
| 1465 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
| 1466 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
| 1467 | 1467 | } |
| 1468 | 1468 | } else { |
| 1469 | 1469 | // Set invalid user error |
| 1470 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
| 1470 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
| 1471 | 1471 | } |
| 1472 | 1472 | } else { |
| 1473 | 1473 | // Set invalid user error |
| 1474 | - wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) ); |
|
| 1474 | + wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing')); |
|
| 1475 | 1475 | } |
| 1476 | 1476 | |
| 1477 | 1477 | // Return user data |
@@ -1483,27 +1483,27 @@ discard block |
||
| 1483 | 1483 | |
| 1484 | 1484 | $data = array(); |
| 1485 | 1485 | |
| 1486 | - if ( is_user_logged_in() ) { |
|
| 1487 | - if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) { |
|
| 1486 | + if (is_user_logged_in()) { |
|
| 1487 | + if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id())) { |
|
| 1488 | 1488 | $data['user_id'] = (int)get_current_user_id(); |
| 1489 | 1489 | } else { |
| 1490 | - wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) ); |
|
| 1490 | + wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing')); |
|
| 1491 | 1491 | } |
| 1492 | 1492 | } else { |
| 1493 | 1493 | // If guest checkout allowed |
| 1494 | - if ( !wpinv_require_login_to_checkout() ) { |
|
| 1494 | + if (!wpinv_require_login_to_checkout()) { |
|
| 1495 | 1495 | $data['user_id'] = 0; |
| 1496 | 1496 | } else { |
| 1497 | - wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) ); |
|
| 1497 | + wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing')); |
|
| 1498 | 1498 | } |
| 1499 | 1499 | } |
| 1500 | 1500 | |
| 1501 | 1501 | return $data; |
| 1502 | 1502 | } |
| 1503 | 1503 | |
| 1504 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
| 1504 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
| 1505 | 1505 | |
| 1506 | - if ( !empty( $valid_data['current_user']['user_id'] ) ) { |
|
| 1506 | + if (!empty($valid_data['current_user']['user_id'])) { |
|
| 1507 | 1507 | $user = $valid_data['current_user']; |
| 1508 | 1508 | } else { |
| 1509 | 1509 | // Set the valid invoice user |
@@ -1511,7 +1511,7 @@ discard block |
||
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | // Verify invoice have an user |
| 1514 | - if ( false === $user || empty( $user ) ) { |
|
| 1514 | + if (false === $user || empty($user)) { |
|
| 1515 | 1515 | return false; |
| 1516 | 1516 | } |
| 1517 | 1517 | |
@@ -1528,11 +1528,11 @@ discard block |
||
| 1528 | 1528 | 'zip', |
| 1529 | 1529 | ); |
| 1530 | 1530 | |
| 1531 | - foreach ( $address_fields as $field ) { |
|
| 1532 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
| 1531 | + foreach ($address_fields as $field) { |
|
| 1532 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
| 1533 | 1533 | |
| 1534 | - if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) { |
|
| 1535 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
| 1534 | + if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) { |
|
| 1535 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
| 1536 | 1536 | } |
| 1537 | 1537 | } |
| 1538 | 1538 | |
@@ -1540,28 +1540,28 @@ discard block |
||
| 1540 | 1540 | return $user; |
| 1541 | 1541 | } |
| 1542 | 1542 | |
| 1543 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
| 1543 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
| 1544 | 1544 | global $wpi_session; |
| 1545 | 1545 | |
| 1546 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
| 1546 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
| 1547 | 1547 | } |
| 1548 | 1548 | |
| 1549 | 1549 | function wpinv_get_checkout_session() { |
| 1550 | 1550 | global $wpi_session; |
| 1551 | 1551 | |
| 1552 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
| 1552 | + return $wpi_session->get('wpinv_checkout'); |
|
| 1553 | 1553 | } |
| 1554 | 1554 | |
| 1555 | 1555 | function wpinv_empty_cart() { |
| 1556 | 1556 | global $wpi_session; |
| 1557 | 1557 | |
| 1558 | 1558 | // Remove cart contents |
| 1559 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
| 1559 | + $wpi_session->set('wpinv_checkout', NULL); |
|
| 1560 | 1560 | |
| 1561 | 1561 | // Remove all cart fees |
| 1562 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
| 1562 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
| 1563 | 1563 | |
| 1564 | - do_action( 'wpinv_empty_cart' ); |
|
| 1564 | + do_action('wpinv_empty_cart'); |
|
| 1565 | 1565 | } |
| 1566 | 1566 | |
| 1567 | 1567 | function wpinv_process_checkout() { |
@@ -1570,7 +1570,7 @@ discard block |
||
| 1570 | 1570 | wpinv_clear_errors(); |
| 1571 | 1571 | |
| 1572 | 1572 | $invoice = wpinv_get_invoice_cart(); |
| 1573 | - if ( empty( $invoice ) ) { |
|
| 1573 | + if (empty($invoice)) { |
|
| 1574 | 1574 | return false; |
| 1575 | 1575 | } |
| 1576 | 1576 | |
@@ -1578,42 +1578,42 @@ discard block |
||
| 1578 | 1578 | |
| 1579 | 1579 | $wpi_checkout_id = $invoice->ID; |
| 1580 | 1580 | |
| 1581 | - do_action( 'wpinv_pre_process_checkout' ); |
|
| 1581 | + do_action('wpinv_pre_process_checkout'); |
|
| 1582 | 1582 | |
| 1583 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
| 1583 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
| 1584 | 1584 | $valid_data = false; |
| 1585 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
| 1585 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
| 1586 | 1586 | } else { |
| 1587 | 1587 | // Validate the form $_POST data |
| 1588 | 1588 | $valid_data = wpinv_validate_checkout_fields(); |
| 1589 | 1589 | |
| 1590 | 1590 | // Allow themes and plugins to hook to errors |
| 1591 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
| 1591 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
| 1592 | 1592 | } |
| 1593 | 1593 | |
| 1594 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
| 1594 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
| 1595 | 1595 | |
| 1596 | 1596 | // Validate the user |
| 1597 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
| 1597 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
| 1598 | 1598 | |
| 1599 | 1599 | // Let extensions validate fields after user is logged in if user has used login/registration form |
| 1600 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
| 1600 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
| 1601 | 1601 | |
| 1602 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
| 1603 | - if ( $is_ajax ) { |
|
| 1604 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
| 1602 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
| 1603 | + if ($is_ajax) { |
|
| 1604 | + do_action('wpinv_ajax_checkout_errors'); |
|
| 1605 | 1605 | die(); |
| 1606 | 1606 | } else { |
| 1607 | 1607 | return false; |
| 1608 | 1608 | } |
| 1609 | 1609 | } |
| 1610 | 1610 | |
| 1611 | - if ( $is_ajax ) { |
|
| 1611 | + if ($is_ajax) { |
|
| 1612 | 1612 | // Save address fields. |
| 1613 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
| 1614 | - foreach ( $address_fields as $field ) { |
|
| 1615 | - if ( isset( $user[$field] ) ) { |
|
| 1616 | - $invoice->set( $field, $user[$field] ); |
|
| 1613 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
| 1614 | + foreach ($address_fields as $field) { |
|
| 1615 | + if (isset($user[$field])) { |
|
| 1616 | + $invoice->set($field, $user[$field]); |
|
| 1617 | 1617 | } |
| 1618 | 1618 | |
| 1619 | 1619 | $invoice->save(); |
@@ -1621,16 +1621,16 @@ discard block |
||
| 1621 | 1621 | |
| 1622 | 1622 | $response['success'] = true; |
| 1623 | 1623 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
| 1624 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
| 1624 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
| 1625 | 1625 | $response['data']['discount'] = $invoice->get_discount(); |
| 1626 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
| 1626 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
| 1627 | 1627 | $response['data']['tax'] = $invoice->get_tax(); |
| 1628 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
| 1628 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
| 1629 | 1629 | $response['data']['total'] = $invoice->get_total(); |
| 1630 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
| 1631 | - $response['data']['free'] = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false; |
|
| 1630 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
| 1631 | + $response['data']['free'] = $invoice->is_free() && (!((float)$response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false; |
|
| 1632 | 1632 | |
| 1633 | - wp_send_json( $response ); |
|
| 1633 | + wp_send_json($response); |
|
| 1634 | 1634 | } |
| 1635 | 1635 | |
| 1636 | 1636 | $user_info = array( |
@@ -1652,42 +1652,42 @@ discard block |
||
| 1652 | 1652 | |
| 1653 | 1653 | // Setup invoice information |
| 1654 | 1654 | $invoice_data = array( |
| 1655 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
| 1655 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
| 1656 | 1656 | 'items' => $cart_items, |
| 1657 | 1657 | 'cart_discounts' => $discounts, |
| 1658 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
| 1659 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
| 1660 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
| 1661 | - 'tax' => wpinv_get_cart_tax( $cart_items ), // Taxed amount |
|
| 1662 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
| 1658 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
| 1659 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
| 1660 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
| 1661 | + 'tax' => wpinv_get_cart_tax($cart_items), // Taxed amount |
|
| 1662 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
| 1663 | 1663 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
| 1664 | 1664 | 'user_email' => $invoice->get_email(), |
| 1665 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
| 1666 | - 'user_info' => stripslashes_deep( $user_info ), |
|
| 1665 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
| 1666 | + 'user_info' => stripslashes_deep($user_info), |
|
| 1667 | 1667 | 'post_data' => $_POST, |
| 1668 | 1668 | 'cart_details' => $cart_items, |
| 1669 | 1669 | 'gateway' => $valid_data['gateway'], |
| 1670 | 1670 | 'card_info' => $valid_data['cc_info'] |
| 1671 | 1671 | ); |
| 1672 | 1672 | |
| 1673 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
| 1674 | - if ( is_array( $vat_info ) ) { |
|
| 1673 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
| 1674 | + if (is_array($vat_info)) { |
|
| 1675 | 1675 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
| 1676 | 1676 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
| 1677 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 1677 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
| 1678 | 1678 | |
| 1679 | 1679 | // Add the VAT rate to each item in the cart |
| 1680 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
| 1680 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
| 1681 | 1681 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
| 1682 | - $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 ); |
|
| 1682 | + $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4); |
|
| 1683 | 1683 | } |
| 1684 | 1684 | } |
| 1685 | 1685 | |
| 1686 | 1686 | // Save vat fields. |
| 1687 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
| 1688 | - foreach ( $address_fields as $field ) { |
|
| 1689 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
| 1690 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
| 1687 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
| 1688 | + foreach ($address_fields as $field) { |
|
| 1689 | + if (isset($invoice_data['user_info'][$field])) { |
|
| 1690 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
| 1691 | 1691 | } |
| 1692 | 1692 | |
| 1693 | 1693 | $invoice->save(); |
@@ -1697,55 +1697,55 @@ discard block |
||
| 1697 | 1697 | $valid_data['user'] = $user; |
| 1698 | 1698 | |
| 1699 | 1699 | // Allow themes and plugins to hook before the gateway |
| 1700 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
| 1700 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
| 1701 | 1701 | |
| 1702 | 1702 | // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice |
| 1703 | - if ( !$invoice_data['price'] ) { |
|
| 1703 | + if (!$invoice_data['price']) { |
|
| 1704 | 1704 | // Revert to manual |
| 1705 | 1705 | $invoice_data['gateway'] = 'manual'; |
| 1706 | 1706 | $_POST['wpi-gateway'] = 'manual'; |
| 1707 | 1707 | } |
| 1708 | 1708 | |
| 1709 | 1709 | // Allow the invoice data to be modified before it is sent to the gateway |
| 1710 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
| 1710 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
| 1711 | 1711 | |
| 1712 | - if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) { |
|
| 1712 | + if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') { |
|
| 1713 | 1713 | $mode = 'test'; |
| 1714 | 1714 | } else { |
| 1715 | - $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live'; |
|
| 1715 | + $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'; |
|
| 1716 | 1716 | } |
| 1717 | 1717 | |
| 1718 | 1718 | // Setup the data we're storing in the purchase session |
| 1719 | 1719 | $session_data = $invoice_data; |
| 1720 | 1720 | // Make sure credit card numbers are never stored in sessions |
| 1721 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
| 1722 | - unset( $session_data['card_info']['card_number'] ); |
|
| 1721 | + if (!empty($session_data['card_info']['card_number'])) { |
|
| 1722 | + unset($session_data['card_info']['card_number']); |
|
| 1723 | 1723 | } |
| 1724 | 1724 | |
| 1725 | 1725 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
| 1726 | - wpinv_set_checkout_session( $invoice_data ); |
|
| 1726 | + wpinv_set_checkout_session($invoice_data); |
|
| 1727 | 1727 | |
| 1728 | 1728 | // Set gateway |
| 1729 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
| 1730 | - $invoice->update_meta( '_wpinv_mode', $mode ); |
|
| 1731 | - $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) ); |
|
| 1729 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
| 1730 | + $invoice->update_meta('_wpinv_mode', $mode); |
|
| 1731 | + $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp'))); |
|
| 1732 | 1732 | |
| 1733 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
| 1733 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
| 1734 | 1734 | |
| 1735 | 1735 | // Send info to the gateway for payment processing |
| 1736 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
| 1736 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
| 1737 | 1737 | die(); |
| 1738 | 1738 | } |
| 1739 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
| 1739 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
| 1740 | 1740 | |
| 1741 | -function wpinv_get_invoices( $args ) { |
|
| 1742 | - $args = wp_parse_args( $args, array( |
|
| 1743 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
| 1741 | +function wpinv_get_invoices($args) { |
|
| 1742 | + $args = wp_parse_args($args, array( |
|
| 1743 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
| 1744 | 1744 | 'type' => 'wpi_invoice', |
| 1745 | 1745 | 'parent' => null, |
| 1746 | 1746 | 'user' => null, |
| 1747 | 1747 | 'email' => '', |
| 1748 | - 'limit' => get_option( 'posts_per_page' ), |
|
| 1748 | + 'limit' => get_option('posts_per_page'), |
|
| 1749 | 1749 | 'offset' => null, |
| 1750 | 1750 | 'page' => 1, |
| 1751 | 1751 | 'exclude' => array(), |
@@ -1753,7 +1753,7 @@ discard block |
||
| 1753 | 1753 | 'order' => 'DESC', |
| 1754 | 1754 | 'return' => 'objects', |
| 1755 | 1755 | 'paginate' => false, |
| 1756 | - ) ); |
|
| 1756 | + )); |
|
| 1757 | 1757 | |
| 1758 | 1758 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
| 1759 | 1759 | $map_legacy = array( |
@@ -1766,18 +1766,18 @@ discard block |
||
| 1766 | 1766 | 'paged' => 'page', |
| 1767 | 1767 | ); |
| 1768 | 1768 | |
| 1769 | - foreach ( $map_legacy as $from => $to ) { |
|
| 1770 | - if ( isset( $args[ $from ] ) ) { |
|
| 1771 | - $args[ $to ] = $args[ $from ]; |
|
| 1769 | + foreach ($map_legacy as $from => $to) { |
|
| 1770 | + if (isset($args[$from])) { |
|
| 1771 | + $args[$to] = $args[$from]; |
|
| 1772 | 1772 | } |
| 1773 | 1773 | } |
| 1774 | 1774 | |
| 1775 | - if ( get_query_var( 'paged' ) ) |
|
| 1775 | + if (get_query_var('paged')) |
|
| 1776 | 1776 | $args['page'] = get_query_var('paged'); |
| 1777 | - else if ( get_query_var( 'page' ) ) |
|
| 1778 | - $args['page'] = get_query_var( 'page' ); |
|
| 1779 | - else if ( !empty( $args[ 'page' ] ) ) |
|
| 1780 | - $args['page'] = $args[ 'page' ]; |
|
| 1777 | + else if (get_query_var('page')) |
|
| 1778 | + $args['page'] = get_query_var('page'); |
|
| 1779 | + else if (!empty($args['page'])) |
|
| 1780 | + $args['page'] = $args['page']; |
|
| 1781 | 1781 | else |
| 1782 | 1782 | $args['page'] = 1; |
| 1783 | 1783 | |
@@ -1790,49 +1790,49 @@ discard block |
||
| 1790 | 1790 | 'post_status' => $args['status'], |
| 1791 | 1791 | 'posts_per_page' => $args['limit'], |
| 1792 | 1792 | 'meta_query' => array(), |
| 1793 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
| 1793 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
| 1794 | 1794 | 'fields' => 'ids', |
| 1795 | 1795 | 'orderby' => $args['orderby'], |
| 1796 | 1796 | 'order' => $args['order'], |
| 1797 | 1797 | ); |
| 1798 | 1798 | |
| 1799 | - if ( !empty( $args['user'] ) ) { |
|
| 1800 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
| 1799 | + if (!empty($args['user'])) { |
|
| 1800 | + $wp_query_args['author'] = absint($args['user']); |
|
| 1801 | 1801 | } |
| 1802 | 1802 | |
| 1803 | - if ( ! is_null( $args['parent'] ) ) { |
|
| 1804 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
| 1803 | + if (!is_null($args['parent'])) { |
|
| 1804 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
| 1805 | 1805 | } |
| 1806 | 1806 | |
| 1807 | - if ( ! is_null( $args['offset'] ) ) { |
|
| 1808 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
| 1807 | + if (!is_null($args['offset'])) { |
|
| 1808 | + $wp_query_args['offset'] = absint($args['offset']); |
|
| 1809 | 1809 | } else { |
| 1810 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
| 1810 | + $wp_query_args['paged'] = absint($args['page']); |
|
| 1811 | 1811 | } |
| 1812 | 1812 | |
| 1813 | - if ( ! empty( $args['exclude'] ) ) { |
|
| 1814 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
| 1813 | + if (!empty($args['exclude'])) { |
|
| 1814 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
| 1815 | 1815 | } |
| 1816 | 1816 | |
| 1817 | - if ( ! $args['paginate' ] ) { |
|
| 1817 | + if (!$args['paginate']) { |
|
| 1818 | 1818 | $wp_query_args['no_found_rows'] = true; |
| 1819 | 1819 | } |
| 1820 | 1820 | |
| 1821 | 1821 | $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args); |
| 1822 | 1822 | |
| 1823 | 1823 | // Get results. |
| 1824 | - $invoices = new WP_Query( $wp_query_args ); |
|
| 1824 | + $invoices = new WP_Query($wp_query_args); |
|
| 1825 | 1825 | |
| 1826 | - if ( 'objects' === $args['return'] ) { |
|
| 1827 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
| 1828 | - } elseif ( 'self' === $args['return'] ) { |
|
| 1826 | + if ('objects' === $args['return']) { |
|
| 1827 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
| 1828 | + } elseif ('self' === $args['return']) { |
|
| 1829 | 1829 | return $invoices; |
| 1830 | 1830 | } else { |
| 1831 | 1831 | $return = $invoices->posts; |
| 1832 | 1832 | } |
| 1833 | 1833 | |
| 1834 | - if ( $args['paginate' ] ) { |
|
| 1835 | - return (object) array( |
|
| 1834 | + if ($args['paginate']) { |
|
| 1835 | + return (object)array( |
|
| 1836 | 1836 | 'invoices' => $return, |
| 1837 | 1837 | 'total' => $invoices->found_posts, |
| 1838 | 1838 | 'max_num_pages' => $invoices->max_num_pages, |
@@ -1844,22 +1844,22 @@ discard block |
||
| 1844 | 1844 | |
| 1845 | 1845 | function wpinv_get_user_invoices_columns() { |
| 1846 | 1846 | $columns = array( |
| 1847 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1848 | - 'created-date' => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1849 | - 'payment-date' => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ), |
|
| 1850 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
| 1851 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
| 1852 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
| 1847 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
| 1848 | + 'created-date' => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'), |
|
| 1849 | + 'payment-date' => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'), |
|
| 1850 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
| 1851 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
| 1852 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
| 1853 | 1853 | ); |
| 1854 | 1854 | |
| 1855 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
| 1855 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
| 1856 | 1856 | } |
| 1857 | 1857 | |
| 1858 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
| 1858 | +function wpinv_payment_receipt($atts, $content = null) { |
|
| 1859 | 1859 | global $wpinv_receipt_args; |
| 1860 | 1860 | |
| 1861 | - $wpinv_receipt_args = shortcode_atts( array( |
|
| 1862 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
| 1861 | + $wpinv_receipt_args = shortcode_atts(array( |
|
| 1862 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
| 1863 | 1863 | 'price' => true, |
| 1864 | 1864 | 'discount' => true, |
| 1865 | 1865 | 'items' => true, |
@@ -1868,197 +1868,197 @@ discard block |
||
| 1868 | 1868 | 'invoice_key' => false, |
| 1869 | 1869 | 'payment_method' => true, |
| 1870 | 1870 | 'invoice_id' => true |
| 1871 | - ), $atts, 'wpinv_receipt' ); |
|
| 1871 | + ), $atts, 'wpinv_receipt'); |
|
| 1872 | 1872 | |
| 1873 | 1873 | $session = wpinv_get_checkout_session(); |
| 1874 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
| 1875 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
| 1876 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
| 1874 | + if (isset($_GET['invoice_key'])) { |
|
| 1875 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
| 1876 | + } else if ($session && isset($session['invoice_key'])) { |
|
| 1877 | 1877 | $invoice_key = $session['invoice_key']; |
| 1878 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
| 1878 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
| 1879 | 1879 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
| 1880 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1881 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
| 1880 | + } else if (isset($_GET['invoice-id'])) { |
|
| 1881 | + $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']); |
|
| 1882 | 1882 | } |
| 1883 | 1883 | |
| 1884 | 1884 | // No key found |
| 1885 | - if ( ! isset( $invoice_key ) ) { |
|
| 1885 | + if (!isset($invoice_key)) { |
|
| 1886 | 1886 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
| 1887 | 1887 | } |
| 1888 | 1888 | |
| 1889 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1890 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
| 1891 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
| 1889 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1890 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
| 1891 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
| 1892 | 1892 | $invoice_id = (int)$_GET['invoice-id']; |
| 1893 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
| 1893 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
| 1894 | 1894 | } |
| 1895 | 1895 | |
| 1896 | 1896 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
| 1897 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
| 1897 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
| 1898 | 1898 | // login redirect |
| 1899 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
| 1899 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
| 1900 | 1900 | } |
| 1901 | 1901 | |
| 1902 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
| 1902 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
| 1903 | 1903 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
| 1904 | 1904 | } |
| 1905 | 1905 | |
| 1906 | 1906 | ob_start(); |
| 1907 | 1907 | |
| 1908 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
| 1908 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
| 1909 | 1909 | |
| 1910 | 1910 | $display = ob_get_clean(); |
| 1911 | 1911 | |
| 1912 | 1912 | return $display; |
| 1913 | 1913 | } |
| 1914 | 1914 | |
| 1915 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
| 1915 | +function wpinv_get_invoice_id_by_key($key) { |
|
| 1916 | 1916 | global $wpdb; |
| 1917 | 1917 | |
| 1918 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
| 1918 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key)); |
|
| 1919 | 1919 | |
| 1920 | - if ( $invoice_id != NULL ) |
|
| 1920 | + if ($invoice_id != NULL) |
|
| 1921 | 1921 | return $invoice_id; |
| 1922 | 1922 | |
| 1923 | 1923 | return 0; |
| 1924 | 1924 | } |
| 1925 | 1925 | |
| 1926 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
| 1926 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
| 1927 | 1927 | $return = false; |
| 1928 | 1928 | |
| 1929 | - if ( empty( $invoice_key ) ) { |
|
| 1929 | + if (empty($invoice_key)) { |
|
| 1930 | 1930 | return $return; |
| 1931 | 1931 | } |
| 1932 | 1932 | |
| 1933 | 1933 | global $wpinv_receipt_args; |
| 1934 | 1934 | |
| 1935 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1936 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
| 1937 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
| 1935 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1936 | + if (isset($_GET['invoice-id'])) { |
|
| 1937 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0; |
|
| 1938 | 1938 | } |
| 1939 | 1939 | |
| 1940 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
| 1940 | + if (empty($wpinv_receipt_args['id'])) { |
|
| 1941 | 1941 | return $return; |
| 1942 | 1942 | } |
| 1943 | 1943 | |
| 1944 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
| 1945 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
| 1944 | + $invoice = wpinv_get_invoice($wpinv_receipt_args['id']); |
|
| 1945 | + if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) { |
|
| 1946 | 1946 | return $return; |
| 1947 | 1947 | } |
| 1948 | 1948 | |
| 1949 | - if ( is_user_logged_in() ) { |
|
| 1950 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
| 1949 | + if (is_user_logged_in()) { |
|
| 1950 | + if ((int)$invoice->get_user_id() === (int)get_current_user_id()) { |
|
| 1951 | 1951 | $return = true; |
| 1952 | 1952 | } |
| 1953 | 1953 | } |
| 1954 | 1954 | |
| 1955 | 1955 | $session = wpinv_get_checkout_session(); |
| 1956 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
| 1957 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
| 1956 | + if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) { |
|
| 1957 | + $check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
| 1958 | 1958 | |
| 1959 | - if ( wpinv_require_login_to_checkout() ) { |
|
| 1959 | + if (wpinv_require_login_to_checkout()) { |
|
| 1960 | 1960 | $return = $return && $check_key === $invoice_key; |
| 1961 | 1961 | } else { |
| 1962 | 1962 | $return = $check_key === $invoice_key; |
| 1963 | 1963 | } |
| 1964 | 1964 | } |
| 1965 | 1965 | |
| 1966 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
| 1966 | + return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
| 1967 | 1967 | } |
| 1968 | 1968 | |
| 1969 | 1969 | function wpinv_pay_for_invoice() { |
| 1970 | 1970 | global $wpinv_euvat; |
| 1971 | 1971 | |
| 1972 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
| 1972 | + if (isset($_GET['invoice_key'])) { |
|
| 1973 | 1973 | $checkout_uri = wpinv_get_checkout_uri(); |
| 1974 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
| 1974 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
| 1975 | 1975 | |
| 1976 | - if ( empty( $invoice_key ) ) { |
|
| 1977 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
| 1978 | - wp_redirect( $checkout_uri ); |
|
| 1976 | + if (empty($invoice_key)) { |
|
| 1977 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
| 1978 | + wp_redirect($checkout_uri); |
|
| 1979 | 1979 | exit(); |
| 1980 | 1980 | } |
| 1981 | 1981 | |
| 1982 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
| 1982 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
| 1983 | 1983 | |
| 1984 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
| 1985 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
| 1986 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
| 1984 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
| 1985 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
| 1986 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
| 1987 | 1987 | $invoice_id = (int)$_GET['invoice-id']; |
| 1988 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
| 1988 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
| 1989 | 1989 | } |
| 1990 | 1990 | |
| 1991 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
| 1992 | - if ( $invoice->needs_payment() ) { |
|
| 1991 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
| 1992 | + if ($invoice->needs_payment()) { |
|
| 1993 | 1993 | $data = array(); |
| 1994 | 1994 | $data['invoice_id'] = $invoice_id; |
| 1995 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
| 1995 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
| 1996 | 1996 | |
| 1997 | - wpinv_set_checkout_session( $data ); |
|
| 1997 | + wpinv_set_checkout_session($data); |
|
| 1998 | 1998 | |
| 1999 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
| 1999 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
| 2000 | 2000 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
| 2001 | 2001 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
| 2002 | 2002 | |
| 2003 | - wpinv_recalculate_tax( true ); |
|
| 2003 | + wpinv_recalculate_tax(true); |
|
| 2004 | 2004 | } |
| 2005 | 2005 | |
| 2006 | 2006 | } else { |
| 2007 | 2007 | $checkout_uri = $invoice->get_view_url(); |
| 2008 | 2008 | } |
| 2009 | 2009 | } else { |
| 2010 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
| 2010 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
| 2011 | 2011 | |
| 2012 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
| 2012 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
| 2013 | 2013 | } |
| 2014 | 2014 | |
| 2015 | - if(wp_redirect( $checkout_uri )){ |
|
| 2015 | + if (wp_redirect($checkout_uri)) { |
|
| 2016 | 2016 | exit; |
| 2017 | 2017 | }; |
| 2018 | 2018 | wpinv_die(); |
| 2019 | 2019 | } |
| 2020 | 2020 | } |
| 2021 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
| 2021 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
| 2022 | 2022 | |
| 2023 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
| 2024 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
| 2025 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
| 2023 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
| 2024 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
| 2025 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
| 2026 | 2026 | $user_id = $invoice->get_user_id(); |
| 2027 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
| 2027 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
| 2028 | 2028 | |
| 2029 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
| 2030 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
| 2029 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
| 2030 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
| 2031 | 2031 | |
| 2032 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
| 2032 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
| 2033 | 2033 | exit(); |
| 2034 | 2034 | } |
| 2035 | 2035 | } |
| 2036 | 2036 | } |
| 2037 | 2037 | } |
| 2038 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
| 2038 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
| 2039 | 2039 | |
| 2040 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
| 2041 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
| 2040 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
| 2041 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
| 2042 | 2042 | |
| 2043 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
| 2043 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
| 2044 | 2044 | return false; |
| 2045 | 2045 | } |
| 2046 | 2046 | |
| 2047 | - if ( empty( $transaction_id ) ) { |
|
| 2047 | + if (empty($transaction_id)) { |
|
| 2048 | 2048 | $transaction_id = $invoice_id; |
| 2049 | 2049 | } |
| 2050 | 2050 | |
| 2051 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
| 2051 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
| 2052 | 2052 | |
| 2053 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
| 2053 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
| 2054 | 2054 | } |
| 2055 | 2055 | |
| 2056 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
| 2057 | - if ( empty( $status_display ) ) { |
|
| 2058 | - $status_display = wpinv_status_nicename( $status ); |
|
| 2056 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
| 2057 | + if (empty($status_display)) { |
|
| 2058 | + $status_display = wpinv_status_nicename($status); |
|
| 2059 | 2059 | } |
| 2060 | 2060 | |
| 2061 | - switch ( $status ) { |
|
| 2061 | + switch ($status) { |
|
| 2062 | 2062 | case 'publish' : |
| 2063 | 2063 | case 'wpi-renewal' : |
| 2064 | 2064 | $class = 'label-success'; |
@@ -2083,201 +2083,201 @@ discard block |
||
| 2083 | 2083 | |
| 2084 | 2084 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
| 2085 | 2085 | |
| 2086 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
| 2086 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
| 2087 | 2087 | } |
| 2088 | 2088 | |
| 2089 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
| 2090 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
| 2091 | - if ( null !== $check ) { |
|
| 2089 | +function wpinv_format_invoice_number($number, $type = '') { |
|
| 2090 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
| 2091 | + if (null !== $check) { |
|
| 2092 | 2092 | return $check; |
| 2093 | 2093 | } |
| 2094 | 2094 | |
| 2095 | - if ( !empty( $number ) && !is_numeric( $number ) ) { |
|
| 2095 | + if (!empty($number) && !is_numeric($number)) { |
|
| 2096 | 2096 | return $number; |
| 2097 | 2097 | } |
| 2098 | 2098 | |
| 2099 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
| 2100 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
| 2101 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
| 2099 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
| 2100 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
| 2101 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
| 2102 | 2102 | |
| 2103 | - $padd = absint( $padd ); |
|
| 2104 | - $formatted_number = absint( $number ); |
|
| 2103 | + $padd = absint($padd); |
|
| 2104 | + $formatted_number = absint($number); |
|
| 2105 | 2105 | |
| 2106 | - if ( $padd > 0 ) { |
|
| 2107 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
| 2106 | + if ($padd > 0) { |
|
| 2107 | + $formatted_number = zeroise($formatted_number, $padd); |
|
| 2108 | 2108 | } |
| 2109 | 2109 | |
| 2110 | 2110 | $formatted_number = $prefix . $formatted_number . $postfix; |
| 2111 | 2111 | |
| 2112 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
| 2112 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
| 2113 | 2113 | } |
| 2114 | 2114 | |
| 2115 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
| 2116 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
| 2117 | - if ( null !== $check ) { |
|
| 2115 | +function wpinv_get_next_invoice_number($type = '') { |
|
| 2116 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
| 2117 | + if (null !== $check) { |
|
| 2118 | 2118 | return $check; |
| 2119 | 2119 | } |
| 2120 | 2120 | |
| 2121 | - if ( !wpinv_sequential_number_active() ) { |
|
| 2121 | + if (!wpinv_sequential_number_active()) { |
|
| 2122 | 2122 | return false; |
| 2123 | 2123 | } |
| 2124 | 2124 | |
| 2125 | - $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 ); |
|
| 2126 | - $start = wpinv_get_option( 'invoice_sequence_start', 1 ); |
|
| 2127 | - if ( !absint( $start ) > 0 ) { |
|
| 2125 | + $number = $last_number = get_option('wpinv_last_invoice_number', 0); |
|
| 2126 | + $start = wpinv_get_option('invoice_sequence_start', 1); |
|
| 2127 | + if (!absint($start) > 0) { |
|
| 2128 | 2128 | $start = 1; |
| 2129 | 2129 | } |
| 2130 | 2130 | $increment_number = true; |
| 2131 | 2131 | $save_number = false; |
| 2132 | 2132 | |
| 2133 | - if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) { |
|
| 2134 | - $number = wpinv_clean_invoice_number( $number ); |
|
| 2133 | + if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) { |
|
| 2134 | + $number = wpinv_clean_invoice_number($number); |
|
| 2135 | 2135 | } |
| 2136 | 2136 | |
| 2137 | - if ( empty( $number ) ) { |
|
| 2138 | - if ( !( $last_number === 0 || $last_number === '0' ) ) { |
|
| 2139 | - $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) ); |
|
| 2137 | + if (empty($number)) { |
|
| 2138 | + if (!($last_number === 0 || $last_number === '0')) { |
|
| 2139 | + $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true)))); |
|
| 2140 | 2140 | |
| 2141 | - if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) { |
|
| 2142 | - if ( is_numeric( $invoice_number ) ) { |
|
| 2141 | + if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) { |
|
| 2142 | + if (is_numeric($invoice_number)) { |
|
| 2143 | 2143 | $number = $invoice_number; |
| 2144 | 2144 | } else { |
| 2145 | - $number = wpinv_clean_invoice_number( $invoice_number ); |
|
| 2145 | + $number = wpinv_clean_invoice_number($invoice_number); |
|
| 2146 | 2146 | } |
| 2147 | 2147 | } |
| 2148 | 2148 | |
| 2149 | - if ( empty( $number ) ) { |
|
| 2149 | + if (empty($number)) { |
|
| 2150 | 2150 | $increment_number = false; |
| 2151 | 2151 | $number = $start; |
| 2152 | - $save_number = ( $number - 1 ); |
|
| 2152 | + $save_number = ($number - 1); |
|
| 2153 | 2153 | } else { |
| 2154 | 2154 | $save_number = $number; |
| 2155 | 2155 | } |
| 2156 | 2156 | } |
| 2157 | 2157 | } |
| 2158 | 2158 | |
| 2159 | - if ( $start > $number ) { |
|
| 2159 | + if ($start > $number) { |
|
| 2160 | 2160 | $increment_number = false; |
| 2161 | 2161 | $number = $start; |
| 2162 | - $save_number = ( $number - 1 ); |
|
| 2162 | + $save_number = ($number - 1); |
|
| 2163 | 2163 | } |
| 2164 | 2164 | |
| 2165 | - if ( $save_number !== false ) { |
|
| 2166 | - update_option( 'wpinv_last_invoice_number', $save_number ); |
|
| 2165 | + if ($save_number !== false) { |
|
| 2166 | + update_option('wpinv_last_invoice_number', $save_number); |
|
| 2167 | 2167 | } |
| 2168 | 2168 | |
| 2169 | - $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number ); |
|
| 2169 | + $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number); |
|
| 2170 | 2170 | |
| 2171 | - if ( $increment_number ) { |
|
| 2171 | + if ($increment_number) { |
|
| 2172 | 2172 | $number++; |
| 2173 | 2173 | } |
| 2174 | 2174 | |
| 2175 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
| 2175 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
| 2176 | 2176 | } |
| 2177 | 2177 | |
| 2178 | -function wpinv_clean_invoice_number( $number, $type = '' ) { |
|
| 2179 | - $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type ); |
|
| 2180 | - if ( null !== $check ) { |
|
| 2178 | +function wpinv_clean_invoice_number($number, $type = '') { |
|
| 2179 | + $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type); |
|
| 2180 | + if (null !== $check) { |
|
| 2181 | 2181 | return $check; |
| 2182 | 2182 | } |
| 2183 | 2183 | |
| 2184 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
| 2185 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
| 2184 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
| 2185 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
| 2186 | 2186 | |
| 2187 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
| 2187 | + $number = preg_replace('/' . $prefix . '/', '', $number, 1); |
|
| 2188 | 2188 | |
| 2189 | - $length = strlen( $number ); |
|
| 2190 | - $postfix_pos = strrpos( $number, $postfix ); |
|
| 2189 | + $length = strlen($number); |
|
| 2190 | + $postfix_pos = strrpos($number, $postfix); |
|
| 2191 | 2191 | |
| 2192 | - if ( false !== $postfix_pos ) { |
|
| 2193 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
| 2192 | + if (false !== $postfix_pos) { |
|
| 2193 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
| 2194 | 2194 | } |
| 2195 | 2195 | |
| 2196 | - $number = intval( $number ); |
|
| 2196 | + $number = intval($number); |
|
| 2197 | 2197 | |
| 2198 | - return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix ); |
|
| 2198 | + return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix); |
|
| 2199 | 2199 | } |
| 2200 | 2200 | |
| 2201 | -function wpinv_save_number_post_saved( $post_ID, $post, $update ) { |
|
| 2201 | +function wpinv_save_number_post_saved($post_ID, $post, $update) { |
|
| 2202 | 2202 | global $wpdb; |
| 2203 | 2203 | |
| 2204 | - if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) { |
|
| 2205 | - wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type ); |
|
| 2204 | + if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) { |
|
| 2205 | + wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type); |
|
| 2206 | 2206 | } |
| 2207 | 2207 | |
| 2208 | - if ( !$update ) { |
|
| 2209 | - $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) ); |
|
| 2210 | - clean_post_cache( $post_ID ); |
|
| 2208 | + if (!$update) { |
|
| 2209 | + $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID)); |
|
| 2210 | + clean_post_cache($post_ID); |
|
| 2211 | 2211 | } |
| 2212 | 2212 | } |
| 2213 | -add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 ); |
|
| 2213 | +add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3); |
|
| 2214 | 2214 | |
| 2215 | -function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) { |
|
| 2216 | - if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) { |
|
| 2217 | - wpinv_update_invoice_number( $post_ID, true, $post_after->post_type ); |
|
| 2215 | +function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) { |
|
| 2216 | + if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) { |
|
| 2217 | + wpinv_update_invoice_number($post_ID, true, $post_after->post_type); |
|
| 2218 | 2218 | } |
| 2219 | 2219 | } |
| 2220 | -add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 ); |
|
| 2220 | +add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3); |
|
| 2221 | 2221 | |
| 2222 | -function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) { |
|
| 2222 | +function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') { |
|
| 2223 | 2223 | global $wpdb; |
| 2224 | 2224 | |
| 2225 | - $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type ); |
|
| 2226 | - if ( null !== $check ) { |
|
| 2225 | + $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type); |
|
| 2226 | + if (null !== $check) { |
|
| 2227 | 2227 | return $check; |
| 2228 | 2228 | } |
| 2229 | 2229 | |
| 2230 | - if ( wpinv_sequential_number_active() ) { |
|
| 2230 | + if (wpinv_sequential_number_active()) { |
|
| 2231 | 2231 | $number = wpinv_get_next_invoice_number(); |
| 2232 | 2232 | |
| 2233 | - if ( $save_sequential ) { |
|
| 2234 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
| 2233 | + if ($save_sequential) { |
|
| 2234 | + update_option('wpinv_last_invoice_number', $number); |
|
| 2235 | 2235 | } |
| 2236 | 2236 | } else { |
| 2237 | 2237 | $number = $post_ID; |
| 2238 | 2238 | } |
| 2239 | 2239 | |
| 2240 | - $number = wpinv_format_invoice_number( $number ); |
|
| 2240 | + $number = wpinv_format_invoice_number($number); |
|
| 2241 | 2241 | |
| 2242 | - update_post_meta( $post_ID, '_wpinv_number', $number ); |
|
| 2242 | + update_post_meta($post_ID, '_wpinv_number', $number); |
|
| 2243 | 2243 | |
| 2244 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) ); |
|
| 2244 | + $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID)); |
|
| 2245 | 2245 | |
| 2246 | - clean_post_cache( $post_ID ); |
|
| 2246 | + clean_post_cache($post_ID); |
|
| 2247 | 2247 | |
| 2248 | 2248 | return $number; |
| 2249 | 2249 | } |
| 2250 | 2250 | |
| 2251 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
| 2252 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
| 2251 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
| 2252 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
| 2253 | 2253 | } |
| 2254 | 2254 | |
| 2255 | -function wpinv_generate_post_name( $post_ID ) { |
|
| 2256 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
| 2257 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
| 2255 | +function wpinv_generate_post_name($post_ID) { |
|
| 2256 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
| 2257 | + $post_name = sanitize_title($prefix . $post_ID); |
|
| 2258 | 2258 | |
| 2259 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
| 2259 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
| 2260 | 2260 | } |
| 2261 | 2261 | |
| 2262 | -function wpinv_is_invoice_viewed( $invoice_id ) { |
|
| 2263 | - if ( empty( $invoice_id ) ) { |
|
| 2262 | +function wpinv_is_invoice_viewed($invoice_id) { |
|
| 2263 | + if (empty($invoice_id)) { |
|
| 2264 | 2264 | return false; |
| 2265 | 2265 | } |
| 2266 | 2266 | |
| 2267 | - $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true ); |
|
| 2267 | + $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true); |
|
| 2268 | 2268 | |
| 2269 | - return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id ); |
|
| 2269 | + return apply_filters('wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id); |
|
| 2270 | 2270 | } |
| 2271 | 2271 | |
| 2272 | 2272 | function wpinv_mark_invoice_viewed() { |
| 2273 | 2273 | |
| 2274 | - if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) { |
|
| 2275 | - $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : ''; |
|
| 2274 | + if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) { |
|
| 2275 | + $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : ''; |
|
| 2276 | 2276 | global $post; |
| 2277 | 2277 | |
| 2278 | - if(!empty($invoice_key)){ |
|
| 2278 | + if (!empty($invoice_key)) { |
|
| 2279 | 2279 | $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
| 2280 | - } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
|
| 2280 | + } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
|
| 2281 | 2281 | $invoice_id = $post->ID; |
| 2282 | 2282 | } else { |
| 2283 | 2283 | return; |
@@ -2285,60 +2285,60 @@ discard block |
||
| 2285 | 2285 | |
| 2286 | 2286 | $invoice = new WPInv_Invoice($invoice_id); |
| 2287 | 2287 | |
| 2288 | - if(!$invoice_id){ |
|
| 2288 | + if (!$invoice_id) { |
|
| 2289 | 2289 | return; |
| 2290 | 2290 | } |
| 2291 | 2291 | |
| 2292 | - if ( is_user_logged_in() ) { |
|
| 2293 | - if ( (int)$invoice->get_user_id() === get_current_user_id() ) { |
|
| 2294 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2295 | - } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
| 2296 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2292 | + if (is_user_logged_in()) { |
|
| 2293 | + if ((int)$invoice->get_user_id() === get_current_user_id()) { |
|
| 2294 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
| 2295 | + } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
| 2296 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
| 2297 | 2297 | } |
| 2298 | 2298 | } else { |
| 2299 | - if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
| 2300 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
| 2299 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
| 2300 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
| 2301 | 2301 | } |
| 2302 | 2302 | } |
| 2303 | 2303 | } |
| 2304 | 2304 | |
| 2305 | 2305 | } |
| 2306 | -add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' ); |
|
| 2306 | +add_action('template_redirect', 'wpinv_mark_invoice_viewed'); |
|
| 2307 | 2307 | |
| 2308 | -function wpinv_get_subscription( $invoice, $by_parent = false ) { |
|
| 2309 | - if ( empty( $invoice ) ) { |
|
| 2308 | +function wpinv_get_subscription($invoice, $by_parent = false) { |
|
| 2309 | + if (empty($invoice)) { |
|
| 2310 | 2310 | return false; |
| 2311 | 2311 | } |
| 2312 | 2312 | |
| 2313 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
| 2314 | - $invoice = wpinv_get_invoice( $invoice ); |
|
| 2313 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
| 2314 | + $invoice = wpinv_get_invoice($invoice); |
|
| 2315 | 2315 | } |
| 2316 | 2316 | |
| 2317 | - if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) { |
|
| 2317 | + if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) { |
|
| 2318 | 2318 | return false; |
| 2319 | 2319 | } |
| 2320 | 2320 | |
| 2321 | - $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID; |
|
| 2321 | + $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID; |
|
| 2322 | 2322 | |
| 2323 | 2323 | $subs_db = new WPInv_Subscriptions_DB; |
| 2324 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) ); |
|
| 2324 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1)); |
|
| 2325 | 2325 | |
| 2326 | - if ( ! empty( $subs ) ) { |
|
| 2327 | - return reset( $subs ); |
|
| 2326 | + if (!empty($subs)) { |
|
| 2327 | + return reset($subs); |
|
| 2328 | 2328 | } |
| 2329 | 2329 | |
| 2330 | 2330 | return false; |
| 2331 | 2331 | } |
| 2332 | 2332 | |
| 2333 | -function wpinv_filter_posts_clauses( $clauses, $wp_query ) { |
|
| 2333 | +function wpinv_filter_posts_clauses($clauses, $wp_query) { |
|
| 2334 | 2334 | global $wpdb; |
| 2335 | 2335 | |
| 2336 | - if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) { |
|
| 2337 | - if ( !empty( $clauses['join'] ) ) { |
|
| 2336 | + if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') { |
|
| 2337 | + if (!empty($clauses['join'])) { |
|
| 2338 | 2338 | $clauses['join'] .= " "; |
| 2339 | 2339 | } |
| 2340 | 2340 | |
| 2341 | - if ( !empty( $clauses['fields'] ) ) { |
|
| 2341 | + if (!empty($clauses['fields'])) { |
|
| 2342 | 2342 | $clauses['fields'] .= ", "; |
| 2343 | 2343 | } |
| 2344 | 2344 | |
@@ -2349,4 +2349,4 @@ discard block |
||
| 2349 | 2349 | |
| 2350 | 2350 | return $clauses; |
| 2351 | 2351 | } |
| 2352 | -add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 ); |
|
| 2353 | 2352 | \ No newline at end of file |
| 2353 | +add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2); |
|
| 2354 | 2354 | \ No newline at end of file |
@@ -7,15 +7,15 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | class WPInv_Plugin { |
| 15 | 15 | private static $instance; |
| 16 | 16 | |
| 17 | 17 | public static function run() { |
| 18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
| 18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
| 19 | 19 | self::$instance = new WPInv_Plugin; |
| 20 | 20 | self::$instance->includes(); |
| 21 | 21 | self::$instance->actions(); |
@@ -32,31 +32,31 @@ discard block |
||
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public function define_constants() { |
| 35 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 36 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 35 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 36 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | private function actions() { |
| 40 | 40 | /* Internationalize the text strings used. */ |
| 41 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 41 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 42 | 42 | |
| 43 | 43 | /* Perform actions on admin initialization. */ |
| 44 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
| 45 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
| 46 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
| 47 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 44 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
| 45 | + add_action('init', array(&$this, 'init'), 3); |
|
| 46 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
| 47 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
| 48 | 48 | |
| 49 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 50 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 49 | + if (class_exists('BuddyPress')) { |
|
| 50 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 53 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
| 54 | 54 | |
| 55 | - if ( is_admin() ) { |
|
| 56 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
| 57 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
| 55 | + if (is_admin()) { |
|
| 56 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
| 57 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
| 58 | 58 | } else { |
| 59 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 59 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,16 +66,16 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
| 68 | 68 | */ |
| 69 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
| 69 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
| 70 | 70 | |
| 71 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
| 71 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | public function plugins_loaded() { |
| 75 | 75 | /* Internationalize the text strings used. */ |
| 76 | 76 | $this->load_textdomain(); |
| 77 | 77 | |
| 78 | - do_action( 'wpinv_loaded' ); |
|
| 78 | + do_action('wpinv_loaded'); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -83,223 +83,223 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @since 1.0 |
| 85 | 85 | */ |
| 86 | - public function load_textdomain( $locale = NULL ) { |
|
| 87 | - if ( empty( $locale ) ) { |
|
| 88 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
| 86 | + public function load_textdomain($locale = NULL) { |
|
| 87 | + if (empty($locale)) { |
|
| 88 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
| 91 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
| 92 | 92 | |
| 93 | - unload_textdomain( 'invoicing' ); |
|
| 94 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 95 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 93 | + unload_textdomain('invoicing'); |
|
| 94 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
| 95 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
| 96 | 96 | |
| 97 | 97 | /** |
| 98 | 98 | * Define language constants. |
| 99 | 99 | */ |
| 100 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 100 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | public function includes() { |
| 104 | 104 | global $wpinv_options; |
| 105 | 105 | |
| 106 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 106 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
| 107 | 107 | $wpinv_options = wpinv_get_settings(); |
| 108 | 108 | |
| 109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
| 110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
| 117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 118 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 119 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 120 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 121 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 122 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
| 123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
| 124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
| 125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
| 126 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
| 127 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
| 128 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 129 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 130 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 131 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
| 132 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
| 133 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
| 134 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
| 135 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
| 136 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
| 137 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
| 138 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
| 139 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
| 140 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
| 141 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
| 142 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
| 143 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
| 109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
| 110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
| 111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
| 112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
| 113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
| 114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
| 115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
| 116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
| 117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
| 118 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
| 119 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
| 120 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
| 121 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
| 122 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
| 123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
| 124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
| 125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
| 126 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
| 127 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
| 128 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
| 129 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
| 130 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
| 131 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
| 132 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
| 133 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
| 134 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
| 135 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
| 136 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
| 137 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
| 138 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
| 139 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
| 140 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
| 141 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
| 142 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
| 143 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
| 144 | 144 | |
| 145 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
| 146 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 145 | + if (!class_exists('WPInv_EUVat')) { |
|
| 146 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 150 | - if ( !empty( $gateways ) ) { |
|
| 151 | - foreach ( $gateways as $gateway ) { |
|
| 152 | - if ( $gateway == 'manual' ) { |
|
| 149 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 150 | + if (!empty($gateways)) { |
|
| 151 | + foreach ($gateways as $gateway) { |
|
| 152 | + if ($gateway == 'manual') { |
|
| 153 | 153 | continue; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
| 157 | 157 | |
| 158 | - if ( file_exists( $gateway_file ) ) { |
|
| 159 | - require_once( $gateway_file ); |
|
| 158 | + if (file_exists($gateway_file)) { |
|
| 159 | + require_once($gateway_file); |
|
| 160 | 160 | } |
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
| 163 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
| 164 | 164 | |
| 165 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 166 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 167 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 168 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
| 165 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 166 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
| 167 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
| 168 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
| 169 | 169 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
| 170 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
| 171 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
| 172 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 173 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
| 174 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 175 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
| 176 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
| 170 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
| 171 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
| 172 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
| 173 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
| 174 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
| 175 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
| 176 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
| 177 | 177 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
| 178 | 178 | // load the user class only on the users.php page |
| 179 | 179 | global $pagenow; |
| 180 | - if($pagenow=='users.php'){ |
|
| 180 | + if ($pagenow == 'users.php') { |
|
| 181 | 181 | new WPInv_Admin_Users(); |
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // Register cli commands |
| 186 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 187 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
| 188 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
| 186 | + if (defined('WP_CLI') && WP_CLI) { |
|
| 187 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
| 188 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | // include css inliner |
| 192 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 193 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 192 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
| 193 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 196 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | public function init() { |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | public function admin_init() { |
| 203 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
| 203 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | public function activation_redirect() { |
| 207 | 207 | // Bail if no activation redirect |
| 208 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
| 208 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
| 209 | 209 | return; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | // Delete the redirect transient |
| 213 | - delete_transient( '_wpinv_activation_redirect' ); |
|
| 213 | + delete_transient('_wpinv_activation_redirect'); |
|
| 214 | 214 | |
| 215 | 215 | // Bail if activating from network, or bulk |
| 216 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 216 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
| 217 | 217 | return; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 220 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
| 221 | 221 | exit; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | public function enqueue_scripts() { |
| 225 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 225 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 226 | 226 | |
| 227 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
| 228 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 227 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
| 228 | + wp_enqueue_style('wpinv_front_style'); |
|
| 229 | 229 | |
| 230 | 230 | // Register scripts |
| 231 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 232 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 231 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 232 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), WPINV_VERSION); |
|
| 233 | 233 | |
| 234 | 234 | $localize = array(); |
| 235 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 236 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 235 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 236 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 237 | 237 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
| 238 | 238 | $localize['currency_pos'] = wpinv_currency_position(); |
| 239 | 239 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 240 | 240 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 241 | 241 | $localize['decimals'] = wpinv_decimals(); |
| 242 | - $localize['txtComplete'] = __( 'Complete', 'invoicing' ); |
|
| 242 | + $localize['txtComplete'] = __('Complete', 'invoicing'); |
|
| 243 | 243 | $localize['UseTaxes'] = wpinv_use_taxes(); |
| 244 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
| 244 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
| 245 | 245 | |
| 246 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 246 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 247 | 247 | |
| 248 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 248 | + wp_enqueue_script('jquery-blockui'); |
|
| 249 | 249 | $autofill_api = wpinv_get_option('address_autofill_api'); |
| 250 | 250 | $autofill_active = wpinv_get_option('address_autofill_active'); |
| 251 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
| 252 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
| 253 | - wp_dequeue_script( 'google-maps-api' ); |
|
| 251 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
| 252 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
| 253 | + wp_dequeue_script('google-maps-api'); |
|
| 254 | 254 | } |
| 255 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
| 256 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
| 255 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
| 256 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
| 260 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 259 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
| 260 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 261 | 261 | |
| 262 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 263 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 262 | + wp_enqueue_script('wpinv-front-script'); |
|
| 263 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | public function admin_enqueue_scripts() { |
| 267 | 267 | global $post, $pagenow; |
| 268 | 268 | |
| 269 | 269 | $post_type = wpinv_admin_post_type(); |
| 270 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 271 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
| 270 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
| 271 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
| 272 | 272 | |
| 273 | 273 | $jquery_ui_css = false; |
| 274 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
| 274 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
| 275 | 275 | $jquery_ui_css = true; |
| 276 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
| 276 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
| 277 | 277 | $jquery_ui_css = true; |
| 278 | 278 | } |
| 279 | - if ( $jquery_ui_css ) { |
|
| 280 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
| 281 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
| 279 | + if ($jquery_ui_css) { |
|
| 280 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
| 281 | + wp_enqueue_style('jquery-ui-css'); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
| 285 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
| 284 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
| 285 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
| 286 | 286 | |
| 287 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
| 288 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
| 287 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
| 288 | + wp_enqueue_style('wpinv_admin_style'); |
|
| 289 | 289 | |
| 290 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
| 291 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 292 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 290 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
| 291 | + if ($page == 'wpinv-subscriptions') { |
|
| 292 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
| 296 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 295 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
| 296 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 300 | - wp_enqueue_script( 'wp-color-picker' ); |
|
| 299 | + wp_enqueue_style('wp-color-picker'); |
|
| 300 | + wp_enqueue_script('wp-color-picker'); |
|
| 301 | 301 | |
| 302 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 302 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 303 | 303 | |
| 304 | 304 | if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
| 305 | 305 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -310,20 +310,20 @@ discard block |
||
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
| 314 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
| 313 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
| 314 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
| 315 | 315 | |
| 316 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), WPINV_VERSION ); |
|
| 317 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
| 316 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION); |
|
| 317 | + wp_enqueue_script('wpinv-admin-script'); |
|
| 318 | 318 | |
| 319 | 319 | $localize = array(); |
| 320 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 321 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
| 322 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 323 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
| 324 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
| 325 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
| 326 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
| 320 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 321 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
| 322 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 323 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
| 324 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
| 325 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
| 326 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
| 327 | 327 | $localize['tax'] = wpinv_tax_amount(); |
| 328 | 328 | $localize['discount'] = wpinv_discount_amount(); |
| 329 | 329 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -331,69 +331,69 @@ discard block |
||
| 331 | 331 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 332 | 332 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 333 | 333 | $localize['decimals'] = wpinv_decimals(); |
| 334 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
| 335 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
| 336 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
| 337 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
| 338 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
| 339 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
| 340 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
| 341 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
| 342 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
| 343 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
| 344 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
| 345 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
| 346 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
| 347 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
| 334 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
| 335 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
| 336 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
| 337 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
| 338 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
| 339 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
| 340 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
| 341 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
| 342 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
| 343 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
| 344 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
| 345 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
| 346 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
| 347 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
| 348 | 348 | |
| 349 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
| 349 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
| 350 | 350 | |
| 351 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
| 351 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
| 352 | 352 | |
| 353 | - if ( $page == 'wpinv-subscriptions' ) { |
|
| 354 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
| 355 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
| 353 | + if ($page == 'wpinv-subscriptions') { |
|
| 354 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
| 355 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - public function admin_body_class( $classes ) { |
|
| 359 | + public function admin_body_class($classes) { |
|
| 360 | 360 | global $pagenow, $post, $current_screen; |
| 361 | 361 | |
| 362 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
| 362 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) { |
|
| 363 | 363 | $classes .= ' wpinv-cpt'; |
| 364 | 364 | } |
| 365 | 365 | |
| 366 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
| 366 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
| 367 | 367 | |
| 368 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
| 369 | - if ( $add_class ) { |
|
| 370 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
| 368 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
| 369 | + if ($add_class) { |
|
| 370 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | $settings_class = array(); |
| 374 | - if ( $page == 'wpinv-settings' ) { |
|
| 375 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
| 376 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
| 374 | + if ($page == 'wpinv-settings') { |
|
| 375 | + if (!empty($_REQUEST['tab'])) { |
|
| 376 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
| 380 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
| 379 | + if (!empty($_REQUEST['section'])) { |
|
| 380 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
| 383 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - if ( !empty( $settings_class ) ) { |
|
| 387 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
| 386 | + if (!empty($settings_class)) { |
|
| 387 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | $post_type = wpinv_admin_post_type(); |
| 391 | 391 | |
| 392 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
| 392 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
| 393 | 393 | return $classes .= ' wpinv'; |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
| 396 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
| 397 | 397 | $classes .= ' wpi-editable-n'; |
| 398 | 398 | } |
| 399 | 399 | |
@@ -405,20 +405,20 @@ discard block |
||
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | public function wpinv_actions() { |
| 408 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 409 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 408 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 409 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | - public function pre_get_posts( $wp_query ) { |
|
| 414 | - if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
| 415 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 413 | + public function pre_get_posts($wp_query) { |
|
| 414 | + if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
| 415 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | return $wp_query; |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | public function bp_invoicing_init() { |
| 422 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 422 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | \ No newline at end of file |
@@ -35,27 +35,27 @@ discard block |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Registers routes |
|
| 40 | - * |
|
| 38 | + /** |
|
| 39 | + * Registers routes |
|
| 40 | + * |
|
| 41 | 41 | * @since 1.0.13 |
| 42 | - */ |
|
| 43 | - public function register_rest_routes() { |
|
| 42 | + */ |
|
| 43 | + public function register_rest_routes() { |
|
| 44 | 44 | |
| 45 | - //Invoices |
|
| 46 | - register_rest_route( |
|
| 47 | - $this->api_namespace, |
|
| 48 | - '/invoices', |
|
| 49 | - array( |
|
| 45 | + //Invoices |
|
| 46 | + register_rest_route( |
|
| 47 | + $this->api_namespace, |
|
| 48 | + '/invoices', |
|
| 49 | + array( |
|
| 50 | 50 | |
| 51 | - //Create a single invoice |
|
| 52 | - array( |
|
| 53 | - 'methods' => WP_REST_Server::CREATABLE, |
|
| 54 | - 'callback' => array( $this, 'insert_invoice' ), |
|
| 55 | - 'permission_callback' => array( $this, 'can_manage_options' ), |
|
| 51 | + //Create a single invoice |
|
| 52 | + array( |
|
| 53 | + 'methods' => WP_REST_Server::CREATABLE, |
|
| 54 | + 'callback' => array( $this, 'insert_invoice' ), |
|
| 55 | + 'permission_callback' => array( $this, 'can_manage_options' ), |
|
| 56 | 56 | ), |
| 57 | 57 | |
| 58 | - ) |
|
| 58 | + ) |
|
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | 61 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | * @param WP_REST_Request $request |
| 68 | 68 | */ |
| 69 | 69 | public function can_manage_options( $request ) { |
| 70 | - return current_user_can( 'manage_options' ); |
|
| 70 | + return current_user_can( 'manage_options' ); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | 11 | exit; |
| 12 | 12 | } |
| 13 | 13 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | /** |
| 20 | 20 | * @param string A prefix for our REST routes |
| 21 | 21 | */ |
| 22 | - protected $api_namespace = ''; |
|
| 22 | + protected $api_namespace = ''; |
|
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | 25 | * Class constructor. |
@@ -27,11 +27,11 @@ discard block |
||
| 27 | 27 | * @since 1.0.13 |
| 28 | 28 | * Sets the API namespace and inits hooks |
| 29 | 29 | */ |
| 30 | - public function __construct( $api_namespace = 'invoicing/v1' ) { |
|
| 31 | - $this->api_namespace = apply_filters( 'invoicing_api_namespace', $api_namespace ); |
|
| 30 | + public function __construct($api_namespace = 'invoicing/v1') { |
|
| 31 | + $this->api_namespace = apply_filters('invoicing_api_namespace', $api_namespace); |
|
| 32 | 32 | |
| 33 | 33 | //Register REST routes |
| 34 | - add_action( 'rest_api_init', array( $this, 'register_rest_routes' ) ); |
|
| 34 | + add_action('rest_api_init', array($this, 'register_rest_routes')); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | //Create a single invoice |
| 52 | 52 | array( |
| 53 | 53 | 'methods' => WP_REST_Server::CREATABLE, |
| 54 | - 'callback' => array( $this, 'insert_invoice' ), |
|
| 55 | - 'permission_callback' => array( $this, 'can_manage_options' ), |
|
| 54 | + 'callback' => array($this, 'insert_invoice'), |
|
| 55 | + 'permission_callback' => array($this, 'can_manage_options'), |
|
| 56 | 56 | ), |
| 57 | 57 | |
| 58 | 58 | ) |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | * @since 1.0.13 |
| 67 | 67 | * @param WP_REST_Request $request |
| 68 | 68 | */ |
| 69 | - public function can_manage_options( $request ) { |
|
| 70 | - return current_user_can( 'manage_options' ); |
|
| 69 | + public function can_manage_options($request) { |
|
| 70 | + return current_user_can('manage_options'); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -76,41 +76,41 @@ discard block |
||
| 76 | 76 | * @param WP_REST_Request $request |
| 77 | 77 | * @return mixed WP_Error or invoice data |
| 78 | 78 | */ |
| 79 | - public function insert_invoice( $request ) { |
|
| 79 | + public function insert_invoice($request) { |
|
| 80 | 80 | |
| 81 | 81 | // Fetch invoice data from the request |
| 82 | - $invoice_data = wp_unslash( $request->get_params() ); |
|
| 82 | + $invoice_data = wp_unslash($request->get_params()); |
|
| 83 | 83 | |
| 84 | 84 | // Abort if no invoice data is provided |
| 85 | - if( empty( $invoice_data ) ) { |
|
| 86 | - return new WP_Error( 'missing_data', __( 'Invoice data not provided', 'invoicing' ) ); |
|
| 85 | + if (empty($invoice_data)) { |
|
| 86 | + return new WP_Error('missing_data', __('Invoice data not provided', 'invoicing')); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // Try creating the invoice |
| 90 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
| 90 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
| 91 | 91 | |
| 92 | - if ( is_wp_error( $invoice ) ) { |
|
| 92 | + if (is_wp_error($invoice)) { |
|
| 93 | 93 | return $invoice; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // Fetch invoice data ... |
| 97 | - $invoice_data = get_object_vars( $invoice ); |
|
| 97 | + $invoice_data = get_object_vars($invoice); |
|
| 98 | 98 | |
| 99 | 99 | // ... and formart some of it |
| 100 | - foreach( $invoice_data as $key => $value ) { |
|
| 101 | - $invoice_data[ $key ] = $invoice->get( $key ); |
|
| 100 | + foreach ($invoice_data as $key => $value) { |
|
| 101 | + $invoice_data[$key] = $invoice->get($key); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | //Return the invoice data |
| 105 | - return rest_ensure_response( $invoice_data ); |
|
| 105 | + return rest_ensure_response($invoice_data); |
|
| 106 | 106 | |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - public function send_status( $code ) { |
|
| 110 | - status_header( $code ); |
|
| 109 | + public function send_status($code) { |
|
| 110 | + status_header($code); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - protected function set_billing_details( $invoice, $data ) { |
|
| 113 | + protected function set_billing_details($invoice, $data) { |
|
| 114 | 114 | $address_fields = array( |
| 115 | 115 | 'user_id', |
| 116 | 116 | 'first_name', |
@@ -129,66 +129,66 @@ discard block |
||
| 129 | 129 | $billing_details = array(); |
| 130 | 130 | $user_id = $invoice->get_user_id(); |
| 131 | 131 | |
| 132 | - foreach ( $address_fields as $field ) { |
|
| 133 | - if ( isset( $data['billing_details'][ $field ] ) ) { |
|
| 134 | - $value = sanitize_text_field( $data['billing_details'][ $field ] ); |
|
| 132 | + foreach ($address_fields as $field) { |
|
| 133 | + if (isset($data['billing_details'][$field])) { |
|
| 134 | + $value = sanitize_text_field($data['billing_details'][$field]); |
|
| 135 | 135 | |
| 136 | - if ( $field == 'country' && empty( $value ) ) { |
|
| 137 | - if ( !empty( $invoice->country ) ) { |
|
| 136 | + if ($field == 'country' && empty($value)) { |
|
| 137 | + if (!empty($invoice->country)) { |
|
| 138 | 138 | $value = $invoice->country; |
| 139 | 139 | } else { |
| 140 | - $value = wpinv_default_billing_country( '', $user_id ); |
|
| 140 | + $value = wpinv_default_billing_country('', $user_id); |
|
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ( $field == 'state' && empty( $value ) ) { |
|
| 145 | - if ( !empty( $invoice->state ) ) { |
|
| 144 | + if ($field == 'state' && empty($value)) { |
|
| 145 | + if (!empty($invoice->state)) { |
|
| 146 | 146 | $value = $invoice->state; |
| 147 | 147 | } else { |
| 148 | 148 | $value = wpinv_get_default_state(); |
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - $invoice->set( $field, $value ); |
|
| 152 | + $invoice->set($field, $value); |
|
| 153 | 153 | |
| 154 | - update_post_meta( $invoice->ID, '_wpinv_' . $field, $value ); |
|
| 154 | + update_post_meta($invoice->ID, '_wpinv_' . $field, $value); |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | return $invoice; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - protected function set_discount( $invoice, $data ) { |
|
| 162 | - if ( isset( $data['discount'] ) ) { |
|
| 163 | - $invoice->set( 'discount', wpinv_round_amount( $data['discount'] ) ); |
|
| 161 | + protected function set_discount($invoice, $data) { |
|
| 162 | + if (isset($data['discount'])) { |
|
| 163 | + $invoice->set('discount', wpinv_round_amount($data['discount'])); |
|
| 164 | 164 | |
| 165 | - update_post_meta( $invoice->ID, '_wpinv_discount', wpinv_round_amount( $data['discount'] ) ); |
|
| 165 | + update_post_meta($invoice->ID, '_wpinv_discount', wpinv_round_amount($data['discount'])); |
|
| 166 | 166 | |
| 167 | - if ( isset( $data['discount_code'] ) ) { |
|
| 168 | - $invoice->set( 'discount_code', $data['discount_code'] ); |
|
| 167 | + if (isset($data['discount_code'])) { |
|
| 168 | + $invoice->set('discount_code', $data['discount_code']); |
|
| 169 | 169 | |
| 170 | - update_post_meta( $invoice->ID, '_wpinv_discount_code', $data['discount_code'] ); |
|
| 170 | + update_post_meta($invoice->ID, '_wpinv_discount_code', $data['discount_code']); |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | return $invoice; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - protected function set_items( $invoice, $data ) { |
|
| 178 | - if ( !empty( $data['items'] ) && is_array( $data['items'] ) ) { |
|
| 177 | + protected function set_items($invoice, $data) { |
|
| 178 | + if (!empty($data['items']) && is_array($data['items'])) { |
|
| 179 | 179 | $items_array = array(); |
| 180 | 180 | |
| 181 | - if ( !empty( $invoice->country ) ) { |
|
| 181 | + if (!empty($invoice->country)) { |
|
| 182 | 182 | $country = $invoice->country; |
| 183 | - } else if ( !empty( $data['billing_details']['country'] ) ) { |
|
| 183 | + } else if (!empty($data['billing_details']['country'])) { |
|
| 184 | 184 | $country = $data['billing_details']['country']; |
| 185 | 185 | } else { |
| 186 | - $country = wpinv_default_billing_country( '', $invoice->get_user_id() ); |
|
| 186 | + $country = wpinv_default_billing_country('', $invoice->get_user_id()); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if ( !empty( $invoice->state ) ) { |
|
| 189 | + if (!empty($invoice->state)) { |
|
| 190 | 190 | $state = $invoice->state; |
| 191 | - } else if ( !empty( $data['billing_details']['state'] ) ) { |
|
| 191 | + } else if (!empty($data['billing_details']['state'])) { |
|
| 192 | 192 | $state = $data['billing_details']['state']; |
| 193 | 193 | } else { |
| 194 | 194 | $state = wpinv_get_default_state(); |
@@ -197,54 +197,54 @@ discard block |
||
| 197 | 197 | $_POST['country'] = $country; |
| 198 | 198 | $_POST['state'] = $state; |
| 199 | 199 | |
| 200 | - $rate = wpinv_get_tax_rate( $country, $state, 'global' ); |
|
| 200 | + $rate = wpinv_get_tax_rate($country, $state, 'global'); |
|
| 201 | 201 | |
| 202 | 202 | $total_tax = 0; |
| 203 | - foreach ( $data['items'] as $item ) { |
|
| 204 | - $id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
| 205 | - $title = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : ''; |
|
| 206 | - $desc = isset( $item['description'] ) ? sanitize_text_field( $item['description'] ) : ''; |
|
| 207 | - $amount = isset( $item['amount'] ) ? wpinv_round_amount( $item['amount'] ) : 0; |
|
| 203 | + foreach ($data['items'] as $item) { |
|
| 204 | + $id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
| 205 | + $title = isset($item['title']) ? sanitize_text_field($item['title']) : ''; |
|
| 206 | + $desc = isset($item['description']) ? sanitize_text_field($item['description']) : ''; |
|
| 207 | + $amount = isset($item['amount']) ? wpinv_round_amount($item['amount']) : 0; |
|
| 208 | 208 | |
| 209 | - if ( !empty( $item['vat_rates_class'] ) ) { |
|
| 209 | + if (!empty($item['vat_rates_class'])) { |
|
| 210 | 210 | $vat_rates_class = $item['vat_rates_class']; |
| 211 | 211 | } else { |
| 212 | 212 | $vat_rates_class = '_standard'; |
| 213 | 213 | } |
| 214 | - $vat_rate = wpinv_get_tax_rate( $country, $state, $id ); |
|
| 214 | + $vat_rate = wpinv_get_tax_rate($country, $state, $id); |
|
| 215 | 215 | |
| 216 | - $tax = $amount > 0 ? ( $amount * 0.01 * (float)$vat_rate ) : 0; |
|
| 216 | + $tax = $amount > 0 ? ($amount * 0.01 * (float)$vat_rate) : 0; |
|
| 217 | 217 | $total_tax += $tax; |
| 218 | 218 | |
| 219 | 219 | $items_array[] = array( |
| 220 | 220 | 'id' => $id, |
| 221 | - 'title' => esc_html( $title ), |
|
| 222 | - 'description' => esc_html( $desc ), |
|
| 223 | - 'amount' => $amount > 0 ? wpinv_round_amount( $amount ) : 0, |
|
| 224 | - 'subtotal' => $amount > 0 ? wpinv_round_amount( $amount ) : 0, |
|
| 221 | + 'title' => esc_html($title), |
|
| 222 | + 'description' => esc_html($desc), |
|
| 223 | + 'amount' => $amount > 0 ? wpinv_round_amount($amount) : 0, |
|
| 224 | + 'subtotal' => $amount > 0 ? wpinv_round_amount($amount) : 0, |
|
| 225 | 225 | 'vat_rates_class' => $vat_rates_class, |
| 226 | 226 | 'vat_rate' => $vat_rate, |
| 227 | - 'tax' => $tax > 0 ? wpinv_round_amount( $tax ) : 0, |
|
| 227 | + 'tax' => $tax > 0 ? wpinv_round_amount($tax) : 0, |
|
| 228 | 228 | ); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - update_post_meta( $invoice->ID, '_wpinv_tax', wpinv_round_amount( $total_tax ) ); |
|
| 232 | - $invoice->set( 'tax', wpinv_round_amount( $total_tax ) ); |
|
| 231 | + update_post_meta($invoice->ID, '_wpinv_tax', wpinv_round_amount($total_tax)); |
|
| 232 | + $invoice->set('tax', wpinv_round_amount($total_tax)); |
|
| 233 | 233 | |
| 234 | - $items_array = apply_filters( 'wpinv_save_invoice_items', $items_array, $data['items'], $invoice ); |
|
| 234 | + $items_array = apply_filters('wpinv_save_invoice_items', $items_array, $data['items'], $invoice); |
|
| 235 | 235 | |
| 236 | - $invoice->set( 'items', $items_array ); |
|
| 237 | - update_post_meta( $invoice->ID, '_wpinv_items', $items_array ); |
|
| 236 | + $invoice->set('items', $items_array); |
|
| 237 | + update_post_meta($invoice->ID, '_wpinv_items', $items_array); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | return $invoice; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - protected function set_invoice_meta( $invoice_id, $invoice_meta ) { |
|
| 244 | - foreach ( $invoice_meta as $meta_key => $meta_value ) { |
|
| 243 | + protected function set_invoice_meta($invoice_id, $invoice_meta) { |
|
| 244 | + foreach ($invoice_meta as $meta_key => $meta_value) { |
|
| 245 | 245 | |
| 246 | - if ( is_string( $meta_key) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) { |
|
| 247 | - update_post_meta( $invoice_id, $meta_key, $meta_value ); |
|
| 246 | + if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) { |
|
| 247 | + update_post_meta($invoice_id, $meta_key, $meta_value); |
|
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | } |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | class WPInv_API_Exception extends Exception { |
| 255 | 255 | protected $error_code; |
| 256 | 256 | |
| 257 | - public function __construct( $error_code, $error_message, $http_status_code ) { |
|
| 257 | + public function __construct($error_code, $error_message, $http_status_code) { |
|
| 258 | 258 | $this->error_code = $error_code; |
| 259 | - parent::__construct( $error_message, $http_status_code ); |
|
| 259 | + parent::__construct($error_message, $http_status_code); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | public function getErrorCode() { |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | 9 | // MUST have WordPress. |
| 10 | -if ( !defined( 'WPINC' ) ) { |
|
| 10 | +if (!defined('WPINC')) { |
|
| 11 | 11 | exit; |
| 12 | 12 | } |
| 13 | 13 | |
@@ -24,40 +24,40 @@ discard block |
||
| 24 | 24 | * @param Array $assoc_args Key value arguments stored in associated array format. |
| 25 | 25 | * @since 1.0.13 |
| 26 | 26 | */ |
| 27 | - public function insert_invoice( $args, $assoc_args ) { |
|
| 27 | + public function insert_invoice($args, $assoc_args) { |
|
| 28 | 28 | |
| 29 | 29 | // Fetch invoice data from the args |
| 30 | - $invoice_data = wp_unslash( $assoc_args ); |
|
| 30 | + $invoice_data = wp_unslash($assoc_args); |
|
| 31 | 31 | |
| 32 | 32 | // Abort if no invoice data is provided |
| 33 | - if( empty( $invoice_data ) ) { |
|
| 34 | - return WP_CLI::error( __( 'Invoice data not provided', 'invoicing' ) ); |
|
| 33 | + if (empty($invoice_data)) { |
|
| 34 | + return WP_CLI::error(__('Invoice data not provided', 'invoicing')); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | //Cart details |
| 38 | - if( !empty( $invoice_data['cart_details'] ) ) { |
|
| 39 | - $invoice_data['cart_details'] = json_decode( $invoice_data['cart_details'], true ); |
|
| 38 | + if (!empty($invoice_data['cart_details'])) { |
|
| 39 | + $invoice_data['cart_details'] = json_decode($invoice_data['cart_details'], true); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | //User details |
| 43 | - if( !empty( $invoice_data['user_info'] ) ) { |
|
| 44 | - $invoice_data['user_info'] = json_decode( $invoice_data['user_info'], true ); |
|
| 43 | + if (!empty($invoice_data['user_info'])) { |
|
| 44 | + $invoice_data['user_info'] = json_decode($invoice_data['user_info'], true); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | //Payment info |
| 48 | - if( !empty( $invoice_data['payment_details'] ) ) { |
|
| 49 | - $invoice_data['payment_details'] = json_decode( $invoice_data['payment_details'], true ); |
|
| 48 | + if (!empty($invoice_data['payment_details'])) { |
|
| 49 | + $invoice_data['payment_details'] = json_decode($invoice_data['payment_details'], true); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // Try creating the invoice |
| 53 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
| 53 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
| 54 | 54 | |
| 55 | - if ( is_wp_error( $invoice ) ) { |
|
| 56 | - return WP_CLI::error( $invoice->get_error_message() ); |
|
| 55 | + if (is_wp_error($invoice)) { |
|
| 56 | + return WP_CLI::error($invoice->get_error_message()); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - $message = sprintf( __( 'Invoice %s created', 'invoicing' ), $invoice->ID ); |
|
| 60 | - WP_CLI::success( $message ); |
|
| 59 | + $message = sprintf(__('Invoice %s created', 'invoicing'), $invoice->ID); |
|
| 60 | + WP_CLI::success($message); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |