@@ -1,23 +1,23 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | // MUST have WordPress. |
| 3 | -if ( !defined( 'WPINC' ) ) { |
|
| 4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
| 3 | +if (!defined('WPINC')) { |
|
| 4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | function wpinv_gd_active() { |
| 8 | - return (bool)defined( 'GEODIRECTORY_VERSION' ); |
|
| 8 | + return (bool)defined('GEODIRECTORY_VERSION'); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | function wpinv_pm_active() { |
| 12 | - return (bool)wpinv_gd_active() && (bool)defined( 'GEODIRPAYMENT_VERSION' ); |
|
| 12 | + return (bool)wpinv_gd_active() && (bool)defined('GEODIRPAYMENT_VERSION'); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | -function wpinv_is_gd_post_type( $post_type ) { |
|
| 15 | +function wpinv_is_gd_post_type($post_type) { |
|
| 16 | 16 | global $gd_posttypes; |
| 17 | 17 | |
| 18 | - $gd_posttypes = !empty( $gd_posttypes ) && is_array( $gd_posttypes ) ? $gd_posttypes : geodir_get_posttypes(); |
|
| 18 | + $gd_posttypes = !empty($gd_posttypes) && is_array($gd_posttypes) ? $gd_posttypes : geodir_get_posttypes(); |
|
| 19 | 19 | |
| 20 | - if ( !empty( $post_type ) && !empty( $gd_posttypes ) && in_array( $post_type, $gd_posttypes ) ) { |
|
| 20 | + if (!empty($post_type) && !empty($gd_posttypes) && in_array($post_type, $gd_posttypes)) { |
|
| 21 | 21 | return true; |
| 22 | 22 | } |
| 23 | 23 | |
@@ -29,10 +29,10 @@ discard block |
||
| 29 | 29 | return; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
| 32 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 33 | 33 | // Add fields for force upgrade |
| 34 | - if ( defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column') ) { |
|
| 35 | - geodir_add_column_if_not_exist( INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0' ); |
|
| 34 | + if (defined('INVOICE_TABLE') && !get_option('wpinv_gdp_column')) { |
|
| 35 | + geodir_add_column_if_not_exist(INVOICE_TABLE, 'invoice_id', 'INT( 11 ) NOT NULL DEFAULT 0'); |
|
| 36 | 36 | |
| 37 | 37 | update_option('wpinv_gdp_column', '1'); |
| 38 | 38 | } |
@@ -40,39 +40,39 @@ discard block |
||
| 40 | 40 | wpinv_merge_gd_packages_to_items(); |
| 41 | 41 | } |
| 42 | 42 | } |
| 43 | -add_action( 'admin_init', 'wpinv_geodir_integration' ); |
|
| 43 | +add_action('admin_init', 'wpinv_geodir_integration'); |
|
| 44 | 44 | |
| 45 | -function wpinv_get_gdp_package_type( $item_types ) { |
|
| 46 | - if ( wpinv_pm_active() ) { |
|
| 47 | - $item_types['package'] = __( 'Package', 'invoicing' ); |
|
| 45 | +function wpinv_get_gdp_package_type($item_types) { |
|
| 46 | + if (wpinv_pm_active()) { |
|
| 47 | + $item_types['package'] = __('Package', 'invoicing'); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | return $item_types; |
| 51 | 51 | } |
| 52 | -add_filter( 'wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1 ); |
|
| 52 | +add_filter('wpinv_get_item_types', 'wpinv_get_gdp_package_type', 10, 1); |
|
| 53 | 53 | |
| 54 | 54 | function wpinv_update_package_item($package_id) { |
| 55 | 55 | return wpinv_merge_gd_package_to_item($package_id, true); |
| 56 | 56 | } |
| 57 | 57 | add_action('geodir_after_save_package', 'wpinv_update_package_item', 10, 1); |
| 58 | 58 | |
| 59 | -function wpinv_merge_gd_packages_to_items( $force = false ) { |
|
| 60 | - if ( $merged = get_option( 'wpinv_merge_gd_packages' ) && !$force ) { |
|
| 59 | +function wpinv_merge_gd_packages_to_items($force = false) { |
|
| 60 | + if ($merged = get_option('wpinv_merge_gd_packages') && !$force) { |
|
| 61 | 61 | return true; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if(!function_exists('geodir_package_list_info')){ |
|
| 64 | + if (!function_exists('geodir_package_list_info')) { |
|
| 65 | 65 | return false; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | $packages = geodir_package_list_info(); |
| 69 | 69 | |
| 70 | - foreach ( $packages as $key => $package ) { |
|
| 71 | - wpinv_merge_gd_package_to_item( $package->pid, $force, $package ); |
|
| 70 | + foreach ($packages as $key => $package) { |
|
| 71 | + wpinv_merge_gd_package_to_item($package->pid, $force, $package); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if ( !$merged ) { |
|
| 75 | - update_option( 'wpinv_merge_gd_packages', 1 ); |
|
| 74 | + if (!$merged) { |
|
| 75 | + update_option('wpinv_merge_gd_packages', 1); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | return true; |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | $package = empty($package) ? geodir_get_package_info_by_id($package_id, '') : $package; |
| 103 | 103 | |
| 104 | - if ( empty($package) || !wpinv_is_gd_post_type( $package->post_type ) ) { |
|
| 104 | + if (empty($package) || !wpinv_is_gd_post_type($package->post_type)) { |
|
| 105 | 105 | return false; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -110,17 +110,17 @@ discard block |
||
| 110 | 110 | $meta['custom_id'] = $package_id; |
| 111 | 111 | $meta['custom_singular_name'] = get_post_type_singular_label($package->post_type); |
| 112 | 112 | $meta['custom_name'] = get_post_type_plural_label($package->post_type); |
| 113 | - $meta['price'] = wpinv_round_amount( $package->amount ); |
|
| 113 | + $meta['price'] = wpinv_round_amount($package->amount); |
|
| 114 | 114 | $meta['vat_rule'] = 'digital'; |
| 115 | 115 | $meta['vat_class'] = '_standard'; |
| 116 | 116 | |
| 117 | - if ( !empty( $package->sub_active ) ) { |
|
| 118 | - $sub_num_trial_days = absint( $package->sub_num_trial_days ); |
|
| 117 | + if (!empty($package->sub_active)) { |
|
| 118 | + $sub_num_trial_days = absint($package->sub_num_trial_days); |
|
| 119 | 119 | |
| 120 | 120 | $meta['is_recurring'] = 1; |
| 121 | 121 | $meta['recurring_period'] = $package->sub_units; |
| 122 | - $meta['recurring_interval'] = absint( $package->sub_units_num ); |
|
| 123 | - $meta['recurring_limit'] = absint( $package->sub_units_num_times ); |
|
| 122 | + $meta['recurring_interval'] = absint($package->sub_units_num); |
|
| 123 | + $meta['recurring_limit'] = absint($package->sub_units_num_times); |
|
| 124 | 124 | $meta['free_trial'] = $sub_num_trial_days > 0 ? 1 : 0; |
| 125 | 125 | $meta['trial_period'] = $package->sub_num_trial_units; |
| 126 | 126 | $meta['trial_interval'] = $sub_num_trial_days; |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | $meta['trial_interval'] = ''; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $data = array( |
|
| 137 | + $data = array( |
|
| 138 | 138 | 'post_title' => $package->title, |
| 139 | 139 | 'post_excerpt' => $package->title_desc, |
| 140 | 140 | 'post_status' => $package->status == 1 ? 'publish' : 'pending', |
@@ -151,48 +151,48 @@ discard block |
||
| 151 | 151 | return $item; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | -function wpinv_gdp_to_wpi_gateway( $payment_method ) { |
|
| 155 | - switch( $payment_method ) { |
|
| 154 | +function wpinv_gdp_to_wpi_gateway($payment_method) { |
|
| 155 | + switch ($payment_method) { |
|
| 156 | 156 | case 'prebanktransfer': |
| 157 | 157 | $gateway = 'bank_transfer'; |
| 158 | 158 | break; |
| 159 | 159 | default: |
| 160 | - $gateway = empty( $payment_method ) ? 'manual' : $payment_method; |
|
| 160 | + $gateway = empty($payment_method) ? 'manual' : $payment_method; |
|
| 161 | 161 | break; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - return apply_filters( 'wpinv_gdp_to_wpi_gateway', $gateway, $payment_method ); |
|
| 164 | + return apply_filters('wpinv_gdp_to_wpi_gateway', $gateway, $payment_method); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | -function wpinv_gdp_to_wpi_gateway_title( $payment_method ) { |
|
| 168 | - $gateway = wpinv_gdp_to_wpi_gateway( $payment_method ); |
|
| 167 | +function wpinv_gdp_to_wpi_gateway_title($payment_method) { |
|
| 168 | + $gateway = wpinv_gdp_to_wpi_gateway($payment_method); |
|
| 169 | 169 | |
| 170 | - $gateway_title = wpinv_get_gateway_checkout_label( $gateway ); |
|
| 170 | + $gateway_title = wpinv_get_gateway_checkout_label($gateway); |
|
| 171 | 171 | |
| 172 | - if ( $gateway == $gateway_title ) { |
|
| 173 | - $gateway_title = geodir_payment_method_title( $gateway ); |
|
| 172 | + if ($gateway == $gateway_title) { |
|
| 173 | + $gateway_title = geodir_payment_method_title($gateway); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - return apply_filters( 'wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method ); |
|
| 176 | + return apply_filters('wpinv_gdp_to_wpi_gateway_title', $gateway_title, $payment_method); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | function wpinv_print_checkout_errors() { |
| 180 | 180 | global $wpi_session; |
| 181 | 181 | wpinv_print_errors(); |
| 182 | 182 | } |
| 183 | -add_action( 'geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10 ); |
|
| 183 | +add_action('geodir_checkout_page_content', 'wpinv_print_checkout_errors', -10); |
|
| 184 | 184 | |
| 185 | -function wpinv_cpt_save( $invoice_id, $update = false, $pre_status = NULL ) { |
|
| 185 | +function wpinv_cpt_save($invoice_id, $update = false, $pre_status = NULL) { |
|
| 186 | 186 | global $wpi_nosave, $wpi_zero_tax, $wpi_gdp_inv_merge; |
| 187 | 187 | |
| 188 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
| 188 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
| 189 | 189 | |
| 190 | - $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : 0; |
|
| 190 | + $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : 0; |
|
| 191 | 191 | |
| 192 | 192 | if (!empty($invoice_info)) { |
| 193 | - $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice( $wpi_invoice_id ) : NULL; |
|
| 193 | + $wpi_invoice = $wpi_invoice_id > 0 ? wpinv_get_invoice($wpi_invoice_id) : NULL; |
|
| 194 | 194 | |
| 195 | - if ( !empty( $wpi_invoice ) ) { // update invoice |
|
| 195 | + if (!empty($wpi_invoice)) { // update invoice |
|
| 196 | 196 | $save = false; |
| 197 | 197 | if ($invoice_info->coupon_code !== $wpi_invoice->discount_code || (float)$invoice_info->discount < (float)$wpi_invoice->discount || (float)$invoice_info->discount > (float)$wpi_invoice->discount) { |
| 198 | 198 | $save = true; |
@@ -202,16 +202,16 @@ discard block |
||
| 202 | 202 | |
| 203 | 203 | if ($invoice_info->paymentmethod !== $wpi_invoice->gateway) { |
| 204 | 204 | $save = true; |
| 205 | - $gateway = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : ''; |
|
| 206 | - $gateway = wpinv_gdp_to_wpi_gateway( $gateway ); |
|
| 207 | - $gateway_title = wpinv_gdp_to_wpi_gateway_title( $gateway ); |
|
| 208 | - $wpi_invoice->set('gateway', $gateway ); |
|
| 209 | - $wpi_invoice->set('gateway_title', $gateway_title ); |
|
| 205 | + $gateway = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : ''; |
|
| 206 | + $gateway = wpinv_gdp_to_wpi_gateway($gateway); |
|
| 207 | + $gateway_title = wpinv_gdp_to_wpi_gateway_title($gateway); |
|
| 208 | + $wpi_invoice->set('gateway', $gateway); |
|
| 209 | + $wpi_invoice->set('gateway_title', $gateway_title); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - if ( ( $status = wpinv_gdp_to_wpi_status( $invoice_info->status ) ) !== $wpi_invoice->status ) { |
|
| 212 | + if (($status = wpinv_gdp_to_wpi_status($invoice_info->status)) !== $wpi_invoice->status) { |
|
| 213 | 213 | $save = true; |
| 214 | - $wpi_invoice->set( 'status', $status ); |
|
| 214 | + $wpi_invoice->set('status', $status); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | if ($save) { |
@@ -222,16 +222,16 @@ discard block |
||
| 222 | 222 | |
| 223 | 223 | return $wpi_invoice; |
| 224 | 224 | } else { // create invoice |
| 225 | - $user_info = get_userdata( $invoice_info->user_id ); |
|
| 225 | + $user_info = get_userdata($invoice_info->user_id); |
|
| 226 | 226 | |
| 227 | - if ( !empty( $pre_status ) ) { |
|
| 227 | + if (!empty($pre_status)) { |
|
| 228 | 228 | $invoice_info->status = $pre_status; |
| 229 | 229 | } |
| 230 | - $status = wpinv_gdp_to_wpi_status( $invoice_info->status ); |
|
| 230 | + $status = wpinv_gdp_to_wpi_status($invoice_info->status); |
|
| 231 | 231 | |
| 232 | 232 | $wpi_zero_tax = false; |
| 233 | 233 | |
| 234 | - if ( $wpi_gdp_inv_merge && in_array( $status, array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) { |
|
| 234 | + if ($wpi_gdp_inv_merge && in_array($status, array('publish', 'wpi-processing', 'wpi-renewal'))) { |
|
| 235 | 235 | $wpi_zero_tax = true; |
| 236 | 236 | } |
| 237 | 237 | |
@@ -241,13 +241,13 @@ discard block |
||
| 241 | 241 | $invoice_data['user_id'] = $invoice_info->user_id; |
| 242 | 242 | $invoice_data['created_via'] = 'API'; |
| 243 | 243 | |
| 244 | - if ( !empty( $invoice_info->date ) ) { |
|
| 245 | - $invoice_data['created_date'] = $invoice_info->date; |
|
| 244 | + if (!empty($invoice_info->date)) { |
|
| 245 | + $invoice_data['created_date'] = $invoice_info->date; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - $paymentmethod = !empty( $invoice_info->paymentmethod ) ? $invoice_info->paymentmethod : ''; |
|
| 249 | - $paymentmethod = wpinv_gdp_to_wpi_gateway( $paymentmethod ); |
|
| 250 | - $payment_method_title = wpinv_gdp_to_wpi_gateway_title( $paymentmethod ); |
|
| 248 | + $paymentmethod = !empty($invoice_info->paymentmethod) ? $invoice_info->paymentmethod : ''; |
|
| 249 | + $paymentmethod = wpinv_gdp_to_wpi_gateway($paymentmethod); |
|
| 250 | + $payment_method_title = wpinv_gdp_to_wpi_gateway_title($paymentmethod); |
|
| 251 | 251 | |
| 252 | 252 | $invoice_data['payment_details'] = array( |
| 253 | 253 | 'gateway' => $paymentmethod, |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | 'currency' => geodir_get_currency_type(), |
| 256 | 256 | ); |
| 257 | 257 | |
| 258 | - $user_address = wpinv_get_user_address( $invoice_info->user_id, false ); |
|
| 258 | + $user_address = wpinv_get_user_address($invoice_info->user_id, false); |
|
| 259 | 259 | |
| 260 | 260 | $invoice_data['user_info'] = array( |
| 261 | 261 | 'user_id' => $invoice_info->user_id, |
@@ -278,14 +278,14 @@ discard block |
||
| 278 | 278 | |
| 279 | 279 | $post_item = wpinv_get_gd_package_item($invoice_info->package_id); |
| 280 | 280 | |
| 281 | - if ( $invoice_info->invoice_type == 'add_franchise' ) { |
|
| 281 | + if ($invoice_info->invoice_type == 'add_franchise') { |
|
| 282 | 282 | $custom_price = $invoice_info->amount; |
| 283 | 283 | } else { |
| 284 | 284 | $custom_price = ''; |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | - if ( !empty( $post_item ) ) { |
|
| 288 | - $cart_details = array(); |
|
| 287 | + if (!empty($post_item)) { |
|
| 288 | + $cart_details = array(); |
|
| 289 | 289 | $cart_details[] = array( |
| 290 | 290 | 'id' => $post_item->ID, |
| 291 | 291 | 'name' => $post_item->get_name(), |
@@ -299,19 +299,19 @@ discard block |
||
| 299 | 299 | ), |
| 300 | 300 | ); |
| 301 | 301 | |
| 302 | - $invoice_data['cart_details'] = $cart_details; |
|
| 302 | + $invoice_data['cart_details'] = $cart_details; |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - $data = array( 'invoice' => $invoice_data ); |
|
| 305 | + $data = array('invoice' => $invoice_data); |
|
| 306 | 306 | |
| 307 | 307 | $wpinv_api = new WPInv_API(); |
| 308 | - $data = $wpinv_api->insert_invoice( $data ); |
|
| 308 | + $data = $wpinv_api->insert_invoice($data); |
|
| 309 | 309 | |
| 310 | - if ( is_wp_error( $data ) ) { |
|
| 311 | - wpinv_error_log( 'WPInv_Invoice: ' . $data->get_error_message() ); |
|
| 310 | + if (is_wp_error($data)) { |
|
| 311 | + wpinv_error_log('WPInv_Invoice: ' . $data->get_error_message()); |
|
| 312 | 312 | } else { |
| 313 | - if ( !empty( $data ) ) { |
|
| 314 | - update_post_meta( $data->ID, '_wpinv_gdp_id', $invoice_id ); |
|
| 313 | + if (!empty($data)) { |
|
| 314 | + update_post_meta($data->ID, '_wpinv_gdp_id', $invoice_id); |
|
| 315 | 315 | |
| 316 | 316 | $update_data = array(); |
| 317 | 317 | $update_data['tax_amount'] = $data->get_tax(); |
@@ -319,14 +319,14 @@ discard block |
||
| 319 | 319 | $update_data['invoice_id'] = $data->ID; |
| 320 | 320 | |
| 321 | 321 | global $wpdb; |
| 322 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $invoice_id ) ); |
|
| 322 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $invoice_id)); |
|
| 323 | 323 | |
| 324 | 324 | return $data; |
| 325 | 325 | } else { |
| 326 | - if ( $update ) { |
|
| 327 | - wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to update invoice.', 'invoicing' ) ); |
|
| 326 | + if ($update) { |
|
| 327 | + wpinv_error_log('WPInv_Invoice: ' . __('Fail to update invoice.', 'invoicing')); |
|
| 328 | 328 | } else { |
| 329 | - wpinv_error_log( 'WPInv_Invoice: ' . __( 'Fail to create invoice.', 'invoicing' ) ); |
|
| 329 | + wpinv_error_log('WPInv_Invoice: ' . __('Fail to create invoice.', 'invoicing')); |
|
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | 332 | } |
@@ -337,59 +337,59 @@ discard block |
||
| 337 | 337 | } |
| 338 | 338 | add_action('geodir_payment_invoice_created', 'wpinv_cpt_save', 11, 3); |
| 339 | 339 | |
| 340 | -function wpinv_cpt_update( $invoice_id ) { |
|
| 341 | - return wpinv_cpt_save( $invoice_id, true ); |
|
| 340 | +function wpinv_cpt_update($invoice_id) { |
|
| 341 | + return wpinv_cpt_save($invoice_id, true); |
|
| 342 | 342 | } |
| 343 | 343 | add_action('geodir_payment_invoice_updated', 'wpinv_cpt_update', 11, 1); |
| 344 | 344 | |
| 345 | -function wpinv_payment_status_changed( $invoice_id, $new_status, $old_status = 'wpi-pending', $subscription = false ) { |
|
| 346 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
| 347 | - if ( empty( $invoice_info ) ) { |
|
| 345 | +function wpinv_payment_status_changed($invoice_id, $new_status, $old_status = 'wpi-pending', $subscription = false) { |
|
| 346 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
| 347 | + if (empty($invoice_info)) { |
|
| 348 | 348 | return false; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - $invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL; |
|
| 352 | - if ( !empty( $invoice ) ) { |
|
| 351 | + $invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL; |
|
| 352 | + if (!empty($invoice)) { |
|
| 353 | 353 | $new_status = wpinv_gdp_to_wpi_status($new_status); |
| 354 | - $invoice = wpinv_update_payment_status( $invoice->ID, $new_status ); |
|
| 354 | + $invoice = wpinv_update_payment_status($invoice->ID, $new_status); |
|
| 355 | 355 | } else { |
| 356 | - $invoice = wpinv_cpt_save( $invoice_id ); |
|
| 356 | + $invoice = wpinv_cpt_save($invoice_id); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | return $invoice; |
| 360 | 360 | } |
| 361 | -add_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 ); |
|
| 361 | +add_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4); |
|
| 362 | 362 | |
| 363 | -function wpinv_transaction_details_note( $invoice_id, $html ) { |
|
| 364 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
| 365 | - if ( empty( $invoice_info ) ) { |
|
| 363 | +function wpinv_transaction_details_note($invoice_id, $html) { |
|
| 364 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
| 365 | + if (empty($invoice_info)) { |
|
| 366 | 366 | return false; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - $wpi_invoice_id = !empty( $invoice_info->invoice_id ) ? $invoice_info->invoice_id : NULL; |
|
| 369 | + $wpi_invoice_id = !empty($invoice_info->invoice_id) ? $invoice_info->invoice_id : NULL; |
|
| 370 | 370 | |
| 371 | - if ( !$wpi_invoice_id ) { |
|
| 372 | - $invoice = wpinv_cpt_save( $invoice_id, false, $old_status ); |
|
| 371 | + if (!$wpi_invoice_id) { |
|
| 372 | + $invoice = wpinv_cpt_save($invoice_id, false, $old_status); |
|
| 373 | 373 | |
| 374 | - if ( !empty( $invoice ) ) { |
|
| 374 | + if (!empty($invoice)) { |
|
| 375 | 375 | $wpi_invoice_id = $invoice->ID; |
| 376 | 376 | } |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - $invoice = wpinv_get_invoice( $wpi_invoice_id ); |
|
| 379 | + $invoice = wpinv_get_invoice($wpi_invoice_id); |
|
| 380 | 380 | |
| 381 | - if ( empty( $invoice ) ) { |
|
| 381 | + if (empty($invoice)) { |
|
| 382 | 382 | return false; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - return $invoice->add_note( $html, true ); |
|
| 385 | + return $invoice->add_note($html, true); |
|
| 386 | 386 | } |
| 387 | -add_action( 'geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2 ); |
|
| 387 | +add_action('geodir_payment_invoice_transaction_details_changed', 'wpinv_transaction_details_note', 11, 2); |
|
| 388 | 388 | |
| 389 | -function wpinv_gdp_to_wpi_status( $status ) { |
|
| 389 | +function wpinv_gdp_to_wpi_status($status) { |
|
| 390 | 390 | $inv_status = $status ? $status : 'wpi-pending'; |
| 391 | 391 | |
| 392 | - switch ( $status ) { |
|
| 392 | + switch ($status) { |
|
| 393 | 393 | case 'pending': |
| 394 | 394 | $inv_status = 'wpi-pending'; |
| 395 | 395 | break; |
@@ -412,10 +412,10 @@ discard block |
||
| 412 | 412 | return $inv_status; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | -function wpinv_wpi_to_gdp_status( $status ) { |
|
| 415 | +function wpinv_wpi_to_gdp_status($status) { |
|
| 416 | 416 | $inv_status = $status ? $status : 'pending'; |
| 417 | 417 | |
| 418 | - switch ( $status ) { |
|
| 418 | + switch ($status) { |
|
| 419 | 419 | case 'wpi-pending': |
| 420 | 420 | $inv_status = 'pending'; |
| 421 | 421 | break; |
@@ -441,72 +441,72 @@ discard block |
||
| 441 | 441 | return $inv_status; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | -function wpinv_wpi_to_gdp_id( $invoice_id ) { |
|
| 444 | +function wpinv_wpi_to_gdp_id($invoice_id) { |
|
| 445 | 445 | global $wpdb; |
| 446 | 446 | |
| 447 | - return $wpdb->get_var( $wpdb->prepare( "SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array( (int)$invoice_id ) ) ); |
|
| 447 | + return $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . INVOICE_TABLE . "` WHERE `invoice_id` = %d AND `invoice_id` > 0 ORDER BY id DESC LIMIT 1", array((int)$invoice_id))); |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | -function wpinv_gdp_to_wpi_id( $invoice_id ) { |
|
| 451 | - $invoice = geodir_get_invoice( $invoice_id ); |
|
| 452 | - return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false); |
|
| 450 | +function wpinv_gdp_to_wpi_id($invoice_id) { |
|
| 451 | + $invoice = geodir_get_invoice($invoice_id); |
|
| 452 | + return (empty($invoice->invoice_id) ? $invoice->invoice_id : false); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | -function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) { |
|
| 455 | +function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) { |
|
| 456 | 456 | global $wpdb; |
| 457 | 457 | |
| 458 | - if ( !empty( $wpi_nosave ) ) { |
|
| 458 | + if (!empty($wpi_nosave)) { |
|
| 459 | 459 | return; |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | - $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID ); |
|
| 462 | + $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID); |
|
| 463 | 463 | |
| 464 | - if ( $gdp_invoice_id > 0 ) { |
|
| 464 | + if ($gdp_invoice_id > 0) { |
|
| 465 | 465 | $update_data = array(); |
| 466 | 466 | $update_data['tax_amount'] = $invoice->tax; |
| 467 | 467 | $update_data['paied_amount'] = $invoice->total; |
| 468 | 468 | $update_data['discount'] = $invoice->discount; |
| 469 | 469 | $update_data['coupon_code'] = $invoice->discount_code; |
| 470 | 470 | |
| 471 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) ); |
|
| 471 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id)); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | return; |
| 475 | 475 | } |
| 476 | 476 | //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 ); |
| 477 | 477 | |
| 478 | -function wpinv_gdp_to_wpi_invoice( $invoice_id ) { |
|
| 479 | - $invoice = geodir_get_invoice( $invoice_id ); |
|
| 480 | - if ( empty( $invoice->invoice_id ) ) { |
|
| 478 | +function wpinv_gdp_to_wpi_invoice($invoice_id) { |
|
| 479 | + $invoice = geodir_get_invoice($invoice_id); |
|
| 480 | + if (empty($invoice->invoice_id)) { |
|
| 481 | 481 | return false; |
| 482 | 482 | } |
| 483 | 483 | |
| 484 | - return wpinv_get_invoice( $invoice->invoice_id ); |
|
| 484 | + return wpinv_get_invoice($invoice->invoice_id); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | -function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) { |
|
| 488 | - $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id ); |
|
| 489 | - if ( empty( $invoice ) ) { |
|
| 487 | +function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) { |
|
| 488 | + $invoice = wpinv_gdp_to_wpi_invoice($invoice_id); |
|
| 489 | + if (empty($invoice)) { |
|
| 490 | 490 | return $status; |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | - if ( $status === 1 || $status === 0 ) { |
|
| 494 | - if ( $status === 1 ) { |
|
| 495 | - $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() ); |
|
| 493 | + if ($status === 1 || $status === 0) { |
|
| 494 | + if ($status === 1) { |
|
| 495 | + $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal()); |
|
| 496 | 496 | } else { |
| 497 | 497 | $discount = ''; |
| 498 | 498 | $coupon_code = ''; |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | - $invoice->set( 'discount', $discount ); |
|
| 502 | - $invoice->set( 'discount_code', $coupon_code ); |
|
| 501 | + $invoice->set('discount', $discount); |
|
| 502 | + $invoice->set('discount_code', $coupon_code); |
|
| 503 | 503 | $invoice->save(); |
| 504 | 504 | $invoice->recalculate_total(); |
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | return $status; |
| 508 | 508 | } |
| 509 | -add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 ); |
|
| 509 | +add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3); |
|
| 510 | 510 | |
| 511 | 511 | function wpinv_merge_gd_invoices() { |
| 512 | 512 | if (!defined('GEODIRPAYMENT_VERSION')) { |
@@ -514,157 +514,157 @@ discard block |
||
| 514 | 514 | } |
| 515 | 515 | ?> |
| 516 | 516 | <tr> |
| 517 | - <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td> |
|
| 518 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td> |
|
| 519 | - <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
| 517 | + <td><?php _e('Merge Price Packages', 'invoicing'); ?></td> |
|
| 518 | + <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td> |
|
| 519 | + <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
| 520 | 520 | </tr> |
| 521 | 521 | <tr> |
| 522 | - <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td> |
|
| 523 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td> |
|
| 524 | - <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
| 522 | + <td><?php _e('Merge Invoices', 'invoicing'); ?></td> |
|
| 523 | + <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td> |
|
| 524 | + <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
| 525 | 525 | </tr> |
| 526 | 526 | <tr> |
| 527 | - <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td> |
|
| 528 | - <td><p><?php _e( 'Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing' ); ?></p></td> |
|
| 529 | - <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
| 527 | + <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td> |
|
| 528 | + <td><p><?php _e('Fix taxes for NON-PAID invoices which are merged before, from GeoDirectory Payment Manager invoices to Invoicing. This will recalculate taxes for non-paid merged invoices.', 'invoicing'); ?></p></td> |
|
| 529 | + <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
| 530 | 530 | </tr> |
| 531 | 531 | <tr> |
| 532 | - <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td> |
|
| 533 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td> |
|
| 534 | - <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
| 532 | + <td><?php _e('Merge Coupons', 'invoicing'); ?></td> |
|
| 533 | + <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td> |
|
| 534 | + <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
| 535 | 535 | </tr> |
| 536 | 536 | <?php |
| 537 | 537 | } |
| 538 | -add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 ); |
|
| 538 | +add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10); |
|
| 539 | 539 | |
| 540 | 540 | function wpinv_tool_merge_packages() { |
| 541 | 541 | $packages = geodir_package_list_info(); |
| 542 | 542 | |
| 543 | 543 | $count = 0; |
| 544 | 544 | |
| 545 | - if ( !empty( $packages ) ) { |
|
| 545 | + if (!empty($packages)) { |
|
| 546 | 546 | $success = true; |
| 547 | 547 | |
| 548 | - foreach ( $packages as $key => $package ) { |
|
| 548 | + foreach ($packages as $key => $package) { |
|
| 549 | 549 | $item = wpinv_get_item_by('custom_id', $package->pid, 'package'); |
| 550 | - if ( !empty( $item ) ) { |
|
| 550 | + if (!empty($item)) { |
|
| 551 | 551 | continue; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package ); |
|
| 554 | + $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package); |
|
| 555 | 555 | |
| 556 | - if ( !empty( $merged ) ) { |
|
| 557 | - wpinv_error_log( 'Package merge S : ' . $package->pid ); |
|
| 556 | + if (!empty($merged)) { |
|
| 557 | + wpinv_error_log('Package merge S : ' . $package->pid); |
|
| 558 | 558 | $count++; |
| 559 | 559 | } else { |
| 560 | - wpinv_error_log( 'Package merge F : ' . $package->pid ); |
|
| 560 | + wpinv_error_log('Package merge F : ' . $package->pid); |
|
| 561 | 561 | } |
| 562 | 562 | } |
| 563 | 563 | |
| 564 | - if ( $count > 0 ) { |
|
| 565 | - $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count ); |
|
| 564 | + if ($count > 0) { |
|
| 565 | + $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count); |
|
| 566 | 566 | } else { |
| 567 | - $message = __( 'No price packages merged.', 'invoicing' ); |
|
| 567 | + $message = __('No price packages merged.', 'invoicing'); |
|
| 568 | 568 | } |
| 569 | 569 | } else { |
| 570 | 570 | $success = false; |
| 571 | - $message = __( 'No price packages found to merge!', 'invoicing' ); |
|
| 571 | + $message = __('No price packages found to merge!', 'invoicing'); |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | $response = array(); |
| 575 | 575 | $response['success'] = $success; |
| 576 | 576 | $response['data']['message'] = $message; |
| 577 | - wp_send_json( $response ); |
|
| 577 | + wp_send_json($response); |
|
| 578 | 578 | } |
| 579 | -add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' ); |
|
| 579 | +add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages'); |
|
| 580 | 580 | |
| 581 | 581 | function wpinv_tool_merge_invoices() { |
| 582 | 582 | global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates; |
| 583 | 583 | |
| 584 | 584 | $sql = "SELECT `gdi`.`id`, `gdi`.`date`, `gdi`.`date_updated` FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NULL ORDER BY `gdi`.`id` ASC"; |
| 585 | 585 | |
| 586 | - $items = $wpdb->get_results( $sql ); |
|
| 586 | + $items = $wpdb->get_results($sql); |
|
| 587 | 587 | |
| 588 | 588 | $count = 0; |
| 589 | 589 | |
| 590 | - if ( !empty( $items ) ) { |
|
| 590 | + if (!empty($items)) { |
|
| 591 | 591 | $success = true; |
| 592 | 592 | $wpi_gdp_inv_merge = true; |
| 593 | 593 | |
| 594 | - foreach ( $items as $item ) { |
|
| 594 | + foreach ($items as $item) { |
|
| 595 | 595 | $wpi_tax_rates = NULL; |
| 596 | 596 | |
| 597 | - $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" ); |
|
| 597 | + $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'"); |
|
| 598 | 598 | |
| 599 | - $merged = wpinv_cpt_save( $item->id ); |
|
| 599 | + $merged = wpinv_cpt_save($item->id); |
|
| 600 | 600 | |
| 601 | - if ( !empty( $merged ) && !empty( $merged->ID ) ) { |
|
| 601 | + if (!empty($merged) && !empty($merged->ID)) { |
|
| 602 | 602 | $count++; |
| 603 | 603 | |
| 604 | - $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' ); |
|
| 605 | - $post_date_gmt = get_gmt_from_date( $post_date ); |
|
| 606 | - $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date; |
|
| 607 | - $post_modified_gmt = get_gmt_from_date( $post_modified ); |
|
| 604 | + $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql'); |
|
| 605 | + $post_date_gmt = get_gmt_from_date($post_date); |
|
| 606 | + $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date; |
|
| 607 | + $post_modified_gmt = get_gmt_from_date($post_modified); |
|
| 608 | 608 | |
| 609 | - $wpdb->update( $wpdb->posts, array( 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt ), array( 'ID' => $merged->ID ) ); |
|
| 609 | + $wpdb->update($wpdb->posts, array('post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_modified' => $post_modified, 'post_modified_gmt' => $post_modified_gmt), array('ID' => $merged->ID)); |
|
| 610 | 610 | |
| 611 | - if ( $merged->is_paid() ) { |
|
| 612 | - update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified ); |
|
| 611 | + if ($merged->is_paid()) { |
|
| 612 | + update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified); |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - clean_post_cache( $merged->ID ); |
|
| 615 | + clean_post_cache($merged->ID); |
|
| 616 | 616 | |
| 617 | - wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID ); |
|
| 617 | + wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID); |
|
| 618 | 618 | } else { |
| 619 | - wpinv_error_log( 'Invoice merge F : ' . $item->id ); |
|
| 619 | + wpinv_error_log('Invoice merge F : ' . $item->id); |
|
| 620 | 620 | } |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | $wpi_gdp_inv_merge = false; |
| 624 | 624 | |
| 625 | - if ( $count > 0 ) { |
|
| 626 | - $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count ); |
|
| 625 | + if ($count > 0) { |
|
| 626 | + $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count); |
|
| 627 | 627 | } else { |
| 628 | - $message = __( 'No invoices merged.', 'invoicing' ); |
|
| 628 | + $message = __('No invoices merged.', 'invoicing'); |
|
| 629 | 629 | } |
| 630 | 630 | } else { |
| 631 | 631 | $success = false; |
| 632 | - $message = __( 'No invoices found to merge!', 'invoicing' ); |
|
| 632 | + $message = __('No invoices found to merge!', 'invoicing'); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | $response = array(); |
| 636 | 636 | $response['success'] = $success; |
| 637 | 637 | $response['data']['message'] = $message; |
| 638 | - wp_send_json( $response ); |
|
| 638 | + wp_send_json($response); |
|
| 639 | 639 | } |
| 640 | -add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' ); |
|
| 640 | +add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices'); |
|
| 641 | 641 | |
| 642 | 642 | function wpinv_tool_merge_coupons() { |
| 643 | 643 | global $wpdb; |
| 644 | 644 | |
| 645 | 645 | $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC"; |
| 646 | - $items = $wpdb->get_results( $sql ); |
|
| 646 | + $items = $wpdb->get_results($sql); |
|
| 647 | 647 | $count = 0; |
| 648 | 648 | |
| 649 | - if ( !empty( $items ) ) { |
|
| 649 | + if (!empty($items)) { |
|
| 650 | 650 | $success = true; |
| 651 | 651 | |
| 652 | - foreach ( $items as $item ) { |
|
| 653 | - if ( wpinv_get_discount_by_code( $item->coupon_code ) ) { |
|
| 652 | + foreach ($items as $item) { |
|
| 653 | + if (wpinv_get_discount_by_code($item->coupon_code)) { |
|
| 654 | 654 | continue; |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | $args = array( |
| 658 | 658 | 'post_type' => 'wpi_discount', |
| 659 | 659 | 'post_title' => $item->coupon_code, |
| 660 | - 'post_status' => !empty( $item->status ) ? 'publish' : 'pending' |
|
| 660 | + 'post_status' => !empty($item->status) ? 'publish' : 'pending' |
|
| 661 | 661 | ); |
| 662 | 662 | |
| 663 | - $merged = wp_insert_post( $args ); |
|
| 663 | + $merged = wp_insert_post($args); |
|
| 664 | 664 | |
| 665 | 665 | $item_id = $item->cid; |
| 666 | 666 | |
| 667 | - if ( $merged ) { |
|
| 667 | + if ($merged) { |
|
| 668 | 668 | $meta = array( |
| 669 | 669 | 'code' => $item->coupon_code, |
| 670 | 670 | 'type' => $item->discount_type != 'per' ? 'flat' : 'percent', |
@@ -672,65 +672,65 @@ discard block |
||
| 672 | 672 | 'max_uses' => (int)$item->usage_limit, |
| 673 | 673 | 'uses' => (int)$item->usage_count, |
| 674 | 674 | ); |
| 675 | - wpinv_store_discount( $merged, $meta, get_post( $merged ) ); |
|
| 675 | + wpinv_store_discount($merged, $meta, get_post($merged)); |
|
| 676 | 676 | |
| 677 | 677 | $count++; |
| 678 | 678 | |
| 679 | - wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged ); |
|
| 679 | + wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged); |
|
| 680 | 680 | } else { |
| 681 | - wpinv_error_log( 'Coupon merge F : ' . $item_id ); |
|
| 681 | + wpinv_error_log('Coupon merge F : ' . $item_id); |
|
| 682 | 682 | } |
| 683 | 683 | } |
| 684 | 684 | |
| 685 | - if ( $count > 0 ) { |
|
| 686 | - $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count ); |
|
| 685 | + if ($count > 0) { |
|
| 686 | + $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count); |
|
| 687 | 687 | } else { |
| 688 | - $message = __( 'No coupons merged.', 'invoicing' ); |
|
| 688 | + $message = __('No coupons merged.', 'invoicing'); |
|
| 689 | 689 | } |
| 690 | 690 | } else { |
| 691 | 691 | $success = false; |
| 692 | - $message = __( 'No coupons found to merge!', 'invoicing' ); |
|
| 692 | + $message = __('No coupons found to merge!', 'invoicing'); |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | $response = array(); |
| 696 | 696 | $response['success'] = $success; |
| 697 | 697 | $response['data']['message'] = $message; |
| 698 | - wp_send_json( $response ); |
|
| 698 | + wp_send_json($response); |
|
| 699 | 699 | } |
| 700 | -add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' ); |
|
| 700 | +add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons'); |
|
| 701 | 701 | |
| 702 | -function wpinv_gdp_to_wpi_currency( $value, $option = '' ) { |
|
| 702 | +function wpinv_gdp_to_wpi_currency($value, $option = '') { |
|
| 703 | 703 | return wpinv_get_currency(); |
| 704 | 704 | } |
| 705 | -add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 ); |
|
| 705 | +add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2); |
|
| 706 | 706 | |
| 707 | -function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) { |
|
| 707 | +function wpinv_gdp_to_wpi_currency_sign($value, $option = '') { |
|
| 708 | 708 | return wpinv_currency_symbol(); |
| 709 | 709 | } |
| 710 | -add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 ); |
|
| 710 | +add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2); |
|
| 711 | 711 | |
| 712 | -function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) { |
|
| 713 | - if ( !$display ) { |
|
| 714 | - $price = wpinv_round_amount( $amount ); |
|
| 712 | +function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) { |
|
| 713 | + if (!$display) { |
|
| 714 | + $price = wpinv_round_amount($amount); |
|
| 715 | 715 | } else { |
| 716 | - $price = wpinv_price( wpinv_format_amount( $amount ) ); |
|
| 716 | + $price = wpinv_price(wpinv_format_amount($amount)); |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | return $price; |
| 720 | 720 | } |
| 721 | -add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 ); |
|
| 721 | +add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5); |
|
| 722 | 722 | |
| 723 | -function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) { |
|
| 723 | +function wpinv_gdp_to_inv_checkout_redirect($redirect_url) { |
|
| 724 | 724 | $invoice_id = geodir_payment_cart_id(); |
| 725 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
| 726 | - $wpi_invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL; |
|
| 725 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
| 726 | + $wpi_invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL; |
|
| 727 | 727 | |
| 728 | - if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) { |
|
| 729 | - $wpi_invoice_id = wpinv_cpt_save( $invoice_id ); |
|
| 730 | - $wpi_invoice = wpinv_get_invoice( $wpi_invoice_id ); |
|
| 728 | + if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) { |
|
| 729 | + $wpi_invoice_id = wpinv_cpt_save($invoice_id); |
|
| 730 | + $wpi_invoice = wpinv_get_invoice($wpi_invoice_id); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | - if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) { |
|
| 733 | + if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) { |
|
| 734 | 734 | |
| 735 | 735 | // Clear cart |
| 736 | 736 | geodir_payment_clear_cart(); |
@@ -740,121 +740,121 @@ discard block |
||
| 740 | 740 | |
| 741 | 741 | return $redirect_url; |
| 742 | 742 | } |
| 743 | -add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 ); |
|
| 743 | +add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1); |
|
| 744 | 744 | |
| 745 | -function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) { |
|
| 746 | - if ( get_current_user_id() ) { |
|
| 747 | - $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url( wpinv_get_history_page_uri() ) . '">' . __( 'My Invoice History', 'invoicing' ) . '</a></li>'; |
|
| 745 | +function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) { |
|
| 746 | + if (get_current_user_id()) { |
|
| 747 | + $dashboard_links .= '<li><i class="fa fa-shopping-cart"></i><a class="gd-invoice-link" href="' . esc_url(wpinv_get_history_page_uri()) . '">' . __('My Invoice History', 'invoicing') . '</a></li>'; |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | return $dashboard_links; |
| 751 | 751 | } |
| 752 | -add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' ); |
|
| 753 | -remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' ); |
|
| 752 | +add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link'); |
|
| 753 | +remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link'); |
|
| 754 | 754 | |
| 755 | -function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) { |
|
| 755 | +function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) { |
|
| 756 | 756 | if (!defined('GEODIRPAYMENT_VERSION')) { |
| 757 | 757 | return false; |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
| 761 | - if ( empty( $invoice ) ) { |
|
| 760 | + $invoice = wpinv_get_invoice($invoice_id); |
|
| 761 | + if (empty($invoice)) { |
|
| 762 | 762 | return false; |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | - remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 ); |
|
| 765 | + remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4); |
|
| 766 | 766 | |
| 767 | - $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id ); |
|
| 768 | - $new_status = wpinv_wpi_to_gdp_status( $new_status ); |
|
| 767 | + $invoice_id = wpinv_wpi_to_gdp_id($invoice_id); |
|
| 768 | + $new_status = wpinv_wpi_to_gdp_status($new_status); |
|
| 769 | 769 | |
| 770 | - geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() ); |
|
| 770 | + geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring()); |
|
| 771 | 771 | } |
| 772 | -add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 ); |
|
| 772 | +add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3); |
|
| 773 | 773 | |
| 774 | -function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) { |
|
| 775 | - $item = wpinv_get_item_by( 'custom_id', $gd_package_id, 'package' ); |
|
| 774 | +function wpinv_gdp_to_wpi_delete_package($gd_package_id) { |
|
| 775 | + $item = wpinv_get_item_by('custom_id', $gd_package_id, 'package'); |
|
| 776 | 776 | |
| 777 | - if ( !empty( $item ) ) { |
|
| 778 | - wpinv_remove_item( $item, true ); |
|
| 777 | + if (!empty($item)) { |
|
| 778 | + wpinv_remove_item($item, true); |
|
| 779 | 779 | } |
| 780 | 780 | } |
| 781 | -add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ; |
|
| 781 | +add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1); |
|
| 782 | 782 | |
| 783 | -function wpinv_can_delete_package_item( $return, $post_id ) { |
|
| 784 | - if ( $return && function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && $package_id = get_post_meta( $post_id, '_wpinv_custom_id', true ) ) { |
|
| 785 | - $gd_package = geodir_get_package_info_by_id( $package_id, '' ); |
|
| 783 | +function wpinv_can_delete_package_item($return, $post_id) { |
|
| 784 | + if ($return && function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && $package_id = get_post_meta($post_id, '_wpinv_custom_id', true)) { |
|
| 785 | + $gd_package = geodir_get_package_info_by_id($package_id, ''); |
|
| 786 | 786 | |
| 787 | - if ( !empty( $gd_package ) ) { |
|
| 787 | + if (!empty($gd_package)) { |
|
| 788 | 788 | $return = false; |
| 789 | 789 | } |
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | return $return; |
| 793 | 793 | } |
| 794 | -add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 ); |
|
| 794 | +add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2); |
|
| 795 | 795 | |
| 796 | -function wpinv_package_item_classes( $classes, $class, $post_id ) { |
|
| 796 | +function wpinv_package_item_classes($classes, $class, $post_id) { |
|
| 797 | 797 | global $typenow; |
| 798 | 798 | |
| 799 | - if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) { |
|
| 800 | - if ( wpinv_item_in_use( $post_id ) ) { |
|
| 799 | + if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) { |
|
| 800 | + if (wpinv_item_in_use($post_id)) { |
|
| 801 | 801 | $classes[] = 'wpi-inuse-pkg'; |
| 802 | - } else if ( !( function_exists( 'geodir_get_package_info_by_id' ) && get_post_meta( $post_id, '_wpinv_type', true ) == 'package' && geodir_get_package_info_by_id( (int)get_post_meta( $post_id, '_wpinv_custom_id', true ), '' ) ) ) { |
|
| 802 | + } else if (!(function_exists('geodir_get_package_info_by_id') && get_post_meta($post_id, '_wpinv_type', true) == 'package' && geodir_get_package_info_by_id((int)get_post_meta($post_id, '_wpinv_custom_id', true), ''))) { |
|
| 803 | 803 | $classes[] = 'wpi-delete-pkg'; |
| 804 | 804 | } |
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | return $classes; |
| 808 | 808 | } |
| 809 | -add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 ); |
|
| 809 | +add_filter('post_class', 'wpinv_package_item_classes', 10, 3); |
|
| 810 | 810 | |
| 811 | -function wpinv_gdp_package_type_info( $post ) { |
|
| 812 | - if ( wpinv_pm_active() ) { |
|
| 813 | - ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p> |
|
| 811 | +function wpinv_gdp_package_type_info($post) { |
|
| 812 | + if (wpinv_pm_active()) { |
|
| 813 | + ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p> |
|
| 814 | 814 | <?php |
| 815 | 815 | } |
| 816 | 816 | } |
| 817 | -add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ; |
|
| 817 | +add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1); |
|
| 818 | 818 | |
| 819 | -function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) { |
|
| 819 | +function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) { |
|
| 820 | 820 | global $wpi_zero_tax; |
| 821 | 821 | |
| 822 | - if ( $wpi_zero_tax ) { |
|
| 822 | + if ($wpi_zero_tax) { |
|
| 823 | 823 | $is_taxable = false; |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | return $is_taxable; |
| 827 | 827 | } |
| 828 | -add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ; |
|
| 828 | +add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4); |
|
| 829 | 829 | |
| 830 | 830 | function wpinv_tool_merge_fix_taxes() { |
| 831 | 831 | global $wpdb; |
| 832 | 832 | |
| 833 | 833 | $sql = "SELECT DISTINCT p.ID FROM `" . $wpdb->posts . "` AS p LEFT JOIN " . $wpdb->postmeta . " AS pm ON pm.post_id = p.ID WHERE p.post_type = 'wpi_item' AND pm.meta_key = '_wpinv_type' AND pm.meta_value = 'package'"; |
| 834 | - $items = $wpdb->get_results( $sql ); |
|
| 834 | + $items = $wpdb->get_results($sql); |
|
| 835 | 835 | |
| 836 | - if ( !empty( $items ) ) { |
|
| 837 | - foreach ( $items as $item ) { |
|
| 838 | - if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) { |
|
| 839 | - update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' ); |
|
| 836 | + if (!empty($items)) { |
|
| 837 | + foreach ($items as $item) { |
|
| 838 | + if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') { |
|
| 839 | + update_post_meta($item->ID, '_wpinv_vat_class', '_standard'); |
|
| 840 | 840 | } |
| 841 | 841 | } |
| 842 | 842 | } |
| 843 | 843 | |
| 844 | 844 | $sql = "SELECT `p`.`ID`, gdi.id AS gdp_id FROM `" . INVOICE_TABLE . "` AS gdi LEFT JOIN `" . $wpdb->posts . "` AS p ON `p`.`ID` = `gdi`.`invoice_id` AND `p`.`post_type` = 'wpi_invoice' WHERE `p`.`ID` IS NOT NULL AND p.post_status NOT IN( 'publish', 'wpi-processing', 'wpi-renewal' ) ORDER BY `gdi`.`id` ASC"; |
| 845 | - $items = $wpdb->get_results( $sql ); |
|
| 845 | + $items = $wpdb->get_results($sql); |
|
| 846 | 846 | |
| 847 | - if ( !empty( $items ) ) { |
|
| 847 | + if (!empty($items)) { |
|
| 848 | 848 | $success = false; |
| 849 | - $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' ); |
|
| 849 | + $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing'); |
|
| 850 | 850 | |
| 851 | 851 | global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates; |
| 852 | 852 | |
| 853 | - foreach ( $items as $item ) { |
|
| 853 | + foreach ($items as $item) { |
|
| 854 | 854 | $wpi_tax_rates = NULL; |
| 855 | 855 | $data = wpinv_get_invoice($item->ID); |
| 856 | 856 | |
| 857 | - if ( empty( $data ) ) { |
|
| 857 | + if (empty($data)) { |
|
| 858 | 858 | continue; |
| 859 | 859 | } |
| 860 | 860 | |
@@ -862,51 +862,51 @@ discard block |
||
| 862 | 862 | |
| 863 | 863 | $data_session = array(); |
| 864 | 864 | $data_session['invoice_id'] = $data->ID; |
| 865 | - $data_session['cart_discounts'] = $data->get_discounts( true ); |
|
| 865 | + $data_session['cart_discounts'] = $data->get_discounts(true); |
|
| 866 | 866 | |
| 867 | - wpinv_set_checkout_session( $data_session ); |
|
| 867 | + wpinv_set_checkout_session($data_session); |
|
| 868 | 868 | |
| 869 | 869 | $wpi_userID = (int)$data->get_user_id(); |
| 870 | 870 | $_POST['country'] = !empty($data->country) ? $data->country : wpinv_get_default_country(); |
| 871 | 871 | |
| 872 | - $data->country = sanitize_text_field( $_POST['country'] ); |
|
| 873 | - $data->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
| 872 | + $data->country = sanitize_text_field($_POST['country']); |
|
| 873 | + $data->set('country', sanitize_text_field($_POST['country'])); |
|
| 874 | 874 | |
| 875 | 875 | $wpinv_ip_address_country = $data->country; |
| 876 | 876 | |
| 877 | 877 | $data->recalculate_totals(true); |
| 878 | 878 | |
| 879 | - wpinv_set_checkout_session( $checkout_session ); |
|
| 879 | + wpinv_set_checkout_session($checkout_session); |
|
| 880 | 880 | |
| 881 | 881 | $update_data = array(); |
| 882 | 882 | $update_data['tax_amount'] = $data->get_tax(); |
| 883 | 883 | $update_data['paied_amount'] = $data->get_total(); |
| 884 | 884 | $update_data['invoice_id'] = $data->ID; |
| 885 | 885 | |
| 886 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) ); |
|
| 886 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id)); |
|
| 887 | 887 | } |
| 888 | 888 | } else { |
| 889 | 889 | $success = false; |
| 890 | - $message = __( 'No invoices found to fix taxes!', 'invoicing' ); |
|
| 890 | + $message = __('No invoices found to fix taxes!', 'invoicing'); |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | $response = array(); |
| 894 | 894 | $response['success'] = $success; |
| 895 | 895 | $response['data']['message'] = $message; |
| 896 | - wp_send_json( $response ); |
|
| 896 | + wp_send_json($response); |
|
| 897 | 897 | } |
| 898 | -add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' ); |
|
| 899 | -remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 ); |
|
| 898 | +add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes'); |
|
| 899 | +remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2); |
|
| 900 | 900 | |
| 901 | -function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) { |
|
| 902 | - if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) { |
|
| 903 | - if ( $invoice->is_renewal() ) { |
|
| 901 | +function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) { |
|
| 902 | + if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) { |
|
| 903 | + if ($invoice->is_renewal()) { |
|
| 904 | 904 | $invoice = $invoice->get_parent_payment(); |
| 905 | 905 | } |
| 906 | 906 | |
| 907 | - if ( !empty( $invoice ) ) { |
|
| 908 | - wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() ); |
|
| 907 | + if (!empty($invoice)) { |
|
| 908 | + wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status()); |
|
| 909 | 909 | } |
| 910 | 910 | } |
| 911 | 911 | } |
| 912 | -add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 ); |
|
| 913 | 912 | \ No newline at end of file |
| 913 | +add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2); |
|
| 914 | 914 | \ 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(); |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | self::$instance->reports = new WPInv_Reports(); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - do_action( 'wpinv_loaded' ); |
|
| 26 | + do_action('wpinv_loaded'); |
|
| 27 | 27 | |
| 28 | 28 | return self::$instance; |
| 29 | 29 | } |
@@ -33,31 +33,31 @@ discard block |
||
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function define_constants() { |
| 36 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
| 37 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
| 36 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
| 37 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | private function actions() { |
| 41 | 41 | /* Internationalize the text strings used. */ |
| 42 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
| 42 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
| 43 | 43 | |
| 44 | 44 | /* Perform actions on admin initialization. */ |
| 45 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
| 46 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
| 47 | - add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) ); |
|
| 48 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
| 45 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
| 46 | + add_action('init', array(&$this, 'init'), 3); |
|
| 47 | + add_action('init', array('WPInv_Shortcodes', 'init')); |
|
| 48 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
| 49 | 49 | |
| 50 | - if ( class_exists( 'BuddyPress' ) ) { |
|
| 51 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
| 50 | + if (class_exists('BuddyPress')) { |
|
| 51 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
| 54 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
| 55 | 55 | |
| 56 | - if ( is_admin() ) { |
|
| 57 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
| 58 | - add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
| 56 | + if (is_admin()) { |
|
| 57 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
| 58 | + add_action('admin_body_class', array(&$this, 'admin_body_class')); |
|
| 59 | 59 | } else { |
| 60 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
| 60 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
| 69 | 69 | */ |
| 70 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
| 70 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
| 71 | 71 | |
| 72 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
| 72 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | public function plugins_loaded() { |
@@ -83,193 +83,193 @@ discard block |
||
| 83 | 83 | * @since 1.0 |
| 84 | 84 | */ |
| 85 | 85 | public function load_textdomain() { |
| 86 | - $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' ); |
|
| 86 | + $locale = apply_filters('plugin_locale', get_locale(), 'invoicing'); |
|
| 87 | 87 | |
| 88 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
| 89 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
| 88 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
| 89 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
| 90 | 90 | |
| 91 | 91 | /** |
| 92 | 92 | * Define language constants. |
| 93 | 93 | */ |
| 94 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
| 94 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | public function includes() { |
| 98 | 98 | global $wpinv_options; |
| 99 | 99 | |
| 100 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
| 100 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
| 101 | 101 | $wpinv_options = wpinv_get_settings(); |
| 102 | 102 | |
| 103 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
| 104 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
| 105 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
| 106 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
| 107 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
| 108 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
| 109 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
| 110 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
| 111 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
| 112 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
| 113 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
| 114 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
| 115 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
| 116 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' ); |
|
| 117 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
| 103 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
| 104 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
| 105 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
| 106 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
| 107 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
| 108 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
| 109 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
| 110 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
| 111 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
| 112 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
| 113 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
| 114 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
| 115 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
| 116 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php'); |
|
| 117 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
| 118 | 118 | //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
| 119 | 119 | //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
| 120 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
| 120 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
| 121 | 121 | //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscription.php' ); |
| 122 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
| 123 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
| 124 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' ); |
|
| 125 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
| 126 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
| 127 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
| 128 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' ); |
|
| 129 | - if ( !class_exists( 'Geodir_EUVat' ) ) { |
|
| 130 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
| 122 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
| 123 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
| 124 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php'); |
|
| 125 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
| 126 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
| 127 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
| 128 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php'); |
|
| 129 | + if (!class_exists('Geodir_EUVat')) { |
|
| 130 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
| 134 | - if ( !empty( $gateways ) ) { |
|
| 135 | - foreach ( $gateways as $gateway ) { |
|
| 136 | - if ( $gateway == 'manual' ) { |
|
| 133 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
| 134 | + if (!empty($gateways)) { |
|
| 135 | + foreach ($gateways as $gateway) { |
|
| 136 | + if ($gateway == 'manual') { |
|
| 137 | 137 | continue; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
| 141 | 141 | |
| 142 | - if ( file_exists( $gateway_file ) ) { |
|
| 143 | - require_once( $gateway_file ); |
|
| 142 | + if (file_exists($gateway_file)) { |
|
| 143 | + require_once($gateway_file); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
| 147 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
| 148 | 148 | |
| 149 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 150 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
| 151 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
| 152 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
| 149 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
| 150 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
| 151 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
| 152 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
| 153 | 153 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
| 154 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
| 155 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
| 156 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
| 157 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
| 158 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
| 154 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
| 155 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
| 156 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
| 157 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
| 158 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
| 159 | 159 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // include css inliner |
| 163 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
| 164 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
| 163 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
| 164 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
| 167 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | public function init() { |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | public function admin_init() { |
| 174 | - if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) { |
|
| 174 | + if (!(defined('DOING_AJAX') && DOING_AJAX)) { |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
| 177 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | public function activation_redirect() { |
| 181 | 181 | // Bail if no activation redirect |
| 182 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
| 182 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
| 183 | 183 | return; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // Delete the redirect transient |
| 187 | - delete_transient( '_wpinv_activation_redirect' ); |
|
| 187 | + delete_transient('_wpinv_activation_redirect'); |
|
| 188 | 188 | |
| 189 | 189 | // Bail if activating from network, or bulk |
| 190 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
| 190 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
| 191 | 191 | return; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
| 194 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
| 195 | 195 | exit; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | public function enqueue_scripts() { |
| 199 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 199 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 200 | 200 | |
| 201 | - wp_deregister_style( 'font-awesome' ); |
|
| 202 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
| 203 | - wp_enqueue_style( 'font-awesome' ); |
|
| 201 | + wp_deregister_style('font-awesome'); |
|
| 202 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
| 203 | + wp_enqueue_style('font-awesome'); |
|
| 204 | 204 | |
| 205 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION ); |
|
| 206 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
| 205 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION); |
|
| 206 | + wp_enqueue_style('wpinv_front_style'); |
|
| 207 | 207 | |
| 208 | 208 | // Register scripts |
| 209 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 210 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ), WPINV_VERSION ); |
|
| 209 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 210 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION); |
|
| 211 | 211 | |
| 212 | 212 | $localize = array(); |
| 213 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 214 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 213 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 214 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 215 | 215 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
| 216 | 216 | $localize['currency_pos'] = wpinv_currency_position(); |
| 217 | 217 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 218 | 218 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 219 | 219 | $localize['decimals'] = wpinv_decimals(); |
| 220 | 220 | |
| 221 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
| 221 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
| 222 | 222 | |
| 223 | - wp_enqueue_script( 'jquery-blockui' ); |
|
| 224 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
| 225 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
| 223 | + wp_enqueue_script('jquery-blockui'); |
|
| 224 | + wp_enqueue_script('wpinv-front-script'); |
|
| 225 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | public function admin_enqueue_scripts() { |
| 229 | 229 | global $post, $pagenow; |
| 230 | 230 | |
| 231 | 231 | $post_type = wpinv_admin_post_type(); |
| 232 | - $suffix = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 232 | + $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
| 233 | 233 | |
| 234 | - wp_deregister_style( 'font-awesome' ); |
|
| 235 | - wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' ); |
|
| 236 | - wp_enqueue_style( 'font-awesome' ); |
|
| 234 | + wp_deregister_style('font-awesome'); |
|
| 235 | + wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0'); |
|
| 236 | + wp_enqueue_style('font-awesome'); |
|
| 237 | 237 | |
| 238 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
| 239 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
| 238 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
| 239 | + wp_enqueue_style('jquery-ui-css'); |
|
| 240 | 240 | |
| 241 | - wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' ); |
|
| 242 | - wp_enqueue_style( 'jquery-chosen' ); |
|
| 241 | + wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2'); |
|
| 242 | + wp_enqueue_style('jquery-chosen'); |
|
| 243 | 243 | |
| 244 | - wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' ); |
|
| 245 | - wp_enqueue_script( 'jquery-chosen' ); |
|
| 244 | + wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2'); |
|
| 245 | + wp_enqueue_script('jquery-chosen'); |
|
| 246 | 246 | |
| 247 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
| 248 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
| 247 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
| 248 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
| 249 | 249 | |
| 250 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION ); |
|
| 251 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
| 250 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION); |
|
| 251 | + wp_enqueue_style('wpinv_admin_style'); |
|
| 252 | 252 | |
| 253 | - if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
| 254 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
| 253 | + if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
| 254 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 258 | - wp_enqueue_script( 'wp-color-picker' ); |
|
| 257 | + wp_enqueue_style('wp-color-picker'); |
|
| 258 | + wp_enqueue_script('wp-color-picker'); |
|
| 259 | 259 | |
| 260 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
| 260 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
| 261 | 261 | |
| 262 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ), WPINV_VERSION ); |
|
| 263 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
| 262 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION); |
|
| 263 | + wp_enqueue_script('wpinv-admin-script'); |
|
| 264 | 264 | |
| 265 | 265 | $localize = array(); |
| 266 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
| 267 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
| 268 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
| 269 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
| 270 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
| 271 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
| 272 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
| 266 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
| 267 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
| 268 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
| 269 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
| 270 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
| 271 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
| 272 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
| 273 | 273 | $localize['tax'] = wpinv_tax_amount(); |
| 274 | 274 | $localize['discount'] = wpinv_discount_amount(); |
| 275 | 275 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -277,61 +277,61 @@ discard block |
||
| 277 | 277 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
| 278 | 278 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
| 279 | 279 | $localize['decimals'] = wpinv_decimals(); |
| 280 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
| 281 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
| 282 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
| 283 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
| 284 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
| 285 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
| 286 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
| 287 | - $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' ); |
|
| 288 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
| 280 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
| 281 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
| 282 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
| 283 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
| 284 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
| 285 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
| 286 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
| 287 | + $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'); |
|
| 288 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
| 289 | 289 | $localize['hasGD'] = wpinv_gd_active(); |
| 290 | 290 | $localize['hasPM'] = wpinv_pm_active(); |
| 291 | - $localize['emptyInvoice'] = __( 'Add atleast one item to save invoice!', 'invoicing' ); |
|
| 292 | - $localize['deletePackage'] = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' ); |
|
| 293 | - $localize['deletePackages'] = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' ); |
|
| 294 | - $localize['deleteInvoiceFirst'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
| 291 | + $localize['emptyInvoice'] = __('Add atleast one item to save invoice!', 'invoicing'); |
|
| 292 | + $localize['deletePackage'] = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing'); |
|
| 293 | + $localize['deletePackages'] = __('GD package items should be deleted from GD payment manager only', 'invoicing'); |
|
| 294 | + $localize['deleteInvoiceFirst'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
| 295 | 295 | |
| 296 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
| 296 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
| 297 | 297 | |
| 298 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
| 298 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - public function admin_body_class( $classes ) { |
|
| 301 | + public function admin_body_class($classes) { |
|
| 302 | 302 | global $pagenow, $post; |
| 303 | 303 | |
| 304 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
| 304 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
| 305 | 305 | |
| 306 | 306 | $add_class = false; |
| 307 | - if ( $pagenow == 'admin.php' && $page ) { |
|
| 308 | - $add_class = strpos( $page, 'wpinv-' ); |
|
| 307 | + if ($pagenow == 'admin.php' && $page) { |
|
| 308 | + $add_class = strpos($page, 'wpinv-'); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | $settings_class = array(); |
| 312 | - if ( $page == 'wpinv-settings' ) { |
|
| 313 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
| 314 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
| 312 | + if ($page == 'wpinv-settings') { |
|
| 313 | + if (!empty($_REQUEST['tab'])) { |
|
| 314 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
| 318 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
| 317 | + if (!empty($_REQUEST['section'])) { |
|
| 318 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
| 321 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | - if ( !empty( $settings_class ) ) { |
|
| 325 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
| 324 | + if (!empty($settings_class)) { |
|
| 325 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | $post_type = wpinv_admin_post_type(); |
| 329 | 329 | |
| 330 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
| 330 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
| 331 | 331 | return $classes .= ' wpinv'; |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
| 334 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
| 335 | 335 | $classes .= ' wpi-editable-n'; |
| 336 | 336 | } |
| 337 | 337 | |
@@ -343,20 +343,20 @@ discard block |
||
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | public function wpinv_actions() { |
| 346 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
| 347 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
| 346 | + if (isset($_REQUEST['wpi_action'])) { |
|
| 347 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - public function pre_get_posts( $wp_query ) { |
|
| 352 | - 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() ) { |
|
| 353 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
| 351 | + public function pre_get_posts($wp_query) { |
|
| 352 | + 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()) { |
|
| 353 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | return $wp_query; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | public function bp_invoicing_init() { |
| 360 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
| 360 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
| 361 | 361 | } |
| 362 | 362 | } |
| 363 | 363 | \ No newline at end of file |