@@ -11,19 +11,19 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | // MUST have WordPress. |
14 | -if ( !defined( 'WPINC' ) ) { |
|
15 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
14 | +if (!defined('WPINC')) { |
|
15 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
16 | 16 | } |
17 | 17 | |
18 | -if ( !defined( 'WPINV_VERSION' ) ) { |
|
19 | - define( 'WPINV_VERSION', '0.0.4' ); |
|
18 | +if (!defined('WPINV_VERSION')) { |
|
19 | + define('WPINV_VERSION', '0.0.4'); |
|
20 | 20 | } |
21 | 21 | |
22 | -if ( !defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
23 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
22 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
23 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
24 | 24 | } |
25 | 25 | |
26 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wpinv.php'; |
|
26 | +require plugin_dir_path(__FILE__) . 'includes/class-wpinv.php'; |
|
27 | 27 | |
28 | 28 | function wpinv_run() { |
29 | 29 | global $invoicing; |
@@ -40,16 +40,16 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * Show update plugin admin notification. |
42 | 42 | */ |
43 | -if(is_admin()){ |
|
43 | +if (is_admin()) { |
|
44 | 44 | if (!function_exists('ayecode_show_update_plugin_requirement')) {//only load the update file if needed |
45 | 45 | function ayecode_show_update_plugin_requirement() { |
46 | - if ( !defined( 'WP_EASY_UPDATES_ACTIVE' ) ) { |
|
46 | + if (!defined('WP_EASY_UPDATES_ACTIVE')) { |
|
47 | 47 | ?> |
48 | 48 | <div class="notice notice-warning is-dismissible"> |
49 | 49 | <p> |
50 | 50 | <strong> |
51 | 51 | <?php |
52 | - echo sprintf( __( 'The plugin %sWP Easy Updates%s is required to check for and update some installed plugins, please install it now.', 'geodirectory' ), '<a href="https://wpeasyupdates.com/" target="_blank" title="WP Easy Updates">', '</a>' ); |
|
52 | + echo sprintf(__('The plugin %sWP Easy Updates%s is required to check for and update some installed plugins, please install it now.', 'geodirectory'), '<a href="https://wpeasyupdates.com/" target="_blank" title="WP Easy Updates">', '</a>'); |
|
53 | 53 | ?> |
54 | 54 | </strong> |
55 | 55 | </p> |
@@ -58,6 +58,6 @@ discard block |
||
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
61 | - add_action( 'admin_notices', 'ayecode_show_update_plugin_requirement' ); |
|
61 | + add_action('admin_notices', 'ayecode_show_update_plugin_requirement'); |
|
62 | 62 | } |
63 | 63 | } |
@@ -1,7 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if ( !defined('ABSPATH') ) { |
|
4 | 4 | die('-1'); |
5 | +} |
|
5 | 6 | |
6 | 7 | do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
7 | 8 |
@@ -1,18 +1,18 @@ |
||
1 | 1 | <?php |
2 | 2 | // don't load directly |
3 | -if ( !defined('ABSPATH') ) |
|
3 | +if (!defined('ABSPATH')) |
|
4 | 4 | die('-1'); |
5 | 5 | |
6 | -do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin ); |
|
6 | +do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin); |
|
7 | 7 | |
8 | -do_action( 'wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note ); |
|
8 | +do_action('wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note); |
|
9 | 9 | |
10 | -do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin ); |
|
10 | +do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin); |
|
11 | 11 | |
12 | -do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin ); |
|
12 | +do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin); |
|
13 | 13 | |
14 | -do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin ); |
|
14 | +do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin); |
|
15 | 15 | |
16 | -do_action( 'wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note ); |
|
16 | +do_action('wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note); |
|
17 | 17 | |
18 | -do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin ); |
|
19 | 18 | \ No newline at end of file |
19 | +do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin); |
|
20 | 20 | \ No newline at end of file |
@@ -1,41 +1,41 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( !defined('ABSPATH') ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | global $post; |
6 | 6 | $invoice_id = $post->ID; |
7 | -$invoice = wpinv_get_invoice( $invoice_id ); |
|
8 | -if ( empty( $invoice ) ) { |
|
7 | +$invoice = wpinv_get_invoice($invoice_id); |
|
8 | +if (empty($invoice)) { |
|
9 | 9 | exit; |
10 | 10 | } |
11 | -$type = $post->post_type == 'wpi_invoice' ? __( 'Invoice', 'invoicing' ): __( 'Quotation', 'invoicing' ); |
|
12 | -do_action( 'wpinv_invoice_print_before_display', $invoice ); ?><!DOCTYPE html> |
|
11 | +$type = $post->post_type == 'wpi_invoice' ? __('Invoice', 'invoicing') : __('Quotation', 'invoicing'); |
|
12 | +do_action('wpinv_invoice_print_before_display', $invoice); ?><!DOCTYPE html> |
|
13 | 13 | <html <?php language_attributes(); ?>> |
14 | 14 | <head> |
15 | 15 | <meta charset="UTF-8"> |
16 | 16 | <title><?php wp_title() ?></title> |
17 | - <meta charset="<?php bloginfo( 'charset' ); ?>" /> |
|
17 | + <meta charset="<?php bloginfo('charset'); ?>" /> |
|
18 | 18 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
19 | 19 | <meta name="robots" content="noindex,nofollow"> |
20 | 20 | |
21 | - <?php do_action( 'wpinv_invoice_print_head', $invoice ); ?> |
|
21 | + <?php do_action('wpinv_invoice_print_head', $invoice); ?> |
|
22 | 22 | </head> |
23 | 23 | <body class="body wpinv wpinv-print"> |
24 | - <?php do_action( 'wpinv_invoice_print_body_start', $invoice ); ?> |
|
24 | + <?php do_action('wpinv_invoice_print_body_start', $invoice); ?> |
|
25 | 25 | <div class="container wpinv-wrap"> |
26 | - <?php if ( $watermark = wpinv_watermark( $invoice_id ) ) { ?> |
|
27 | - <div class="watermark no-print"><p><?php echo esc_html( $watermark ) ?></p></div> |
|
26 | + <?php if ($watermark = wpinv_watermark($invoice_id)) { ?> |
|
27 | + <div class="watermark no-print"><p><?php echo esc_html($watermark) ?></p></div> |
|
28 | 28 | <?php } ?> |
29 | 29 | <!-- ///// Start PDF header --> |
30 | 30 | <htmlpageheader name="wpinv-pdf-header"> |
31 | - <?php do_action( 'wpinv_invoice_print_before_header', $invoice ); ?> |
|
31 | + <?php do_action('wpinv_invoice_print_before_header', $invoice); ?> |
|
32 | 32 | <div class="row wpinv-header"> |
33 | 33 | <div class="col-xs-6 wpinv-business"> |
34 | - <a target="_blank" href="<?php echo esc_url( wpinv_get_business_website() ); ?>"> |
|
35 | - <?php if ( $logo = wpinv_get_business_logo() ) { ?> |
|
36 | - <img class="logo" src="<?php echo esc_url( $logo ); ?>"> |
|
34 | + <a target="_blank" href="<?php echo esc_url(wpinv_get_business_website()); ?>"> |
|
35 | + <?php if ($logo = wpinv_get_business_logo()) { ?> |
|
36 | + <img class="logo" src="<?php echo esc_url($logo); ?>"> |
|
37 | 37 | <?php } else { ?> |
38 | - <h1><?php echo esc_html( wpinv_get_business_name() ); ?></h1> |
|
38 | + <h1><?php echo esc_html(wpinv_get_business_name()); ?></h1> |
|
39 | 39 | <?php } ?> |
40 | 40 | </a> |
41 | 41 | </div> |
@@ -44,56 +44,56 @@ discard block |
||
44 | 44 | <h2><?php echo $type; ?></h2> |
45 | 45 | </div> |
46 | 46 | </div> |
47 | - <?php do_action( 'wpinv_invoice_print_after_header', $invoice ); ?> |
|
47 | + <?php do_action('wpinv_invoice_print_after_header', $invoice); ?> |
|
48 | 48 | </htmlpageheader> |
49 | 49 | <!-- End PDF header ///// --> |
50 | 50 | |
51 | - <?php do_action( 'wpinv_invoice_print_before_top_content', $invoice ); ?> |
|
51 | + <?php do_action('wpinv_invoice_print_before_top_content', $invoice); ?> |
|
52 | 52 | <div class="row wpinv-top-content"> |
53 | 53 | <div class="col-xs-12 col-sm-6 wpinv-addresses"> |
54 | 54 | <div class="col-xs-12 wpinv-address wpinv-from-address"> |
55 | 55 | <?php wpinv_display_from_address(); ?> |
56 | 56 | </div> |
57 | 57 | <div class="col-xs-12 wpinv-address wpinv-to-address"> |
58 | - <?php wpinv_display_to_address( $invoice_id ); ?> |
|
58 | + <?php wpinv_display_to_address($invoice_id); ?> |
|
59 | 59 | </div> |
60 | 60 | </div> |
61 | 61 | <div class="col-xs-12 col-sm-6 wpinv-details"> |
62 | 62 | <div class="col-xs-12 wpinv-line-details"> |
63 | - <?php do_action( 'wpinv_invoice_print_before_details', $invoice ); ?> |
|
64 | - <?php wpinv_display_invoice_details( $invoice ); ?> |
|
65 | - <?php do_action( 'wpinv_invoice_print_after_details', $invoice ); ?> |
|
63 | + <?php do_action('wpinv_invoice_print_before_details', $invoice); ?> |
|
64 | + <?php wpinv_display_invoice_details($invoice); ?> |
|
65 | + <?php do_action('wpinv_invoice_print_after_details', $invoice); ?> |
|
66 | 66 | </div> |
67 | 67 | </div> |
68 | 68 | </div> |
69 | - <?php do_action( 'wpinv_invoice_print_after_top_content', $invoice ); ?> |
|
69 | + <?php do_action('wpinv_invoice_print_after_top_content', $invoice); ?> |
|
70 | 70 | |
71 | - <?php do_action( 'wpinv_invoice_print_middle', $invoice ); ?> |
|
71 | + <?php do_action('wpinv_invoice_print_middle', $invoice); ?> |
|
72 | 72 | |
73 | - <?php do_action( 'wpinv_invoice_print_before_line_items', $invoice ); ?> |
|
73 | + <?php do_action('wpinv_invoice_print_before_line_items', $invoice); ?> |
|
74 | 74 | <div class="row wpinv-items"> |
75 | 75 | <div class="col-sm-12 wpinv-line-items"> |
76 | - <?php wpinv_display_line_items( $invoice_id ); ?> |
|
76 | + <?php wpinv_display_line_items($invoice_id); ?> |
|
77 | 77 | </div> |
78 | 78 | </div> |
79 | - <?php do_action( 'wpinv_invoice_print_after_line_items', $invoice ); ?> |
|
79 | + <?php do_action('wpinv_invoice_print_after_line_items', $invoice); ?> |
|
80 | 80 | |
81 | 81 | <!-- ///// Start PDF footer --> |
82 | 82 | <htmlpagefooter name="wpinv-pdf-footer"> |
83 | - <?php do_action( 'wpinv_invoice_print_before_footer', $invoice ); ?> |
|
83 | + <?php do_action('wpinv_invoice_print_before_footer', $invoice); ?> |
|
84 | 84 | <div class="row wpinv-footer"> |
85 | 85 | <div class="col-sm-12"> |
86 | - <?php if ( $term_text = wpinv_get_terms_text() ) { ?> |
|
87 | - <div class="terms-text"><?php echo wpautop( $term_text ); ?></div> |
|
86 | + <?php if ($term_text = wpinv_get_terms_text()) { ?> |
|
87 | + <div class="terms-text"><?php echo wpautop($term_text); ?></div> |
|
88 | 88 | <?php } ?> |
89 | 89 | <div class="footer-text"><?php echo wpinv_get_business_footer(); ?></div> |
90 | - <div class="print-only"><?php _e( 'Page ', 'invoicing' ) ?> {PAGENO}/{nbpg}</div> |
|
90 | + <div class="print-only"><?php _e('Page ', 'invoicing') ?> {PAGENO}/{nbpg}</div> |
|
91 | 91 | </div> |
92 | 92 | </div> |
93 | - <?php do_action( 'wpinv_invoice_print_after_footer', $invoice ); ?> |
|
93 | + <?php do_action('wpinv_invoice_print_after_footer', $invoice); ?> |
|
94 | 94 | </htmlpagefooter> |
95 | 95 | <!-- End PDF footer ///// --> |
96 | 96 | </div><!-- END wpinv-wrap --> |
97 | - <?php do_action( 'wpinv_invoice_print_body_end', $invoice ); ?> |
|
97 | + <?php do_action('wpinv_invoice_print_body_end', $invoice); ?> |
|
98 | 98 | </body> |
99 | 99 | </html> |
100 | 100 | \ No newline at end of file |
@@ -976,67 +976,67 @@ |
||
976 | 976 | function wpinv_tool_merge_fix_taxes() { |
977 | 977 | global $wpdb; |
978 | 978 | |
979 | - $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'"; |
|
980 | - $items = $wpdb->get_results( $sql ); |
|
979 | + $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'"; |
|
980 | + $items = $wpdb->get_results( $sql ); |
|
981 | 981 | |
982 | - if ( !empty( $items ) ) { |
|
983 | - foreach ( $items as $item ) { |
|
984 | - if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) { |
|
985 | - update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' ); |
|
986 | - } |
|
987 | - } |
|
988 | - } |
|
982 | + if ( !empty( $items ) ) { |
|
983 | + foreach ( $items as $item ) { |
|
984 | + if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) { |
|
985 | + update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' ); |
|
986 | + } |
|
987 | + } |
|
988 | + } |
|
989 | 989 | |
990 | 990 | $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"; |
991 | 991 | $items = $wpdb->get_results( $sql ); |
992 | 992 | |
993 | - if ( !empty( $items ) ) { |
|
994 | - $success = false; |
|
993 | + if ( !empty( $items ) ) { |
|
994 | + $success = false; |
|
995 | 995 | $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' ); |
996 | 996 | |
997 | - global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates; |
|
997 | + global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates; |
|
998 | 998 | |
999 | - foreach ( $items as $item ) { |
|
1000 | - $wpi_tax_rates = NULL; |
|
1001 | - $data = wpinv_get_invoice($item->ID); |
|
999 | + foreach ( $items as $item ) { |
|
1000 | + $wpi_tax_rates = NULL; |
|
1001 | + $data = wpinv_get_invoice($item->ID); |
|
1002 | 1002 | |
1003 | - if ( empty( $data ) ) { |
|
1004 | - continue; |
|
1005 | - } |
|
1003 | + if ( empty( $data ) ) { |
|
1004 | + continue; |
|
1005 | + } |
|
1006 | 1006 | |
1007 | - $checkout_session = wpinv_get_checkout_session(); |
|
1007 | + $checkout_session = wpinv_get_checkout_session(); |
|
1008 | 1008 | |
1009 | - $data_session = array(); |
|
1010 | - $data_session['invoice_id'] = $data->ID; |
|
1011 | - $data_session['cart_discounts'] = $data->get_discounts( true ); |
|
1009 | + $data_session = array(); |
|
1010 | + $data_session['invoice_id'] = $data->ID; |
|
1011 | + $data_session['cart_discounts'] = $data->get_discounts( true ); |
|
1012 | 1012 | |
1013 | - wpinv_set_checkout_session( $data_session ); |
|
1013 | + wpinv_set_checkout_session( $data_session ); |
|
1014 | 1014 | |
1015 | - $wpi_userID = (int)$data->get_user_id(); |
|
1016 | - $_POST['country'] = !empty($data->country) ? $data->country : wpinv_get_default_country(); |
|
1015 | + $wpi_userID = (int)$data->get_user_id(); |
|
1016 | + $_POST['country'] = !empty($data->country) ? $data->country : wpinv_get_default_country(); |
|
1017 | 1017 | |
1018 | - $data->country = sanitize_text_field( $_POST['country'] ); |
|
1019 | - $data->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
1018 | + $data->country = sanitize_text_field( $_POST['country'] ); |
|
1019 | + $data->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
1020 | 1020 | |
1021 | - $wpinv_ip_address_country = $data->country; |
|
1021 | + $wpinv_ip_address_country = $data->country; |
|
1022 | 1022 | |
1023 | - $data->recalculate_totals(true); |
|
1023 | + $data->recalculate_totals(true); |
|
1024 | 1024 | |
1025 | - wpinv_set_checkout_session( $checkout_session ); |
|
1025 | + wpinv_set_checkout_session( $checkout_session ); |
|
1026 | 1026 | |
1027 | - $update_data = array(); |
|
1028 | - $update_data['tax_amount'] = $data->get_tax(); |
|
1029 | - $update_data['paied_amount'] = $data->get_total(); |
|
1030 | - $update_data['invoice_id'] = $data->ID; |
|
1027 | + $update_data = array(); |
|
1028 | + $update_data['tax_amount'] = $data->get_tax(); |
|
1029 | + $update_data['paied_amount'] = $data->get_total(); |
|
1030 | + $update_data['invoice_id'] = $data->ID; |
|
1031 | 1031 | |
1032 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) ); |
|
1033 | - } |
|
1034 | - } else { |
|
1032 | + $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) ); |
|
1033 | + } |
|
1034 | + } else { |
|
1035 | 1035 | $success = false; |
1036 | 1036 | $message = __( 'No invoices found to fix taxes!', 'invoicing' ); |
1037 | 1037 | } |
1038 | 1038 | |
1039 | - $response = array(); |
|
1039 | + $response = array(); |
|
1040 | 1040 | $response['success'] = $success; |
1041 | 1041 | $response['data']['message'] = $message; |
1042 | 1042 | wp_send_json( $response ); |
@@ -740,6 +740,9 @@ |
||
740 | 740 | add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' ); |
741 | 741 | remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' ); |
742 | 742 | |
743 | +/** |
|
744 | + * @param string $new_status |
|
745 | + */ |
|
743 | 746 | function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) { |
744 | 747 | if (!defined('GEODIRPAYMENT_VERSION')) { |
745 | 748 | return false; |
@@ -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 = '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 = '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 : 'pending'; |
391 | 391 | |
392 | - switch ( $status ) { |
|
392 | + switch ($status) { |
|
393 | 393 | case 'confirmed': |
394 | 394 | $inv_status = 'publish'; |
395 | 395 | break; |
@@ -409,10 +409,10 @@ discard block |
||
409 | 409 | return $inv_status; |
410 | 410 | } |
411 | 411 | |
412 | -function wpinv_wpi_to_gdp_status( $status ) { |
|
412 | +function wpinv_wpi_to_gdp_status($status) { |
|
413 | 413 | $inv_status = $status ? $status : 'pending'; |
414 | 414 | |
415 | - switch ( $status ) { |
|
415 | + switch ($status) { |
|
416 | 416 | case 'publish': |
417 | 417 | case 'wpi-processing': |
418 | 418 | case 'wpi-renewal': |
@@ -435,72 +435,72 @@ discard block |
||
435 | 435 | return $inv_status; |
436 | 436 | } |
437 | 437 | |
438 | -function wpinv_wpi_to_gdp_id( $invoice_id ) { |
|
438 | +function wpinv_wpi_to_gdp_id($invoice_id) { |
|
439 | 439 | global $wpdb; |
440 | 440 | |
441 | - 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 ) ) ); |
|
441 | + 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))); |
|
442 | 442 | } |
443 | 443 | |
444 | -function wpinv_gdp_to_wpi_id( $invoice_id ) { |
|
445 | - $invoice = geodir_get_invoice( $invoice_id ); |
|
446 | - return ( empty( $invoice->invoice_id ) ? $invoice->invoice_id : false); |
|
444 | +function wpinv_gdp_to_wpi_id($invoice_id) { |
|
445 | + $invoice = geodir_get_invoice($invoice_id); |
|
446 | + return (empty($invoice->invoice_id) ? $invoice->invoice_id : false); |
|
447 | 447 | } |
448 | 448 | |
449 | -function wpinv_to_gdp_recalculate_total( $invoice, $wpi_nosave ) { |
|
449 | +function wpinv_to_gdp_recalculate_total($invoice, $wpi_nosave) { |
|
450 | 450 | global $wpdb; |
451 | 451 | |
452 | - if ( !empty( $wpi_nosave ) ) { |
|
452 | + if (!empty($wpi_nosave)) { |
|
453 | 453 | return; |
454 | 454 | } |
455 | 455 | |
456 | - $gdp_invoice_id = wpinv_wpi_to_gdp_id( $invoice->ID ); |
|
456 | + $gdp_invoice_id = wpinv_wpi_to_gdp_id($invoice->ID); |
|
457 | 457 | |
458 | - if ( $gdp_invoice_id > 0 ) { |
|
458 | + if ($gdp_invoice_id > 0) { |
|
459 | 459 | $update_data = array(); |
460 | 460 | $update_data['tax_amount'] = $invoice->tax; |
461 | 461 | $update_data['paied_amount'] = $invoice->total; |
462 | 462 | $update_data['discount'] = $invoice->discount; |
463 | 463 | $update_data['coupon_code'] = $invoice->discount_code; |
464 | 464 | |
465 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $gdp_invoice_id ) ); |
|
465 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $gdp_invoice_id)); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | return; |
469 | 469 | } |
470 | 470 | //add_action( 'wpinv_invoice_recalculate_total', 'wpinv_to_gdp_recalculate_total', 10, 2 ); |
471 | 471 | |
472 | -function wpinv_gdp_to_wpi_invoice( $invoice_id ) { |
|
473 | - $invoice = geodir_get_invoice( $invoice_id ); |
|
474 | - if ( empty( $invoice->invoice_id ) ) { |
|
472 | +function wpinv_gdp_to_wpi_invoice($invoice_id) { |
|
473 | + $invoice = geodir_get_invoice($invoice_id); |
|
474 | + if (empty($invoice->invoice_id)) { |
|
475 | 475 | return false; |
476 | 476 | } |
477 | 477 | |
478 | - return wpinv_get_invoice( $invoice->invoice_id ); |
|
478 | + return wpinv_get_invoice($invoice->invoice_id); |
|
479 | 479 | } |
480 | 480 | |
481 | -function wpinv_payment_set_coupon_code( $status, $invoice_id, $coupon_code ) { |
|
482 | - $invoice = wpinv_gdp_to_wpi_invoice( $invoice_id ); |
|
483 | - if ( empty( $invoice ) ) { |
|
481 | +function wpinv_payment_set_coupon_code($status, $invoice_id, $coupon_code) { |
|
482 | + $invoice = wpinv_gdp_to_wpi_invoice($invoice_id); |
|
483 | + if (empty($invoice)) { |
|
484 | 484 | return $status; |
485 | 485 | } |
486 | 486 | |
487 | - if ( $status === 1 || $status === 0 ) { |
|
488 | - if ( $status === 1 ) { |
|
489 | - $discount = geodir_get_discount_amount( $coupon_code, $invoice->get_subtotal() ); |
|
487 | + if ($status === 1 || $status === 0) { |
|
488 | + if ($status === 1) { |
|
489 | + $discount = geodir_get_discount_amount($coupon_code, $invoice->get_subtotal()); |
|
490 | 490 | } else { |
491 | 491 | $discount = ''; |
492 | 492 | $coupon_code = ''; |
493 | 493 | } |
494 | 494 | |
495 | - $invoice->set( 'discount', $discount ); |
|
496 | - $invoice->set( 'discount_code', $coupon_code ); |
|
495 | + $invoice->set('discount', $discount); |
|
496 | + $invoice->set('discount_code', $coupon_code); |
|
497 | 497 | $invoice->save(); |
498 | 498 | $invoice->recalculate_total(); |
499 | 499 | } |
500 | 500 | |
501 | 501 | return $status; |
502 | 502 | } |
503 | -add_filter( 'geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3 ); |
|
503 | +add_filter('geodir_payment_set_coupon_code', 'wpinv_payment_set_coupon_code', 10, 3); |
|
504 | 504 | |
505 | 505 | function wpinv_merge_gd_invoices() { |
506 | 506 | if (!defined('GEODIRPAYMENT_VERSION')) { |
@@ -508,157 +508,157 @@ discard block |
||
508 | 508 | } |
509 | 509 | ?> |
510 | 510 | <tr> |
511 | - <td><?php _e( 'Merge Price Packages', 'invoicing' ); ?></td> |
|
512 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing' ); ?></p></td> |
|
513 | - <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
511 | + <td><?php _e('Merge Price Packages', 'invoicing'); ?></td> |
|
512 | + <td><p><?php _e('Merge GeoDirectory Payment Manager price packages to the Invoicing items.', 'invoicing'); ?></p></td> |
|
513 | + <td><input type="button" data-tool="merge_packages" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
514 | 514 | </tr> |
515 | 515 | <tr> |
516 | - <td><?php _e( 'Merge Invoices', 'invoicing' ); ?></td> |
|
517 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing' ); ?></p></td> |
|
518 | - <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
516 | + <td><?php _e('Merge Invoices', 'invoicing'); ?></td> |
|
517 | + <td><p><?php _e('Merge GeoDirectory Payment Manager invoices to the Invoicing.', 'invoicing'); ?></p></td> |
|
518 | + <td><input type="button" data-tool="merge_invoices" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
519 | 519 | </tr> |
520 | 520 | <tr> |
521 | - <td><?php _e( 'Fix Taxes for Merged Invoices', 'invoicing' ); ?></td> |
|
522 | - <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> |
|
523 | - <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
521 | + <td><?php _e('Fix Taxes for Merged Invoices', 'invoicing'); ?></td> |
|
522 | + <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> |
|
523 | + <td><input type="button" data-tool="merge_fix_taxes" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
524 | 524 | </tr> |
525 | 525 | <tr> |
526 | - <td><?php _e( 'Merge Coupons', 'invoicing' ); ?></td> |
|
527 | - <td><p><?php _e( 'Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing' ); ?></p></td> |
|
528 | - <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e( 'Run', 'invoicing' ); ?>"></td> |
|
526 | + <td><?php _e('Merge Coupons', 'invoicing'); ?></td> |
|
527 | + <td><p><?php _e('Merge GeoDirectory Payment Manager coupons to the Invoicing.', 'invoicing'); ?></p></td> |
|
528 | + <td><input type="button" data-tool="merge_coupons" class="button-primary wpinv-tool" value="<?php esc_attr_e('Run', 'invoicing'); ?>"></td> |
|
529 | 529 | </tr> |
530 | 530 | <?php |
531 | 531 | } |
532 | -add_action( 'wpinv_tools_row', 'wpinv_merge_gd_invoices', 10 ); |
|
532 | +add_action('wpinv_tools_row', 'wpinv_merge_gd_invoices', 10); |
|
533 | 533 | |
534 | 534 | function wpinv_tool_merge_packages() { |
535 | 535 | $packages = geodir_package_list_info(); |
536 | 536 | |
537 | 537 | $count = 0; |
538 | 538 | |
539 | - if ( !empty( $packages ) ) { |
|
539 | + if (!empty($packages)) { |
|
540 | 540 | $success = true; |
541 | 541 | |
542 | - foreach ( $packages as $key => $package ) { |
|
542 | + foreach ($packages as $key => $package) { |
|
543 | 543 | $item = wpinv_get_item_by('custom_id', $package->pid, 'package'); |
544 | - if ( !empty( $item ) ) { |
|
544 | + if (!empty($item)) { |
|
545 | 545 | continue; |
546 | 546 | } |
547 | 547 | |
548 | - $merged = wpinv_merge_gd_package_to_item( $package->pid, false, $package ); |
|
548 | + $merged = wpinv_merge_gd_package_to_item($package->pid, false, $package); |
|
549 | 549 | |
550 | - if ( !empty( $merged ) ) { |
|
551 | - wpinv_error_log( 'Package merge S : ' . $package->pid ); |
|
550 | + if (!empty($merged)) { |
|
551 | + wpinv_error_log('Package merge S : ' . $package->pid); |
|
552 | 552 | $count++; |
553 | 553 | } else { |
554 | - wpinv_error_log( 'Package merge F : ' . $package->pid ); |
|
554 | + wpinv_error_log('Package merge F : ' . $package->pid); |
|
555 | 555 | } |
556 | 556 | } |
557 | 557 | |
558 | - if ( $count > 0 ) { |
|
559 | - $message = sprintf( _n( 'Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing' ), $count ); |
|
558 | + if ($count > 0) { |
|
559 | + $message = sprintf(_n('Total <b>%d</b> price package is merged successfully.', 'Total <b>%d</b> price packages are merged successfully.', $count, 'invoicing'), $count); |
|
560 | 560 | } else { |
561 | - $message = __( 'No price packages merged.', 'invoicing' ); |
|
561 | + $message = __('No price packages merged.', 'invoicing'); |
|
562 | 562 | } |
563 | 563 | } else { |
564 | 564 | $success = false; |
565 | - $message = __( 'No price packages found to merge!', 'invoicing' ); |
|
565 | + $message = __('No price packages found to merge!', 'invoicing'); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | $response = array(); |
569 | 569 | $response['success'] = $success; |
570 | 570 | $response['data']['message'] = $message; |
571 | - wp_send_json( $response ); |
|
571 | + wp_send_json($response); |
|
572 | 572 | } |
573 | -add_action( 'wpinv_tool_merge_packages', 'wpinv_tool_merge_packages' ); |
|
573 | +add_action('wpinv_tool_merge_packages', 'wpinv_tool_merge_packages'); |
|
574 | 574 | |
575 | 575 | function wpinv_tool_merge_invoices() { |
576 | 576 | global $wpdb, $wpi_gdp_inv_merge, $wpi_tax_rates; |
577 | 577 | |
578 | 578 | $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"; |
579 | 579 | |
580 | - $items = $wpdb->get_results( $sql ); |
|
580 | + $items = $wpdb->get_results($sql); |
|
581 | 581 | |
582 | 582 | $count = 0; |
583 | 583 | |
584 | - if ( !empty( $items ) ) { |
|
584 | + if (!empty($items)) { |
|
585 | 585 | $success = true; |
586 | 586 | $wpi_gdp_inv_merge = true; |
587 | 587 | |
588 | - foreach ( $items as $item ) { |
|
588 | + foreach ($items as $item) { |
|
589 | 589 | $wpi_tax_rates = NULL; |
590 | 590 | |
591 | - $wpdb->query( "UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'" ); |
|
591 | + $wpdb->query("UPDATE `" . INVOICE_TABLE . "` SET `invoice_id` = 0 WHERE id = '" . $item->id . "'"); |
|
592 | 592 | |
593 | - $merged = wpinv_cpt_save( $item->id ); |
|
593 | + $merged = wpinv_cpt_save($item->id); |
|
594 | 594 | |
595 | - if ( !empty( $merged ) && !empty( $merged->ID ) ) { |
|
595 | + if (!empty($merged) && !empty($merged->ID)) { |
|
596 | 596 | $count++; |
597 | 597 | |
598 | - $post_date = !empty( $item->date ) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time( 'mysql' ); |
|
599 | - $post_date_gmt = get_gmt_from_date( $post_date ); |
|
600 | - $post_modified = !empty( $item->date_updated ) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date; |
|
601 | - $post_modified_gmt = get_gmt_from_date( $post_modified ); |
|
598 | + $post_date = !empty($item->date) && $item->date != '0000-00-00 00:00:00' ? $item->date : current_time('mysql'); |
|
599 | + $post_date_gmt = get_gmt_from_date($post_date); |
|
600 | + $post_modified = !empty($item->date_updated) && $item->date_updated != '0000-00-00 00:00:00' ? $item->date_updated : $post_date; |
|
601 | + $post_modified_gmt = get_gmt_from_date($post_modified); |
|
602 | 602 | |
603 | - $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 ) ); |
|
603 | + $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)); |
|
604 | 604 | |
605 | - if ( $merged->is_paid() ) { |
|
606 | - update_post_meta( $merged->ID, '_wpinv_completed_date', $post_modified ); |
|
605 | + if ($merged->is_paid()) { |
|
606 | + update_post_meta($merged->ID, '_wpinv_completed_date', $post_modified); |
|
607 | 607 | } |
608 | 608 | |
609 | - clean_post_cache( $merged->ID ); |
|
609 | + clean_post_cache($merged->ID); |
|
610 | 610 | |
611 | - wpinv_error_log( 'Invoice merge S : ' . $item->id . ' => ' . $merged->ID ); |
|
611 | + wpinv_error_log('Invoice merge S : ' . $item->id . ' => ' . $merged->ID); |
|
612 | 612 | } else { |
613 | - wpinv_error_log( 'Invoice merge F : ' . $item->id ); |
|
613 | + wpinv_error_log('Invoice merge F : ' . $item->id); |
|
614 | 614 | } |
615 | 615 | } |
616 | 616 | |
617 | 617 | $wpi_gdp_inv_merge = false; |
618 | 618 | |
619 | - if ( $count > 0 ) { |
|
620 | - $message = sprintf( _n( 'Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing' ), $count ); |
|
619 | + if ($count > 0) { |
|
620 | + $message = sprintf(_n('Total <b>%d</b> invoice is merged successfully.', 'Total <b>%d</b> invoices are merged successfully.', $count, 'invoicing'), $count); |
|
621 | 621 | } else { |
622 | - $message = __( 'No invoices merged.', 'invoicing' ); |
|
622 | + $message = __('No invoices merged.', 'invoicing'); |
|
623 | 623 | } |
624 | 624 | } else { |
625 | 625 | $success = false; |
626 | - $message = __( 'No invoices found to merge!', 'invoicing' ); |
|
626 | + $message = __('No invoices found to merge!', 'invoicing'); |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | $response = array(); |
630 | 630 | $response['success'] = $success; |
631 | 631 | $response['data']['message'] = $message; |
632 | - wp_send_json( $response ); |
|
632 | + wp_send_json($response); |
|
633 | 633 | } |
634 | -add_action( 'wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices' ); |
|
634 | +add_action('wpinv_tool_merge_invoices', 'wpinv_tool_merge_invoices'); |
|
635 | 635 | |
636 | 636 | function wpinv_tool_merge_coupons() { |
637 | 637 | global $wpdb; |
638 | 638 | |
639 | 639 | $sql = "SELECT * FROM `" . COUPON_TABLE . "` WHERE `coupon_code` IS NOT NULL AND `coupon_code` != '' ORDER BY `cid` ASC"; |
640 | - $items = $wpdb->get_results( $sql ); |
|
640 | + $items = $wpdb->get_results($sql); |
|
641 | 641 | $count = 0; |
642 | 642 | |
643 | - if ( !empty( $items ) ) { |
|
643 | + if (!empty($items)) { |
|
644 | 644 | $success = true; |
645 | 645 | |
646 | - foreach ( $items as $item ) { |
|
647 | - if ( wpinv_get_discount_by_code( $item->coupon_code ) ) { |
|
646 | + foreach ($items as $item) { |
|
647 | + if (wpinv_get_discount_by_code($item->coupon_code)) { |
|
648 | 648 | continue; |
649 | 649 | } |
650 | 650 | |
651 | 651 | $args = array( |
652 | 652 | 'post_type' => 'wpi_discount', |
653 | 653 | 'post_title' => $item->coupon_code, |
654 | - 'post_status' => !empty( $item->status ) ? 'publish' : 'pending' |
|
654 | + 'post_status' => !empty($item->status) ? 'publish' : 'pending' |
|
655 | 655 | ); |
656 | 656 | |
657 | - $merged = wp_insert_post( $args ); |
|
657 | + $merged = wp_insert_post($args); |
|
658 | 658 | |
659 | 659 | $item_id = $item->cid; |
660 | 660 | |
661 | - if ( $merged ) { |
|
661 | + if ($merged) { |
|
662 | 662 | $meta = array( |
663 | 663 | 'code' => $item->coupon_code, |
664 | 664 | 'type' => $item->discount_type != 'per' ? 'flat' : 'percent', |
@@ -666,65 +666,65 @@ discard block |
||
666 | 666 | 'max_uses' => (int)$item->usage_limit, |
667 | 667 | 'uses' => (int)$item->usage_count, |
668 | 668 | ); |
669 | - wpinv_store_discount( $merged, $meta, get_post( $merged ) ); |
|
669 | + wpinv_store_discount($merged, $meta, get_post($merged)); |
|
670 | 670 | |
671 | 671 | $count++; |
672 | 672 | |
673 | - wpinv_error_log( 'Coupon merge S : ' . $item_id . ' => ' . $merged ); |
|
673 | + wpinv_error_log('Coupon merge S : ' . $item_id . ' => ' . $merged); |
|
674 | 674 | } else { |
675 | - wpinv_error_log( 'Coupon merge F : ' . $item_id ); |
|
675 | + wpinv_error_log('Coupon merge F : ' . $item_id); |
|
676 | 676 | } |
677 | 677 | } |
678 | 678 | |
679 | - if ( $count > 0 ) { |
|
680 | - $message = sprintf( _n( 'Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing' ), $count ); |
|
679 | + if ($count > 0) { |
|
680 | + $message = sprintf(_n('Total <b>%d</b> coupon is merged successfully.', 'Total <b>%d</b> coupons are merged successfully.', $count, 'invoicing'), $count); |
|
681 | 681 | } else { |
682 | - $message = __( 'No coupons merged.', 'invoicing' ); |
|
682 | + $message = __('No coupons merged.', 'invoicing'); |
|
683 | 683 | } |
684 | 684 | } else { |
685 | 685 | $success = false; |
686 | - $message = __( 'No coupons found to merge!', 'invoicing' ); |
|
686 | + $message = __('No coupons found to merge!', 'invoicing'); |
|
687 | 687 | } |
688 | 688 | |
689 | 689 | $response = array(); |
690 | 690 | $response['success'] = $success; |
691 | 691 | $response['data']['message'] = $message; |
692 | - wp_send_json( $response ); |
|
692 | + wp_send_json($response); |
|
693 | 693 | } |
694 | -add_action( 'wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons' ); |
|
694 | +add_action('wpinv_tool_merge_coupons', 'wpinv_tool_merge_coupons'); |
|
695 | 695 | |
696 | -function wpinv_gdp_to_wpi_currency( $value, $option = '' ) { |
|
696 | +function wpinv_gdp_to_wpi_currency($value, $option = '') { |
|
697 | 697 | return wpinv_get_currency(); |
698 | 698 | } |
699 | -add_filter( 'pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2 ); |
|
699 | +add_filter('pre_option_geodir_currency', 'wpinv_gdp_to_wpi_currency', 10, 2); |
|
700 | 700 | |
701 | -function wpinv_gdp_to_wpi_currency_sign( $value, $option = '' ) { |
|
701 | +function wpinv_gdp_to_wpi_currency_sign($value, $option = '') { |
|
702 | 702 | return wpinv_currency_symbol(); |
703 | 703 | } |
704 | -add_filter( 'pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2 ); |
|
704 | +add_filter('pre_option_geodir_currencysym', 'wpinv_gdp_to_wpi_currency_sign', 10, 2); |
|
705 | 705 | |
706 | -function wpinv_gdp_to_wpi_display_price( $price, $amount, $display = true , $decimal_sep, $thousand_sep ) { |
|
707 | - if ( !$display ) { |
|
708 | - $price = wpinv_round_amount( $amount ); |
|
706 | +function wpinv_gdp_to_wpi_display_price($price, $amount, $display = true, $decimal_sep, $thousand_sep) { |
|
707 | + if (!$display) { |
|
708 | + $price = wpinv_round_amount($amount); |
|
709 | 709 | } else { |
710 | - $price = wpinv_price( wpinv_format_amount( $amount ) ); |
|
710 | + $price = wpinv_price(wpinv_format_amount($amount)); |
|
711 | 711 | } |
712 | 712 | |
713 | 713 | return $price; |
714 | 714 | } |
715 | -add_filter( 'geodir_payment_price' , 'wpinv_gdp_to_wpi_display_price', 10000, 5 ); |
|
715 | +add_filter('geodir_payment_price', 'wpinv_gdp_to_wpi_display_price', 10000, 5); |
|
716 | 716 | |
717 | -function wpinv_gdp_to_inv_checkout_redirect( $redirect_url ) { |
|
717 | +function wpinv_gdp_to_inv_checkout_redirect($redirect_url) { |
|
718 | 718 | $invoice_id = geodir_payment_cart_id(); |
719 | - $invoice_info = geodir_get_invoice( $invoice_id ); |
|
720 | - $wpi_invoice = !empty( $invoice_info->invoice_id ) ? wpinv_get_invoice( $invoice_info->invoice_id ) : NULL; |
|
719 | + $invoice_info = geodir_get_invoice($invoice_id); |
|
720 | + $wpi_invoice = !empty($invoice_info->invoice_id) ? wpinv_get_invoice($invoice_info->invoice_id) : NULL; |
|
721 | 721 | |
722 | - if ( !( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) ) { |
|
723 | - $wpi_invoice_id = wpinv_cpt_save( $invoice_id ); |
|
724 | - $wpi_invoice = wpinv_get_invoice( $wpi_invoice_id ); |
|
722 | + if (!(!empty($wpi_invoice) && !empty($wpi_invoice->ID))) { |
|
723 | + $wpi_invoice_id = wpinv_cpt_save($invoice_id); |
|
724 | + $wpi_invoice = wpinv_get_invoice($wpi_invoice_id); |
|
725 | 725 | } |
726 | 726 | |
727 | - if ( !empty( $wpi_invoice ) && !empty( $wpi_invoice->ID ) ) { |
|
727 | + if (!empty($wpi_invoice) && !empty($wpi_invoice->ID)) { |
|
728 | 728 | |
729 | 729 | // Clear cart |
730 | 730 | geodir_payment_clear_cart(); |
@@ -734,121 +734,121 @@ discard block |
||
734 | 734 | |
735 | 735 | return $redirect_url; |
736 | 736 | } |
737 | -add_filter( 'geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1 ); |
|
737 | +add_filter('geodir_payment_checkout_redirect_url', 'wpinv_gdp_to_inv_checkout_redirect', 100, 1); |
|
738 | 738 | |
739 | -function wpinv_gdp_dashboard_invoice_history_link( $dashboard_links ) { |
|
740 | - if ( get_current_user_id() ) { |
|
741 | - $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>'; |
|
739 | +function wpinv_gdp_dashboard_invoice_history_link($dashboard_links) { |
|
740 | + if (get_current_user_id()) { |
|
741 | + $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>'; |
|
742 | 742 | } |
743 | 743 | |
744 | 744 | return $dashboard_links; |
745 | 745 | } |
746 | -add_action( 'geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link' ); |
|
747 | -remove_action( 'geodir_dashboard_links', 'geodir_payment_invoices_list_page_link' ); |
|
746 | +add_action('geodir_dashboard_links', 'wpinv_gdp_dashboard_invoice_history_link'); |
|
747 | +remove_action('geodir_dashboard_links', 'geodir_payment_invoices_list_page_link'); |
|
748 | 748 | |
749 | -function wpinv_wpi_to_gdp_update_status( $invoice_id, $new_status, $old_status ) { |
|
749 | +function wpinv_wpi_to_gdp_update_status($invoice_id, $new_status, $old_status) { |
|
750 | 750 | if (!defined('GEODIRPAYMENT_VERSION')) { |
751 | 751 | return false; |
752 | 752 | } |
753 | 753 | |
754 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
755 | - if ( empty( $invoice ) ) { |
|
754 | + $invoice = wpinv_get_invoice($invoice_id); |
|
755 | + if (empty($invoice)) { |
|
756 | 756 | return false; |
757 | 757 | } |
758 | 758 | |
759 | - remove_action( 'geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4 ); |
|
759 | + remove_action('geodir_payment_invoice_status_changed', 'wpinv_payment_status_changed', 11, 4); |
|
760 | 760 | |
761 | - $invoice_id = wpinv_wpi_to_gdp_id( $invoice_id ); |
|
762 | - $new_status = wpinv_wpi_to_gdp_status( $new_status ); |
|
761 | + $invoice_id = wpinv_wpi_to_gdp_id($invoice_id); |
|
762 | + $new_status = wpinv_wpi_to_gdp_status($new_status); |
|
763 | 763 | |
764 | - geodir_update_invoice_status( $invoice_id, $new_status, $invoice->is_recurring() ); |
|
764 | + geodir_update_invoice_status($invoice_id, $new_status, $invoice->is_recurring()); |
|
765 | 765 | } |
766 | -add_action( 'wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3 ); |
|
766 | +add_action('wpinv_update_status', 'wpinv_wpi_to_gdp_update_status', 999, 3); |
|
767 | 767 | |
768 | -function wpinv_gdp_to_wpi_delete_package( $gd_package_id ) { |
|
769 | - $item = wpinv_get_item_by( 'custom_id', $gd_package_id, 'package' ); |
|
768 | +function wpinv_gdp_to_wpi_delete_package($gd_package_id) { |
|
769 | + $item = wpinv_get_item_by('custom_id', $gd_package_id, 'package'); |
|
770 | 770 | |
771 | - if ( !empty( $item ) ) { |
|
772 | - wpinv_remove_item( $item, true ); |
|
771 | + if (!empty($item)) { |
|
772 | + wpinv_remove_item($item, true); |
|
773 | 773 | } |
774 | 774 | } |
775 | -add_action( 'geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1 ) ; |
|
775 | +add_action('geodir_payment_post_delete_package', 'wpinv_gdp_to_wpi_delete_package', 10, 1); |
|
776 | 776 | |
777 | -function wpinv_can_delete_package_item( $return, $post_id ) { |
|
778 | - 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 ) ) { |
|
779 | - $gd_package = geodir_get_package_info_by_id( $package_id, '' ); |
|
777 | +function wpinv_can_delete_package_item($return, $post_id) { |
|
778 | + 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)) { |
|
779 | + $gd_package = geodir_get_package_info_by_id($package_id, ''); |
|
780 | 780 | |
781 | - if ( !empty( $gd_package ) ) { |
|
781 | + if (!empty($gd_package)) { |
|
782 | 782 | $return = false; |
783 | 783 | } |
784 | 784 | } |
785 | 785 | |
786 | 786 | return $return; |
787 | 787 | } |
788 | -add_filter( 'wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2 ); |
|
788 | +add_filter('wpinv_can_delete_item', 'wpinv_can_delete_package_item', 10, 2); |
|
789 | 789 | |
790 | -function wpinv_package_item_classes( $classes, $class, $post_id ) { |
|
790 | +function wpinv_package_item_classes($classes, $class, $post_id) { |
|
791 | 791 | global $typenow; |
792 | 792 | |
793 | - if ( $typenow == 'wpi_item' && in_array( 'wpi-gd-package', $classes ) ) { |
|
794 | - if ( wpinv_item_in_use( $post_id ) ) { |
|
793 | + if ($typenow == 'wpi_item' && in_array('wpi-gd-package', $classes)) { |
|
794 | + if (wpinv_item_in_use($post_id)) { |
|
795 | 795 | $classes[] = 'wpi-inuse-pkg'; |
796 | - } 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 ), '' ) ) ) { |
|
796 | + } 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), ''))) { |
|
797 | 797 | $classes[] = 'wpi-delete-pkg'; |
798 | 798 | } |
799 | 799 | } |
800 | 800 | |
801 | 801 | return $classes; |
802 | 802 | } |
803 | -add_filter( 'post_class', 'wpinv_package_item_classes', 10, 3 ); |
|
803 | +add_filter('post_class', 'wpinv_package_item_classes', 10, 3); |
|
804 | 804 | |
805 | -function wpinv_gdp_package_type_info( $post ) { |
|
806 | - if ( wpinv_pm_active() ) { |
|
807 | - ?><p class="wpi-m0"><?php _e( 'Package: GeoDirectory price packages items.', 'invoicing' );?></p> |
|
805 | +function wpinv_gdp_package_type_info($post) { |
|
806 | + if (wpinv_pm_active()) { |
|
807 | + ?><p class="wpi-m0"><?php _e('Package: GeoDirectory price packages items.', 'invoicing'); ?></p> |
|
808 | 808 | <?php |
809 | 809 | } |
810 | 810 | } |
811 | -add_action( 'wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1 ) ; |
|
811 | +add_action('wpinv_item_info_metabox_after', 'wpinv_gdp_package_type_info', 10, 1); |
|
812 | 812 | |
813 | -function wpinv_gdp_to_gdi_set_zero_tax( $is_taxable, $item_id, $country , $state ) { |
|
813 | +function wpinv_gdp_to_gdi_set_zero_tax($is_taxable, $item_id, $country, $state) { |
|
814 | 814 | global $wpi_zero_tax; |
815 | 815 | |
816 | - if ( $wpi_zero_tax ) { |
|
816 | + if ($wpi_zero_tax) { |
|
817 | 817 | $is_taxable = false; |
818 | 818 | } |
819 | 819 | |
820 | 820 | return $is_taxable; |
821 | 821 | } |
822 | -add_action( 'wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4 ) ; |
|
822 | +add_action('wpinv_item_is_taxable', 'wpinv_gdp_to_gdi_set_zero_tax', 10, 4); |
|
823 | 823 | |
824 | 824 | function wpinv_tool_merge_fix_taxes() { |
825 | 825 | global $wpdb; |
826 | 826 | |
827 | 827 | $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'"; |
828 | - $items = $wpdb->get_results( $sql ); |
|
828 | + $items = $wpdb->get_results($sql); |
|
829 | 829 | |
830 | - if ( !empty( $items ) ) { |
|
831 | - foreach ( $items as $item ) { |
|
832 | - if ( get_post_meta( $item->ID, '_wpinv_vat_class', true ) == '_exempt' ) { |
|
833 | - update_post_meta( $item->ID, '_wpinv_vat_class', '_standard' ); |
|
830 | + if (!empty($items)) { |
|
831 | + foreach ($items as $item) { |
|
832 | + if (get_post_meta($item->ID, '_wpinv_vat_class', true) == '_exempt') { |
|
833 | + update_post_meta($item->ID, '_wpinv_vat_class', '_standard'); |
|
834 | 834 | } |
835 | 835 | } |
836 | 836 | } |
837 | 837 | |
838 | 838 | $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"; |
839 | - $items = $wpdb->get_results( $sql ); |
|
839 | + $items = $wpdb->get_results($sql); |
|
840 | 840 | |
841 | - if ( !empty( $items ) ) { |
|
841 | + if (!empty($items)) { |
|
842 | 842 | $success = false; |
843 | - $message = __( 'Taxes fixed for non-paid merged GD invoices.', 'invoicing' ); |
|
843 | + $message = __('Taxes fixed for non-paid merged GD invoices.', 'invoicing'); |
|
844 | 844 | |
845 | 845 | global $wpi_userID, $wpinv_ip_address_country, $wpi_tax_rates; |
846 | 846 | |
847 | - foreach ( $items as $item ) { |
|
847 | + foreach ($items as $item) { |
|
848 | 848 | $wpi_tax_rates = NULL; |
849 | 849 | $data = wpinv_get_invoice($item->ID); |
850 | 850 | |
851 | - if ( empty( $data ) ) { |
|
851 | + if (empty($data)) { |
|
852 | 852 | continue; |
853 | 853 | } |
854 | 854 | |
@@ -856,51 +856,51 @@ discard block |
||
856 | 856 | |
857 | 857 | $data_session = array(); |
858 | 858 | $data_session['invoice_id'] = $data->ID; |
859 | - $data_session['cart_discounts'] = $data->get_discounts( true ); |
|
859 | + $data_session['cart_discounts'] = $data->get_discounts(true); |
|
860 | 860 | |
861 | - wpinv_set_checkout_session( $data_session ); |
|
861 | + wpinv_set_checkout_session($data_session); |
|
862 | 862 | |
863 | 863 | $wpi_userID = (int)$data->get_user_id(); |
864 | 864 | $_POST['country'] = !empty($data->country) ? $data->country : wpinv_get_default_country(); |
865 | 865 | |
866 | - $data->country = sanitize_text_field( $_POST['country'] ); |
|
867 | - $data->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
866 | + $data->country = sanitize_text_field($_POST['country']); |
|
867 | + $data->set('country', sanitize_text_field($_POST['country'])); |
|
868 | 868 | |
869 | 869 | $wpinv_ip_address_country = $data->country; |
870 | 870 | |
871 | 871 | $data->recalculate_totals(true); |
872 | 872 | |
873 | - wpinv_set_checkout_session( $checkout_session ); |
|
873 | + wpinv_set_checkout_session($checkout_session); |
|
874 | 874 | |
875 | 875 | $update_data = array(); |
876 | 876 | $update_data['tax_amount'] = $data->get_tax(); |
877 | 877 | $update_data['paied_amount'] = $data->get_total(); |
878 | 878 | $update_data['invoice_id'] = $data->ID; |
879 | 879 | |
880 | - $wpdb->update( INVOICE_TABLE, $update_data, array( 'id' => $item->gdp_id ) ); |
|
880 | + $wpdb->update(INVOICE_TABLE, $update_data, array('id' => $item->gdp_id)); |
|
881 | 881 | } |
882 | 882 | } else { |
883 | 883 | $success = false; |
884 | - $message = __( 'No invoices found to fix taxes!', 'invoicing' ); |
|
884 | + $message = __('No invoices found to fix taxes!', 'invoicing'); |
|
885 | 885 | } |
886 | 886 | |
887 | 887 | $response = array(); |
888 | 888 | $response['success'] = $success; |
889 | 889 | $response['data']['message'] = $message; |
890 | - wp_send_json( $response ); |
|
890 | + wp_send_json($response); |
|
891 | 891 | } |
892 | -add_action( 'wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes' ); |
|
893 | -remove_action( 'geodir_before_detail_fields' , 'geodir_build_coupon', 2 ); |
|
892 | +add_action('wpinv_tool_merge_fix_taxes', 'wpinv_tool_merge_fix_taxes'); |
|
893 | +remove_action('geodir_before_detail_fields', 'geodir_build_coupon', 2); |
|
894 | 894 | |
895 | -function wpinv_wpi_to_gdp_handle_subscription_cancel( $invoice_id, $invoice ) { |
|
896 | - if ( wpinv_pm_active() && !empty( $invoice ) && $invoice->is_recurring() ) { |
|
897 | - if ( $invoice->is_renewal() ) { |
|
895 | +function wpinv_wpi_to_gdp_handle_subscription_cancel($invoice_id, $invoice) { |
|
896 | + if (wpinv_pm_active() && !empty($invoice) && $invoice->is_recurring()) { |
|
897 | + if ($invoice->is_renewal()) { |
|
898 | 898 | $invoice = $invoice->get_parent_payment(); |
899 | 899 | } |
900 | 900 | |
901 | - if ( !empty( $invoice ) ) { |
|
902 | - wpinv_wpi_to_gdp_update_status( $invoice->ID, 'wpi-cancelled', $invoice->get_status() ); |
|
901 | + if (!empty($invoice)) { |
|
902 | + wpinv_wpi_to_gdp_update_status($invoice->ID, 'wpi-cancelled', $invoice->get_status()); |
|
903 | 903 | } |
904 | 904 | } |
905 | 905 | } |
906 | -add_action( 'wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2 ); |
|
907 | 906 | \ No newline at end of file |
907 | +add_action('wpinv_subscription_cancelled', 'wpinv_wpi_to_gdp_handle_subscription_cancel', 10, 2); |
|
908 | 908 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -function wpinv_get_subscriptions( $args = array() ) { |
|
3 | - if ( empty( $args['parent_invoice_id'] ) ) { |
|
2 | +function wpinv_get_subscriptions($args = array()) { |
|
3 | + if (empty($args['parent_invoice_id'])) { |
|
4 | 4 | return false; |
5 | 5 | } |
6 | 6 | |
@@ -14,18 +14,18 @@ discard block |
||
14 | 14 | ); |
15 | 15 | |
16 | 16 | $args['post_parent'] = $args['parent_invoice_id']; |
17 | - $args = wp_parse_args( $args, $defaults ); |
|
17 | + $args = wp_parse_args($args, $defaults); |
|
18 | 18 | |
19 | - if( $args['numberposts'] < 1 ) { |
|
19 | + if ($args['numberposts'] < 1) { |
|
20 | 20 | $args['numberposts'] = 999999999999; |
21 | 21 | } |
22 | 22 | |
23 | - $posts = get_posts( $args ); |
|
23 | + $posts = get_posts($args); |
|
24 | 24 | $subscriptions = array(); |
25 | - if ( !empty( $posts ) ) { |
|
26 | - foreach ( $posts as $post ) { |
|
27 | - if ( !empty( $post->ID ) ) { |
|
28 | - $subscriptions[] = wpinv_get_invoice( $post->ID ); |
|
25 | + if (!empty($posts)) { |
|
26 | + foreach ($posts as $post) { |
|
27 | + if (!empty($post->ID)) { |
|
28 | + $subscriptions[] = wpinv_get_invoice($post->ID); |
|
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
@@ -33,19 +33,19 @@ discard block |
||
33 | 33 | |
34 | 34 | return $subscriptions; |
35 | 35 | } |
36 | -function wpinv_get_subscription( $id = 0, $by_profile_id = false ) { |
|
36 | +function wpinv_get_subscription($id = 0, $by_profile_id = false) { |
|
37 | 37 | global $wpdb; |
38 | 38 | |
39 | - if ( empty( $id ) ) { |
|
39 | + if (empty($id)) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | - $id = esc_sql( $id ); |
|
43 | + $id = esc_sql($id); |
|
44 | 44 | |
45 | - $invoice_id = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1" ); |
|
45 | + $invoice_id = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_profile_id' AND meta_value = '{$id}' LIMIT 1"); |
|
46 | 46 | |
47 | - if ( $invoice_id != null ) { |
|
48 | - return wpinv_get_invoice( $invoice_id ); |
|
47 | + if ($invoice_id != null) { |
|
48 | + return wpinv_get_invoice($invoice_id); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | return false; |
@@ -55,49 +55,49 @@ discard block |
||
55 | 55 | * Records a new payment on the subscription |
56 | 56 | * |
57 | 57 | */ |
58 | -function wpinv_recurring_add_subscription_payment( $parent_invoice_id, $subscription_args = array() ) { |
|
59 | - $args = wp_parse_args( $subscription_args, array( |
|
58 | +function wpinv_recurring_add_subscription_payment($parent_invoice_id, $subscription_args = array()) { |
|
59 | + $args = wp_parse_args($subscription_args, array( |
|
60 | 60 | 'amount' => '', |
61 | 61 | 'transaction_id' => '', |
62 | 62 | 'gateway' => '' |
63 | - ) ); |
|
63 | + )); |
|
64 | 64 | |
65 | - if ( wpinv_payment_exists( $args['transaction_id'] ) ) { |
|
65 | + if (wpinv_payment_exists($args['transaction_id'])) { |
|
66 | 66 | return false; |
67 | 67 | } |
68 | 68 | |
69 | - $parent_invoice = wpinv_get_invoice( $parent_invoice_id ); |
|
70 | - if ( empty( $parent_invoice ) ) { |
|
69 | + $parent_invoice = wpinv_get_invoice($parent_invoice_id); |
|
70 | + if (empty($parent_invoice)) { |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
74 | 74 | $invoice = new WPInv_Invoice(); |
75 | - $invoice->set( 'parent_invoice', $parent_invoice_id ); |
|
76 | - $invoice->set( 'currency', $parent_invoice->get_currency() ); |
|
75 | + $invoice->set('parent_invoice', $parent_invoice_id); |
|
76 | + $invoice->set('currency', $parent_invoice->get_currency()); |
|
77 | 77 | //$invoice->set( 'status', 'publish' ); |
78 | - $invoice->set( 'transaction_id', $args['transaction_id'] ); |
|
79 | - $invoice->set( 'key', $parent_invoice->get_key() ); |
|
78 | + $invoice->set('transaction_id', $args['transaction_id']); |
|
79 | + $invoice->set('key', $parent_invoice->get_key()); |
|
80 | 80 | |
81 | - $invoice->set( 'ip', $parent_invoice->ip ); |
|
82 | - $invoice->set( 'user_id', $parent_invoice->get_user_id() ); |
|
83 | - $invoice->set( 'first_name', $parent_invoice->get_first_name() ); |
|
84 | - $invoice->set( 'last_name', $parent_invoice->get_last_name() ); |
|
81 | + $invoice->set('ip', $parent_invoice->ip); |
|
82 | + $invoice->set('user_id', $parent_invoice->get_user_id()); |
|
83 | + $invoice->set('first_name', $parent_invoice->get_first_name()); |
|
84 | + $invoice->set('last_name', $parent_invoice->get_last_name()); |
|
85 | 85 | ///$invoice->set( 'email', $parent_invoice->get_email() ); |
86 | - $invoice->set( 'phone', $parent_invoice->phone ); |
|
87 | - $invoice->set( 'address', $parent_invoice->address ); |
|
88 | - $invoice->set( 'city', $parent_invoice->city ); |
|
89 | - $invoice->set( 'country', $parent_invoice->country ); |
|
90 | - $invoice->set( 'state', $parent_invoice->state ); |
|
91 | - $invoice->set( 'zip', $parent_invoice->zip ); |
|
92 | - $invoice->set( 'company', $parent_invoice->company ); |
|
93 | - $invoice->set( 'vat_number', $parent_invoice->vat_number ); |
|
94 | - $invoice->set( 'vat_rate', $parent_invoice->vat_rate ); |
|
95 | - $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed ); |
|
96 | - |
|
97 | - if ( empty( $args['gateway'] ) ) { |
|
98 | - $invoice->set( 'gateway', $parent_invoice->get_gateway() ); |
|
86 | + $invoice->set('phone', $parent_invoice->phone); |
|
87 | + $invoice->set('address', $parent_invoice->address); |
|
88 | + $invoice->set('city', $parent_invoice->city); |
|
89 | + $invoice->set('country', $parent_invoice->country); |
|
90 | + $invoice->set('state', $parent_invoice->state); |
|
91 | + $invoice->set('zip', $parent_invoice->zip); |
|
92 | + $invoice->set('company', $parent_invoice->company); |
|
93 | + $invoice->set('vat_number', $parent_invoice->vat_number); |
|
94 | + $invoice->set('vat_rate', $parent_invoice->vat_rate); |
|
95 | + $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed); |
|
96 | + |
|
97 | + if (empty($args['gateway'])) { |
|
98 | + $invoice->set('gateway', $parent_invoice->get_gateway()); |
|
99 | 99 | } else { |
100 | - $invoice->set( 'gateway', $args['gateway'] ); |
|
100 | + $invoice->set('gateway', $args['gateway']); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | $recurring_details = $parent_invoice->get_recurring_details(); |
@@ -105,11 +105,11 @@ discard block |
||
105 | 105 | // increase the earnings for each item in the subscription |
106 | 106 | $items = $recurring_details['cart_details']; |
107 | 107 | |
108 | - if ( $items ) { |
|
108 | + if ($items) { |
|
109 | 109 | $add_items = array(); |
110 | 110 | $cart_details = array(); |
111 | 111 | |
112 | - foreach ( $items as $item ) { |
|
112 | + foreach ($items as $item) { |
|
113 | 113 | $add_item = array(); |
114 | 114 | $add_item['id'] = $item['id']; |
115 | 115 | $add_item['quantity'] = $item['quantity']; |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | break; |
120 | 120 | } |
121 | 121 | |
122 | - $invoice->set( 'items', $add_items ); |
|
122 | + $invoice->set('items', $add_items); |
|
123 | 123 | $invoice->cart_details = $cart_details; |
124 | 124 | } |
125 | 125 | |
@@ -129,277 +129,277 @@ discard block |
||
129 | 129 | $tax = $recurring_details['tax']; |
130 | 130 | $discount = $recurring_details['discount']; |
131 | 131 | |
132 | - if ( $discount > 0 ) { |
|
133 | - $invoice->set( 'discount_code', $parent_invoice->discount_code ); |
|
132 | + if ($discount > 0) { |
|
133 | + $invoice->set('discount_code', $parent_invoice->discount_code); |
|
134 | 134 | } |
135 | 135 | |
136 | - $invoice->subtotal = wpinv_round_amount( $subtotal ); |
|
137 | - $invoice->tax = wpinv_round_amount( $tax ); |
|
138 | - $invoice->discount = wpinv_round_amount( $discount ); |
|
139 | - $invoice->total = wpinv_round_amount( $total ); |
|
136 | + $invoice->subtotal = wpinv_round_amount($subtotal); |
|
137 | + $invoice->tax = wpinv_round_amount($tax); |
|
138 | + $invoice->discount = wpinv_round_amount($discount); |
|
139 | + $invoice->total = wpinv_round_amount($total); |
|
140 | 140 | $invoice->save(); |
141 | 141 | |
142 | - wpinv_update_payment_status( $invoice->ID, 'publish' ); |
|
142 | + wpinv_update_payment_status($invoice->ID, 'publish'); |
|
143 | 143 | sleep(1); |
144 | - wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' ); |
|
144 | + wpinv_update_payment_status($invoice->ID, 'wpi-renewal'); |
|
145 | 145 | |
146 | - $invoice = wpinv_get_invoice( $invoice->ID ); |
|
146 | + $invoice = wpinv_get_invoice($invoice->ID); |
|
147 | 147 | |
148 | - $subscription_data = wpinv_payment_subscription_data( $parent_invoice ); |
|
148 | + $subscription_data = wpinv_payment_subscription_data($parent_invoice); |
|
149 | 149 | $subscription_data['recurring_amount'] = $invoice->get_total(); |
150 | - $subscription_data['created'] = current_time( 'mysql', 0 ); |
|
151 | - $subscription_data['expiration'] = $invoice->get_new_expiration( $subscription_data['item_id'] ); |
|
150 | + $subscription_data['created'] = current_time('mysql', 0); |
|
151 | + $subscription_data['expiration'] = $invoice->get_new_expiration($subscription_data['item_id']); |
|
152 | 152 | |
153 | 153 | // Retrieve pending subscription from database and update it's status to active and set proper profile ID |
154 | - $invoice->update_subscription( $subscription_data ); |
|
154 | + $invoice->update_subscription($subscription_data); |
|
155 | 155 | |
156 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args ); |
|
157 | - do_action( 'wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args ); |
|
156 | + do_action('wpinv_recurring_add_subscription_payment', $invoice, $parent_invoice, $subscription_args); |
|
157 | + do_action('wpinv_recurring_record_payment', $invoice->ID, $parent_invoice_id, $subscription_args); |
|
158 | 158 | |
159 | 159 | return $invoice; |
160 | 160 | } |
161 | 161 | |
162 | -function wpinv_payment_exists( $txn_id = '' ) { |
|
162 | +function wpinv_payment_exists($txn_id = '') { |
|
163 | 163 | global $wpdb; |
164 | 164 | |
165 | - if ( empty( $txn_id ) ) { |
|
165 | + if (empty($txn_id)) { |
|
166 | 166 | return false; |
167 | 167 | } |
168 | 168 | |
169 | - $txn_id = esc_sql( $txn_id ); |
|
169 | + $txn_id = esc_sql($txn_id); |
|
170 | 170 | |
171 | - $invoice = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" ); |
|
171 | + $invoice = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1"); |
|
172 | 172 | |
173 | - if ( $invoice != null ) { |
|
173 | + if ($invoice != null) { |
|
174 | 174 | return true; |
175 | 175 | } |
176 | 176 | |
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | |
180 | -function wpinv_is_subscription_payment( $invoice = '' ) { |
|
181 | - if ( empty( $invoice ) ) { |
|
180 | +function wpinv_is_subscription_payment($invoice = '') { |
|
181 | + if (empty($invoice)) { |
|
182 | 182 | return false; |
183 | 183 | } |
184 | 184 | |
185 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
186 | - $invoice = wpinv_get_invoice( $invoice ); |
|
185 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
186 | + $invoice = wpinv_get_invoice($invoice); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( empty( $invoice ) ) { |
|
189 | + if (empty($invoice)) { |
|
190 | 190 | return false; |
191 | 191 | } |
192 | 192 | |
193 | - if ( $invoice->is_renewal() ) { |
|
193 | + if ($invoice->is_renewal()) { |
|
194 | 194 | return true; |
195 | 195 | } |
196 | 196 | |
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | |
200 | -function wpinv_payment_subscription_data( $invoice = '' ) { |
|
201 | - if ( empty( $invoice ) ) { |
|
200 | +function wpinv_payment_subscription_data($invoice = '') { |
|
201 | + if (empty($invoice)) { |
|
202 | 202 | return false; |
203 | 203 | } |
204 | 204 | |
205 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
206 | - $invoice = wpinv_get_invoice( $invoice ); |
|
205 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
206 | + $invoice = wpinv_get_invoice($invoice); |
|
207 | 207 | } |
208 | 208 | |
209 | - if ( empty( $invoice ) ) { |
|
209 | + if (empty($invoice)) { |
|
210 | 210 | return false; |
211 | 211 | } |
212 | 212 | |
213 | 213 | return $invoice->get_subscription_data(); |
214 | 214 | } |
215 | 215 | |
216 | -function wpinv_payment_link_transaction_id( $invoice = '' ) { |
|
217 | - if ( empty( $invoice ) ) { |
|
216 | +function wpinv_payment_link_transaction_id($invoice = '') { |
|
217 | + if (empty($invoice)) { |
|
218 | 218 | return false; |
219 | 219 | } |
220 | 220 | |
221 | - if ( !is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
222 | - $invoice = wpinv_get_invoice( $invoice ); |
|
221 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
222 | + $invoice = wpinv_get_invoice($invoice); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( empty( $invoice ) ) { |
|
225 | + if (empty($invoice)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice ); |
|
229 | + return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice); |
|
230 | 230 | } |
231 | 231 | |
232 | -function wpinv_get_pretty_subscription_period( $period ) { |
|
232 | +function wpinv_get_pretty_subscription_period($period) { |
|
233 | 233 | $frequency = ''; |
234 | 234 | //Format period details |
235 | - switch ( $period ) { |
|
235 | + switch ($period) { |
|
236 | 236 | case 'D' : |
237 | 237 | case 'day' : |
238 | - $frequency = __( 'Daily', 'invoicing' ); |
|
238 | + $frequency = __('Daily', 'invoicing'); |
|
239 | 239 | break; |
240 | 240 | case 'W' : |
241 | 241 | case 'week' : |
242 | - $frequency = __( 'Weekly', 'invoicing' ); |
|
242 | + $frequency = __('Weekly', 'invoicing'); |
|
243 | 243 | break; |
244 | 244 | case 'M' : |
245 | 245 | case 'month' : |
246 | - $frequency = __( 'Monthly', 'invoicing' ); |
|
246 | + $frequency = __('Monthly', 'invoicing'); |
|
247 | 247 | break; |
248 | 248 | case 'Y' : |
249 | 249 | case 'year' : |
250 | - $frequency = __( 'Yearly', 'invoicing' ); |
|
250 | + $frequency = __('Yearly', 'invoicing'); |
|
251 | 251 | break; |
252 | 252 | default : |
253 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period', $frequency, $period ); |
|
253 | + $frequency = apply_filters('wpinv_pretty_subscription_period', $frequency, $period); |
|
254 | 254 | break; |
255 | 255 | } |
256 | 256 | |
257 | 257 | return $frequency; |
258 | 258 | } |
259 | 259 | |
260 | -function wpinv_get_pretty_subscription_period_name( $period ) { |
|
260 | +function wpinv_get_pretty_subscription_period_name($period) { |
|
261 | 261 | $frequency = ''; |
262 | 262 | //Format period details |
263 | - switch ( $period ) { |
|
263 | + switch ($period) { |
|
264 | 264 | case 'D' : |
265 | 265 | case 'day' : |
266 | - $frequency = __( 'Day', 'invoicing' ); |
|
266 | + $frequency = __('Day', 'invoicing'); |
|
267 | 267 | break; |
268 | 268 | case 'W' : |
269 | 269 | case 'week' : |
270 | - $frequency = __( 'Week', 'invoicing' ); |
|
270 | + $frequency = __('Week', 'invoicing'); |
|
271 | 271 | break; |
272 | 272 | case 'M' : |
273 | 273 | case 'month' : |
274 | - $frequency = __( 'Month', 'invoicing' ); |
|
274 | + $frequency = __('Month', 'invoicing'); |
|
275 | 275 | break; |
276 | 276 | case 'Y' : |
277 | 277 | case 'year' : |
278 | - $frequency = __( 'Year', 'invoicing' ); |
|
278 | + $frequency = __('Year', 'invoicing'); |
|
279 | 279 | break; |
280 | 280 | default : |
281 | - $frequency = apply_filters( 'wpinv_pretty_subscription_period_name', $frequency, $period ); |
|
281 | + $frequency = apply_filters('wpinv_pretty_subscription_period_name', $frequency, $period); |
|
282 | 282 | break; |
283 | 283 | } |
284 | 284 | |
285 | 285 | return $frequency; |
286 | 286 | } |
287 | 287 | |
288 | -function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) { |
|
288 | +function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) { |
|
289 | 289 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
290 | 290 | |
291 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
292 | - $amount = __( 'Free', 'invoicing' ); |
|
291 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
292 | + $amount = __('Free', 'invoicing'); |
|
293 | 293 | $interval = $trial_interval; |
294 | 294 | $period = $trial_period; |
295 | 295 | } |
296 | 296 | |
297 | 297 | $description = ''; |
298 | - switch ( $period ) { |
|
298 | + switch ($period) { |
|
299 | 299 | case 'D' : |
300 | 300 | case 'day' : |
301 | - $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval ); |
|
301 | + $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval); |
|
302 | 302 | break; |
303 | 303 | case 'W' : |
304 | 304 | case 'week' : |
305 | - $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
305 | + $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
306 | 306 | break; |
307 | 307 | case 'M' : |
308 | 308 | case 'month' : |
309 | - $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
309 | + $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval); |
|
310 | 310 | break; |
311 | 311 | case 'Y' : |
312 | 312 | case 'year' : |
313 | - $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
313 | + $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval); |
|
314 | 314 | break; |
315 | 315 | } |
316 | 316 | |
317 | - return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval ); |
|
317 | + return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval); |
|
318 | 318 | } |
319 | 319 | |
320 | -function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) { |
|
320 | +function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) { |
|
321 | 321 | $interval = (int)$interval > 0 ? (int)$interval : 1; |
322 | 322 | $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0; |
323 | 323 | |
324 | 324 | $description = ''; |
325 | - switch ( $period ) { |
|
325 | + switch ($period) { |
|
326 | 326 | case 'D' : |
327 | 327 | case 'day' : |
328 | - if ( (int)$bill_times > 0 ) { |
|
329 | - if ( $interval > 1 ) { |
|
330 | - if ( $bill_times > 1 ) { |
|
331 | - $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
328 | + if ((int)$bill_times > 0) { |
|
329 | + if ($interval > 1) { |
|
330 | + if ($bill_times > 1) { |
|
331 | + $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
332 | 332 | } else { |
333 | - $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval ); |
|
333 | + $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval); |
|
334 | 334 | } |
335 | 335 | } else { |
336 | - $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
336 | + $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
337 | 337 | } |
338 | 338 | } else { |
339 | - $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval ); |
|
339 | + $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval); |
|
340 | 340 | } |
341 | 341 | break; |
342 | 342 | case 'W' : |
343 | 343 | case 'week' : |
344 | - if ( (int)$bill_times > 0 ) { |
|
345 | - if ( $interval > 1 ) { |
|
346 | - if ( $bill_times > 1 ) { |
|
347 | - $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
344 | + if ((int)$bill_times > 0) { |
|
345 | + if ($interval > 1) { |
|
346 | + if ($bill_times > 1) { |
|
347 | + $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
348 | 348 | } else { |
349 | - $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval ); |
|
349 | + $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval); |
|
350 | 350 | } |
351 | 351 | } else { |
352 | - $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
352 | + $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
353 | 353 | } |
354 | 354 | } else { |
355 | - $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval ); |
|
355 | + $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval); |
|
356 | 356 | } |
357 | 357 | break; |
358 | 358 | case 'M' : |
359 | 359 | case 'month' : |
360 | - if ( (int)$bill_times > 0 ) { |
|
361 | - if ( $interval > 1 ) { |
|
362 | - if ( $bill_times > 1 ) { |
|
363 | - $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
360 | + if ((int)$bill_times > 0) { |
|
361 | + if ($interval > 1) { |
|
362 | + if ($bill_times > 1) { |
|
363 | + $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
364 | 364 | } else { |
365 | - $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval ); |
|
365 | + $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval); |
|
366 | 366 | } |
367 | 367 | } else { |
368 | - $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
368 | + $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
369 | 369 | } |
370 | 370 | } else { |
371 | - $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval ); |
|
371 | + $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval); |
|
372 | 372 | } |
373 | 373 | break; |
374 | 374 | case 'Y' : |
375 | 375 | case 'year' : |
376 | - if ( (int)$bill_times > 0 ) { |
|
377 | - if ( $interval > 1 ) { |
|
378 | - if ( $bill_times > 1 ) { |
|
379 | - $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times ); |
|
376 | + if ((int)$bill_times > 0) { |
|
377 | + if ($interval > 1) { |
|
378 | + if ($bill_times > 1) { |
|
379 | + $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times); |
|
380 | 380 | } else { |
381 | - $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval ); |
|
381 | + $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval); |
|
382 | 382 | } |
383 | 383 | } else { |
384 | - $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times ); |
|
384 | + $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times); |
|
385 | 385 | } |
386 | 386 | } else { |
387 | - $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval ); |
|
387 | + $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval); |
|
388 | 388 | } |
389 | 389 | break; |
390 | 390 | } |
391 | 391 | |
392 | - return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
392 | + return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
393 | 393 | } |
394 | 394 | |
395 | -function wpinv_subscription_payment_desc( $invoice ) { |
|
396 | - if ( empty( $invoice ) ) { |
|
395 | +function wpinv_subscription_payment_desc($invoice) { |
|
396 | + if (empty($invoice)) { |
|
397 | 397 | return NULL; |
398 | 398 | } |
399 | 399 | |
400 | 400 | $description = ''; |
401 | - if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) { |
|
402 | - if ( $item->has_free_trial() ) { |
|
401 | + if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) { |
|
402 | + if ($item->has_free_trial()) { |
|
403 | 403 | $trial_period = $item->get_trial_period(); |
404 | 404 | $trial_interval = $item->get_trial_interval(); |
405 | 405 | } else { |
@@ -407,45 +407,45 @@ discard block |
||
407 | 407 | $trial_interval = 0; |
408 | 408 | } |
409 | 409 | |
410 | - $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() ); |
|
410 | + $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency()); |
|
411 | 411 | } |
412 | 412 | |
413 | - return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice ); |
|
413 | + return apply_filters('wpinv_subscription_payment_desc', $description, $invoice); |
|
414 | 414 | } |
415 | 415 | |
416 | -function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) { |
|
417 | - $initial_total = wpinv_round_amount( $initial ); |
|
418 | - $recurring_total = wpinv_round_amount( $recurring ); |
|
416 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
417 | + $initial_total = wpinv_round_amount($initial); |
|
418 | + $recurring_total = wpinv_round_amount($recurring); |
|
419 | 419 | |
420 | - if ( $trial_interval > 0 && !empty( $trial_period ) ) { |
|
420 | + if ($trial_interval > 0 && !empty($trial_period)) { |
|
421 | 421 | // Free trial |
422 | 422 | } else { |
423 | - if ( $bill_times == 1 ) { |
|
423 | + if ($bill_times == 1) { |
|
424 | 424 | $recurring_total = $initial_total; |
425 | - } else if ( $bill_times > 1 && $initial_total != $recurring_total ) { |
|
425 | + } else if ($bill_times > 1 && $initial_total != $recurring_total) { |
|
426 | 426 | $bill_times--; |
427 | 427 | } |
428 | 428 | } |
429 | 429 | |
430 | - $initial_amount = wpinv_price( wpinv_format_amount( $initial_total ), $currency ); |
|
431 | - $recurring_amount = wpinv_price( wpinv_format_amount( $recurring_total ), $currency ); |
|
430 | + $initial_amount = wpinv_price(wpinv_format_amount($initial_total), $currency); |
|
431 | + $recurring_amount = wpinv_price(wpinv_format_amount($recurring_total), $currency); |
|
432 | 432 | |
433 | - $recurring = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval ); |
|
433 | + $recurring = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval); |
|
434 | 434 | |
435 | - if ( $initial_total != $recurring_total ) { |
|
436 | - $initial = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval ); |
|
435 | + if ($initial_total != $recurring_total) { |
|
436 | + $initial = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval); |
|
437 | 437 | |
438 | - $description = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring ); |
|
438 | + $description = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring); |
|
439 | 439 | } else { |
440 | 440 | $description = $recurring; |
441 | 441 | } |
442 | 442 | |
443 | - return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency ); |
|
443 | + return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency); |
|
444 | 444 | } |
445 | 445 | |
446 | -function wpinv_recurring_send_payment_failed( $invoice ) { |
|
447 | - if ( !empty( $invoice->ID ) ) { |
|
448 | - wpinv_failed_invoice_notification( $invoice->ID ); |
|
446 | +function wpinv_recurring_send_payment_failed($invoice) { |
|
447 | + if (!empty($invoice->ID)) { |
|
448 | + wpinv_failed_invoice_notification($invoice->ID); |
|
449 | 449 | } |
450 | 450 | } |
451 | -add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 ); |
|
452 | 451 | \ No newline at end of file |
452 | +add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1); |
|
453 | 453 | \ No newline at end of file |
@@ -47,6 +47,9 @@ discard block |
||
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | + /** |
|
51 | + * @param integer $code |
|
52 | + */ |
|
50 | 53 | public function send_status( $code ) { |
51 | 54 | status_header( $code ); |
52 | 55 | } |
@@ -195,6 +198,11 @@ discard block |
||
195 | 198 | class WPInv_API_Exception extends Exception { |
196 | 199 | protected $error_code; |
197 | 200 | |
201 | + /** |
|
202 | + * @param string $error_code |
|
203 | + * @param string $error_message |
|
204 | + * @param integer $http_status_code |
|
205 | + */ |
|
198 | 206 | public function __construct( $error_code, $error_message, $http_status_code ) { |
199 | 207 | $this->error_code = $error_code; |
200 | 208 | parent::__construct( $error_message, $http_status_code ); |
@@ -7,51 +7,51 @@ 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_API { |
15 | 15 | protected $post_type = 'wpi_invoice'; |
16 | 16 | |
17 | - public function __construct( $params = array() ) { |
|
17 | + public function __construct($params = array()) { |
|
18 | 18 | } |
19 | - public function insert_invoice( $data ) { |
|
19 | + public function insert_invoice($data) { |
|
20 | 20 | global $wpdb; |
21 | 21 | //wpinv_transaction_query( 'start' ); |
22 | 22 | |
23 | 23 | try { |
24 | - if ( empty( $data['invoice'] ) ) { |
|
25 | - throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 ); |
|
24 | + if (empty($data['invoice'])) { |
|
25 | + throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400); |
|
26 | 26 | } |
27 | 27 | |
28 | - $data = apply_filters( 'wpinv_api_create_invoice_data', $data['invoice'], $this ); |
|
28 | + $data = apply_filters('wpinv_api_create_invoice_data', $data['invoice'], $this); |
|
29 | 29 | |
30 | - $invoice = wpinv_insert_invoice( $data, true ); |
|
31 | - if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) { |
|
32 | - throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 ); |
|
30 | + $invoice = wpinv_insert_invoice($data, true); |
|
31 | + if (empty($invoice->ID) || is_wp_error($invoice)) { |
|
32 | + throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | // HTTP 201 Created |
36 | - $this->send_status( 201 ); |
|
36 | + $this->send_status(201); |
|
37 | 37 | |
38 | - do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this ); |
|
38 | + do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this); |
|
39 | 39 | |
40 | 40 | //wpinv_transaction_query( 'commit' ); |
41 | 41 | |
42 | - return wpinv_get_invoice( $invoice->ID ); |
|
43 | - } catch ( WPInv_API_Exception $e ) { |
|
42 | + return wpinv_get_invoice($invoice->ID); |
|
43 | + } catch (WPInv_API_Exception $e) { |
|
44 | 44 | //wpinv_transaction_query( 'rollback' ); |
45 | 45 | |
46 | - return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) ); |
|
46 | + return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode())); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | - public function send_status( $code ) { |
|
51 | - status_header( $code ); |
|
50 | + public function send_status($code) { |
|
51 | + status_header($code); |
|
52 | 52 | } |
53 | 53 | |
54 | - protected function set_billing_details( $invoice, $data ) { |
|
54 | + protected function set_billing_details($invoice, $data) { |
|
55 | 55 | $address_fields = array( |
56 | 56 | 'user_id', |
57 | 57 | 'first_name', |
@@ -70,66 +70,66 @@ discard block |
||
70 | 70 | $billing_details = array(); |
71 | 71 | $user_id = $invoice->get_user_id(); |
72 | 72 | |
73 | - foreach ( $address_fields as $field ) { |
|
74 | - if ( isset( $data['billing_details'][ $field ] ) ) { |
|
75 | - $value = sanitize_text_field( $data['billing_details'][ $field ] ); |
|
73 | + foreach ($address_fields as $field) { |
|
74 | + if (isset($data['billing_details'][$field])) { |
|
75 | + $value = sanitize_text_field($data['billing_details'][$field]); |
|
76 | 76 | |
77 | - if ( $field == 'country' && empty( $value ) ) { |
|
78 | - if ( !empty( $invoice->country ) ) { |
|
77 | + if ($field == 'country' && empty($value)) { |
|
78 | + if (!empty($invoice->country)) { |
|
79 | 79 | $value = $invoice->country; |
80 | 80 | } else { |
81 | - $value = wpinv_default_billing_country( '', $user_id ); |
|
81 | + $value = wpinv_default_billing_country('', $user_id); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | - if ( $field == 'state' && empty( $value ) ) { |
|
86 | - if ( !empty( $invoice->state ) ) { |
|
85 | + if ($field == 'state' && empty($value)) { |
|
86 | + if (!empty($invoice->state)) { |
|
87 | 87 | $value = $invoice->state; |
88 | 88 | } else { |
89 | 89 | $value = wpinv_get_default_state(); |
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
93 | - $invoice->set( $field, $value ); |
|
93 | + $invoice->set($field, $value); |
|
94 | 94 | |
95 | - update_post_meta( $invoice->ID, '_wpinv_' . $field, $value ); |
|
95 | + update_post_meta($invoice->ID, '_wpinv_' . $field, $value); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | 99 | return $invoice; |
100 | 100 | } |
101 | 101 | |
102 | - protected function set_discount( $invoice, $data ) { |
|
103 | - if ( isset( $data['discount'] ) ) { |
|
104 | - $invoice->set( 'discount', wpinv_round_amount( $data['discount'] ) ); |
|
102 | + protected function set_discount($invoice, $data) { |
|
103 | + if (isset($data['discount'])) { |
|
104 | + $invoice->set('discount', wpinv_round_amount($data['discount'])); |
|
105 | 105 | |
106 | - update_post_meta( $invoice->ID, '_wpinv_discount', wpinv_round_amount( $data['discount'] ) ); |
|
106 | + update_post_meta($invoice->ID, '_wpinv_discount', wpinv_round_amount($data['discount'])); |
|
107 | 107 | |
108 | - if ( isset( $data['discount_code'] ) ) { |
|
109 | - $invoice->set( 'discount_code', $data['discount_code'] ); |
|
108 | + if (isset($data['discount_code'])) { |
|
109 | + $invoice->set('discount_code', $data['discount_code']); |
|
110 | 110 | |
111 | - update_post_meta( $invoice->ID, '_wpinv_discount_code', $data['discount_code'] ); |
|
111 | + update_post_meta($invoice->ID, '_wpinv_discount_code', $data['discount_code']); |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | 115 | return $invoice; |
116 | 116 | } |
117 | 117 | |
118 | - protected function set_items( $invoice, $data ) { |
|
119 | - if ( !empty( $data['items'] ) && is_array( $data['items'] ) ) { |
|
118 | + protected function set_items($invoice, $data) { |
|
119 | + if (!empty($data['items']) && is_array($data['items'])) { |
|
120 | 120 | $items_array = array(); |
121 | 121 | |
122 | - if ( !empty( $invoice->country ) ) { |
|
122 | + if (!empty($invoice->country)) { |
|
123 | 123 | $country = $invoice->country; |
124 | - } else if ( !empty( $data['billing_details']['country'] ) ) { |
|
124 | + } else if (!empty($data['billing_details']['country'])) { |
|
125 | 125 | $country = $data['billing_details']['country']; |
126 | 126 | } else { |
127 | - $country = wpinv_default_billing_country( '', $invoice->get_user_id() ); |
|
127 | + $country = wpinv_default_billing_country('', $invoice->get_user_id()); |
|
128 | 128 | } |
129 | 129 | |
130 | - if ( !empty( $invoice->state ) ) { |
|
130 | + if (!empty($invoice->state)) { |
|
131 | 131 | $state = $invoice->state; |
132 | - } else if ( !empty( $data['billing_details']['state'] ) ) { |
|
132 | + } else if (!empty($data['billing_details']['state'])) { |
|
133 | 133 | $state = $data['billing_details']['state']; |
134 | 134 | } else { |
135 | 135 | $state = wpinv_get_default_state(); |
@@ -138,54 +138,54 @@ discard block |
||
138 | 138 | $_POST['country'] = $country; |
139 | 139 | $_POST['state'] = $state; |
140 | 140 | |
141 | - $rate = wpinv_get_tax_rate( $country, $state, 'global' ); |
|
141 | + $rate = wpinv_get_tax_rate($country, $state, 'global'); |
|
142 | 142 | |
143 | 143 | $total_tax = 0; |
144 | - foreach ( $data['items'] as $item ) { |
|
145 | - $id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
146 | - $title = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : ''; |
|
147 | - $desc = isset( $item['description'] ) ? sanitize_text_field( $item['description'] ) : ''; |
|
148 | - $amount = isset( $item['amount'] ) ? wpinv_round_amount( $item['amount'] ) : 0; |
|
144 | + foreach ($data['items'] as $item) { |
|
145 | + $id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
146 | + $title = isset($item['title']) ? sanitize_text_field($item['title']) : ''; |
|
147 | + $desc = isset($item['description']) ? sanitize_text_field($item['description']) : ''; |
|
148 | + $amount = isset($item['amount']) ? wpinv_round_amount($item['amount']) : 0; |
|
149 | 149 | |
150 | - if ( !empty( $item['vat_rates_class'] ) ) { |
|
150 | + if (!empty($item['vat_rates_class'])) { |
|
151 | 151 | $vat_rates_class = $item['vat_rates_class']; |
152 | 152 | } else { |
153 | 153 | $vat_rates_class = '_standard'; |
154 | 154 | } |
155 | - $vat_rate = wpinv_get_tax_rate( $country, $state, $id ); |
|
155 | + $vat_rate = wpinv_get_tax_rate($country, $state, $id); |
|
156 | 156 | |
157 | - $tax = $amount > 0 ? ( $amount * 0.01 * (float)$vat_rate ) : 0; |
|
157 | + $tax = $amount > 0 ? ($amount * 0.01 * (float)$vat_rate) : 0; |
|
158 | 158 | $total_tax += $tax; |
159 | 159 | |
160 | 160 | $items_array[] = array( |
161 | 161 | 'id' => $id, |
162 | - 'title' => esc_html( $title ), |
|
163 | - 'description' => esc_html( $desc ), |
|
164 | - 'amount' => $amount > 0 ? wpinv_round_amount( $amount ) : 0, |
|
165 | - 'subtotal' => $amount > 0 ? wpinv_round_amount( $amount ) : 0, |
|
162 | + 'title' => esc_html($title), |
|
163 | + 'description' => esc_html($desc), |
|
164 | + 'amount' => $amount > 0 ? wpinv_round_amount($amount) : 0, |
|
165 | + 'subtotal' => $amount > 0 ? wpinv_round_amount($amount) : 0, |
|
166 | 166 | 'vat_rates_class' => $vat_rates_class, |
167 | 167 | 'vat_rate' => $vat_rate, |
168 | - 'tax' => $tax > 0 ? wpinv_round_amount( $tax ) : 0, |
|
168 | + 'tax' => $tax > 0 ? wpinv_round_amount($tax) : 0, |
|
169 | 169 | ); |
170 | 170 | } |
171 | 171 | |
172 | - update_post_meta( $invoice->ID, '_wpinv_tax', wpinv_round_amount( $total_tax ) ); |
|
173 | - $invoice->set( 'tax', wpinv_round_amount( $total_tax ) ); |
|
172 | + update_post_meta($invoice->ID, '_wpinv_tax', wpinv_round_amount($total_tax)); |
|
173 | + $invoice->set('tax', wpinv_round_amount($total_tax)); |
|
174 | 174 | |
175 | - $items_array = apply_filters( 'wpinv_save_invoice_items', $items_array, $data['items'], $invoice ); |
|
175 | + $items_array = apply_filters('wpinv_save_invoice_items', $items_array, $data['items'], $invoice); |
|
176 | 176 | |
177 | - $invoice->set( 'items', $items_array ); |
|
178 | - update_post_meta( $invoice->ID, '_wpinv_items', $items_array ); |
|
177 | + $invoice->set('items', $items_array); |
|
178 | + update_post_meta($invoice->ID, '_wpinv_items', $items_array); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | return $invoice; |
182 | 182 | } |
183 | 183 | |
184 | - protected function set_invoice_meta( $invoice_id, $invoice_meta ) { |
|
185 | - foreach ( $invoice_meta as $meta_key => $meta_value ) { |
|
184 | + protected function set_invoice_meta($invoice_id, $invoice_meta) { |
|
185 | + foreach ($invoice_meta as $meta_key => $meta_value) { |
|
186 | 186 | |
187 | - if ( is_string( $meta_key) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) { |
|
188 | - update_post_meta( $invoice_id, $meta_key, $meta_value ); |
|
187 | + if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) { |
|
188 | + update_post_meta($invoice_id, $meta_key, $meta_value); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | } |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | class WPInv_API_Exception extends Exception { |
196 | 196 | protected $error_code; |
197 | 197 | |
198 | - public function __construct( $error_code, $error_message, $http_status_code ) { |
|
198 | + public function __construct($error_code, $error_message, $http_status_code) { |
|
199 | 199 | $this->error_code = $error_code; |
200 | - parent::__construct( $error_message, $http_status_code ); |
|
200 | + parent::__construct($error_message, $http_status_code); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | public function getErrorCode() { |
@@ -11,37 +11,37 @@ |
||
11 | 11 | * @since 1.0.0 |
12 | 12 | */ |
13 | 13 | function wpinv_automatic_upgrade() { |
14 | - $wpi_version = get_option( 'wpinv_version' ); |
|
14 | + $wpi_version = get_option('wpinv_version'); |
|
15 | 15 | |
16 | - if ( $wpi_version == WPINV_VERSION ) { |
|
16 | + if ($wpi_version == WPINV_VERSION) { |
|
17 | 17 | return; |
18 | 18 | } |
19 | 19 | |
20 | - if ( version_compare( $wpi_version, '0.0.5', '<' ) ) { |
|
20 | + if (version_compare($wpi_version, '0.0.5', '<')) { |
|
21 | 21 | wpinv_v005_upgrades(); |
22 | 22 | } |
23 | 23 | |
24 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
24 | + update_option('wpinv_version', WPINV_VERSION); |
|
25 | 25 | } |
26 | -add_action( 'admin_init', 'wpinv_automatic_upgrade' ); |
|
26 | +add_action('admin_init', 'wpinv_automatic_upgrade'); |
|
27 | 27 | |
28 | 28 | function wpinv_v005_upgrades() { |
29 | 29 | global $wpdb; |
30 | 30 | |
31 | 31 | // Invoices status |
32 | - $wpdb->query( "UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
32 | + $wpdb->query("UPDATE " . $wpdb->posts . " SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )"); |
|
33 | 33 | |
34 | 34 | // Item meta key changes |
35 | 35 | $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
36 | - $results = $wpdb->get_results( $query ); |
|
36 | + $results = $wpdb->get_results($query); |
|
37 | 37 | |
38 | - if ( !empty( $results ) ) { |
|
39 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
40 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
41 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
38 | + if (!empty($results)) { |
|
39 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
40 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
41 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
42 | 42 | |
43 | - foreach ( $results as $row ) { |
|
44 | - clean_post_cache( $row->post_id ); |
|
43 | + foreach ($results as $row) { |
|
44 | + clean_post_cache($row->post_id); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | } |
48 | 48 | \ No newline at end of file |
@@ -1,22 +1,22 @@ 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 | class WPInv_Meta_Box_Items { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | global $wpinv_euvat, $ajax_cart_details; |
10 | 10 | |
11 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
12 | - $invoice = new WPInv_Invoice( $post_id ); |
|
11 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
12 | + $invoice = new WPInv_Invoice($post_id); |
|
13 | 13 | $ajax_cart_details = $invoice->get_cart_details(); |
14 | - $subtotal = $invoice->get_subtotal( true ); |
|
14 | + $subtotal = $invoice->get_subtotal(true); |
|
15 | 15 | $discount_raw = $invoice->get_discount(); |
16 | - $discount = wpinv_price( $discount_raw, $invoice->get_currency() ); |
|
16 | + $discount = wpinv_price($discount_raw, $invoice->get_currency()); |
|
17 | 17 | $discounts = $discount_raw > 0 ? $invoice->get_discounts() : ''; |
18 | - $tax = $invoice->get_tax( true ); |
|
19 | - $total = $invoice->get_total( true ); |
|
18 | + $tax = $invoice->get_tax(true); |
|
19 | + $total = $invoice->get_total(true); |
|
20 | 20 | $item_quantities = wpinv_item_quantities_enabled(); |
21 | 21 | $use_taxes = wpinv_use_taxes(); |
22 | 22 | $item_types = wpinv_get_item_types(); |
@@ -29,17 +29,17 @@ discard block |
||
29 | 29 | } |
30 | 30 | |
31 | 31 | $cols = 5; |
32 | - if ( $item_quantities ) { |
|
32 | + if ($item_quantities) { |
|
33 | 33 | $cols++; |
34 | 34 | } |
35 | - if ( $use_taxes ) { |
|
35 | + if ($use_taxes) { |
|
36 | 36 | $cols++; |
37 | 37 | } |
38 | 38 | $class = ''; |
39 | - if ( $invoice->is_paid() ) { |
|
39 | + if ($invoice->is_paid()) { |
|
40 | 40 | $class .= ' wpinv-paid'; |
41 | 41 | } |
42 | - if ( $is_recurring ) { |
|
42 | + if ($is_recurring) { |
|
43 | 43 | $class .= ' wpi-recurring'; |
44 | 44 | } |
45 | 45 | ?> |
@@ -47,21 +47,21 @@ discard block |
||
47 | 47 | <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0"> |
48 | 48 | <thead> |
49 | 49 | <tr> |
50 | - <th class="id"><?php _e( 'ID', 'invoicing' );?></th> |
|
51 | - <th class="title"><?php _e( 'Item', 'invoicing' );?></th> |
|
52 | - <th class="price"><?php _e( 'Price', 'invoicing' );?></th> |
|
53 | - <?php if ( $item_quantities ) { ?> |
|
54 | - <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th> |
|
50 | + <th class="id"><?php _e('ID', 'invoicing'); ?></th> |
|
51 | + <th class="title"><?php _e('Item', 'invoicing'); ?></th> |
|
52 | + <th class="price"><?php _e('Price', 'invoicing'); ?></th> |
|
53 | + <?php if ($item_quantities) { ?> |
|
54 | + <th class="qty"><?php _e('Qty', 'invoicing'); ?></th> |
|
55 | 55 | <?php } ?> |
56 | - <th class="total"><?php _e( 'Total', 'invoicing' );?></th> |
|
57 | - <?php if ( $use_taxes ) { ?> |
|
58 | - <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th> |
|
56 | + <th class="total"><?php _e('Total', 'invoicing'); ?></th> |
|
57 | + <?php if ($use_taxes) { ?> |
|
58 | + <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th> |
|
59 | 59 | <?php } ?> |
60 | 60 | <th class="action"></th> |
61 | 61 | </tr> |
62 | 62 | </thead> |
63 | 63 | <tbody class="wpinv-line-items"> |
64 | - <?php echo wpinv_admin_get_line_items( $invoice ); ?> |
|
64 | + <?php echo wpinv_admin_get_line_items($invoice); ?> |
|
65 | 65 | </tbody> |
66 | 66 | <tfoot class="wpinv-totals"> |
67 | 67 | <tr> |
@@ -73,44 +73,44 @@ discard block |
||
73 | 73 | </td> |
74 | 74 | <td class="title"> |
75 | 75 | <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]"> |
76 | - <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?> |
|
76 | + <?php if ($wpinv_euvat->allow_vat_rules()) { ?> |
|
77 | 77 | <div class="wp-clearfix"> |
78 | 78 | <label class="wpi-vat-rule"> |
79 | - <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span> |
|
79 | + <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span> |
|
80 | 80 | <span class="input-text-wrap"> |
81 | - <?php echo wpinv_html_select( array( |
|
81 | + <?php echo wpinv_html_select(array( |
|
82 | 82 | 'options' => $wpinv_euvat->get_rules(), |
83 | 83 | 'name' => '_wpinv_quick[vat_rule]', |
84 | 84 | 'id' => '_wpinv_quick_vat_rule', |
85 | 85 | 'show_option_all' => false, |
86 | 86 | 'show_option_none' => false, |
87 | 87 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-rule', |
88 | - ) ); ?> |
|
88 | + )); ?> |
|
89 | 89 | </span> |
90 | 90 | </label> |
91 | 91 | </div> |
92 | - <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?> |
|
92 | + <?php } if ($wpinv_euvat->allow_vat_classes()) { ?> |
|
93 | 93 | <div class="wp-clearfix"> |
94 | 94 | <label class="wpi-vat-class"> |
95 | - <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span> |
|
95 | + <span class="title"><?php _e('VAT class', 'invoicing'); ?></span> |
|
96 | 96 | <span class="input-text-wrap"> |
97 | - <?php echo wpinv_html_select( array( |
|
97 | + <?php echo wpinv_html_select(array( |
|
98 | 98 | 'options' => $wpinv_euvat->get_all_classes(), |
99 | 99 | 'name' => '_wpinv_quick[vat_class]', |
100 | 100 | 'id' => '_wpinv_quick_vat_class', |
101 | 101 | 'show_option_all' => false, |
102 | 102 | 'show_option_none' => false, |
103 | 103 | 'class' => 'gdmbx2-text-medium wpinv-quick-vat-class', |
104 | - ) ); ?> |
|
104 | + )); ?> |
|
105 | 105 | </span> |
106 | 106 | </label> |
107 | 107 | </div> |
108 | 108 | <?php } ?> |
109 | 109 | <div class="wp-clearfix"> |
110 | 110 | <label class="wpi-item-type"> |
111 | - <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
|
111 | + <span class="title"><?php _e('Item type', 'invoicing'); ?></span> |
|
112 | 112 | <span class="input-text-wrap"> |
113 | - <?php echo wpinv_html_select( array( |
|
113 | + <?php echo wpinv_html_select(array( |
|
114 | 114 | 'options' => $item_types, |
115 | 115 | 'name' => '_wpinv_quick[type]', |
116 | 116 | 'id' => '_wpinv_quick_type', |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | 'show_option_all' => false, |
119 | 119 | 'show_option_none' => false, |
120 | 120 | 'class' => 'gdmbx2-text-medium wpinv-quick-type', |
121 | - ) ); ?> |
|
121 | + )); ?> |
|
122 | 122 | </span> |
123 | 123 | </label> |
124 | 124 | </div> |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | </div> |
132 | 132 | </td> |
133 | 133 | <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td> |
134 | - <?php if ( $item_quantities ) { ?> |
|
134 | + <?php if ($item_quantities) { ?> |
|
135 | 135 | <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td> |
136 | 136 | <?php } ?> |
137 | 137 | <td class="total"></td> |
138 | - <?php if ( $use_taxes ) { ?> |
|
138 | + <?php if ($use_taxes) { ?> |
|
139 | 139 | <td class="tax"></td> |
140 | 140 | <?php } ?> |
141 | 141 | <td class="action"></td> |
@@ -148,29 +148,29 @@ discard block |
||
148 | 148 | <td colspan="<?php echo $cols; ?>"></td> |
149 | 149 | </tr> |
150 | 150 | <tr class="totals"> |
151 | - <td colspan="<?php echo ( $cols - 4 ); ?>"></td> |
|
151 | + <td colspan="<?php echo ($cols - 4); ?>"></td> |
|
152 | 152 | <td colspan="4"> |
153 | 153 | <table cellspacing="0" cellpadding="0"> |
154 | 154 | <tr class="subtotal"> |
155 | - <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td> |
|
156 | - <td class="total"><?php echo $subtotal;?></td> |
|
155 | + <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td> |
|
156 | + <td class="total"><?php echo $subtotal; ?></td> |
|
157 | 157 | <td class="action"></td> |
158 | 158 | </tr> |
159 | 159 | <tr class="discount"> |
160 | - <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td> |
|
161 | - <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td> |
|
160 | + <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td> |
|
161 | + <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td> |
|
162 | 162 | <td class="action"></td> |
163 | 163 | </tr> |
164 | - <?php if ( $use_taxes ) { ?> |
|
164 | + <?php if ($use_taxes) { ?> |
|
165 | 165 | <tr class="tax"> |
166 | - <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td> |
|
167 | - <td class="total"><?php echo $tax;?></td> |
|
166 | + <td class="name"><?php _e('Tax:', 'invoicing'); ?></td> |
|
167 | + <td class="total"><?php echo $tax; ?></td> |
|
168 | 168 | <td class="action"></td> |
169 | 169 | </tr> |
170 | 170 | <?php } ?> |
171 | 171 | <tr class="total"> |
172 | - <td class="name"><?php _e( 'Invoice Total:', 'invoicing' );?></td> |
|
173 | - <td class="total"><?php echo $total;?></td> |
|
172 | + <td class="name"><?php _e('Invoice Total:', 'invoicing'); ?></td> |
|
173 | + <td class="total"><?php echo $total; ?></td> |
|
174 | 174 | <td class="action"></td> |
175 | 175 | </tr> |
176 | 176 | </table> |
@@ -180,89 +180,89 @@ discard block |
||
180 | 180 | </table> |
181 | 181 | <div class="wpinv-actions"> |
182 | 182 | <?php |
183 | - if ( !$invoice->is_paid() ) { |
|
184 | - if ( !$invoice->is_recurring() ) { |
|
185 | - echo wpinv_item_dropdown( array( |
|
183 | + if (!$invoice->is_paid()) { |
|
184 | + if (!$invoice->is_recurring()) { |
|
185 | + echo wpinv_item_dropdown(array( |
|
186 | 186 | 'name' => 'wpinv_invoice_item', |
187 | 187 | 'id' => 'wpinv_invoice_item', |
188 | 188 | 'with_packages' => false, |
189 | 189 | 'show_recurring' => true, |
190 | - ) ); |
|
190 | + )); |
|
191 | 191 | ?> |
192 | - <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
192 | + <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals"> |
|
193 | 193 | <?php } ?> |
194 | - <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?> |
|
194 | + <?php do_action('wpinv_invoice_items_actions', $invoice); ?> |
|
195 | 195 | </div> |
196 | 196 | </div> |
197 | 197 | <?php |
198 | 198 | } |
199 | 199 | |
200 | - public static function prices( $post ) { |
|
200 | + public static function prices($post) { |
|
201 | 201 | $symbol = wpinv_currency_symbol(); |
202 | 202 | $position = wpinv_currency_position(); |
203 | - $item = new WPInv_Item( $post->ID ); |
|
203 | + $item = new WPInv_Item($post->ID); |
|
204 | 204 | |
205 | 205 | $price = $item->get_price(); |
206 | 206 | $is_recurring = $item->is_recurring(); |
207 | 207 | $period = $item->get_recurring_period(); |
208 | - $interval = absint( $item->get_recurring_interval() ); |
|
209 | - $times = absint( $item->get_recurring_limit() ); |
|
208 | + $interval = absint($item->get_recurring_interval()); |
|
209 | + $times = absint($item->get_recurring_limit()); |
|
210 | 210 | $free_trial = $item->has_free_trial(); |
211 | 211 | $trial_interval = $item->get_trial_interval(); |
212 | 212 | $trial_period = $item->get_trial_period(); |
213 | 213 | |
214 | 214 | $intervals = array(); |
215 | - for ( $i = 1; $i <= 90; $i++ ) { |
|
215 | + for ($i = 1; $i <= 90; $i++) { |
|
216 | 216 | $intervals[$i] = $i; |
217 | 217 | } |
218 | 218 | |
219 | - $interval = $interval > 0 ? $interval : 1; |
|
219 | + $interval = $interval > 0 ? $interval : 1; |
|
220 | 220 | |
221 | 221 | $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n'; |
222 | 222 | ?> |
223 | - <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_package(), true ); ?> /><?php echo ( $position == 'right' ? ' ' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" /> |
|
224 | - <?php if ( $item->is_package() ) { ?> |
|
225 | - <span class="description"><?php _e( 'GD package item price can be edited only from GD payment manager.', 'invoicing' ); ?></span> |
|
223 | + <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_package(), true); ?> /><?php echo ($position == 'right' ? ' ' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" /> |
|
224 | + <?php if ($item->is_package()) { ?> |
|
225 | + <span class="description"><?php _e('GD package item price can be edited only from GD payment manager.', 'invoicing'); ?></span> |
|
226 | 226 | <?php } ?> |
227 | 227 | </p> |
228 | 228 | <p class="wpinv-row-is-recurring"> |
229 | 229 | <label for="wpinv_is_recurring"> |
230 | - <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> /> |
|
231 | - <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?> |
|
230 | + <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> /> |
|
231 | + <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?> |
|
232 | 232 | </label> |
233 | 233 | </p> |
234 | - <p class="wpinv-row-recurring-fields <?php echo $class;?>"> |
|
235 | - <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label> |
|
236 | - <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array( |
|
234 | + <p class="wpinv-row-recurring-fields <?php echo $class; ?>"> |
|
235 | + <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label> |
|
236 | + <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array( |
|
237 | 237 | 'options' => $intervals, |
238 | 238 | 'name' => 'wpinv_recurring_interval', |
239 | 239 | 'id' => 'wpinv_recurring_interval', |
240 | 240 | 'selected' => $interval, |
241 | 241 | 'show_option_all' => false, |
242 | 242 | 'show_option_none' => false |
243 | - ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label> |
|
244 | - <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label> |
|
243 | + )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label> |
|
244 | + <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label> |
|
245 | 245 | <span class="clear wpi-trial-clr"></span> |
246 | 246 | <label class="wpinv-free-trial" for="wpinv_free_trial"> |
247 | - <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> |
|
248 | - <?php echo __( 'Offer free trial for', 'invoicing' ); ?> |
|
247 | + <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> |
|
248 | + <?php echo __('Offer free trial for', 'invoicing'); ?> |
|
249 | 249 | </label> |
250 | 250 | <label class="wpinv-trial-interval" for="wpinv_trial_interval"> |
251 | - <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select> |
|
251 | + <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select> |
|
252 | 252 | </label> |
253 | 253 | </p> |
254 | - <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" /> |
|
255 | - <?php do_action( 'wpinv_item_price_field', $post->ID ); ?> |
|
254 | + <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" /> |
|
255 | + <?php do_action('wpinv_item_price_field', $post->ID); ?> |
|
256 | 256 | <?php |
257 | 257 | } |
258 | 258 | |
259 | - public static function vat_rules( $post ) { |
|
259 | + public static function vat_rules($post) { |
|
260 | 260 | global $wpinv_euvat; |
261 | 261 | |
262 | - $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); |
|
262 | + $rule_type = $wpinv_euvat->get_item_rule($post->ID); |
|
263 | 263 | ?> |
264 | - <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label> |
|
265 | - <?php echo wpinv_html_select( array( |
|
264 | + <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label> |
|
265 | + <?php echo wpinv_html_select(array( |
|
266 | 266 | 'options' => $wpinv_euvat->get_rules(), |
267 | 267 | 'name' => 'wpinv_vat_rules', |
268 | 268 | 'id' => 'wpinv_vat_rules', |
@@ -270,19 +270,19 @@ discard block |
||
270 | 270 | 'show_option_all' => false, |
271 | 271 | 'show_option_none' => false, |
272 | 272 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules', |
273 | - ) ); ?> |
|
273 | + )); ?> |
|
274 | 274 | </p> |
275 | - <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p> |
|
276 | - <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p> |
|
275 | + <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT. The VAT rate used will be the rate in your country.', 'invoicing'); ?></p> |
|
276 | + <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer. Only businesses in your country will be charged VAT.', 'invoicing'); ?></p> |
|
277 | 277 | <?php |
278 | 278 | } |
279 | 279 | |
280 | - public static function vat_classes( $post ) { |
|
280 | + public static function vat_classes($post) { |
|
281 | 281 | global $wpinv_euvat; |
282 | 282 | |
283 | - $vat_class = $wpinv_euvat->get_item_class( $post->ID ); |
|
283 | + $vat_class = $wpinv_euvat->get_item_class($post->ID); |
|
284 | 284 | ?> |
285 | - <p><?php echo wpinv_html_select( array( |
|
285 | + <p><?php echo wpinv_html_select(array( |
|
286 | 286 | 'options' => $wpinv_euvat->get_all_classes(), |
287 | 287 | 'name' => 'wpinv_vat_class', |
288 | 288 | 'id' => 'wpinv_vat_class', |
@@ -290,18 +290,18 @@ discard block |
||
290 | 290 | 'show_option_all' => false, |
291 | 291 | 'show_option_none' => false, |
292 | 292 | 'class' => 'gdmbx2-text-medium wpinv-vat-class', |
293 | - ) ); ?> |
|
293 | + )); ?> |
|
294 | 294 | </p> |
295 | - <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p> |
|
295 | + <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p> |
|
296 | 296 | <?php |
297 | 297 | } |
298 | 298 | |
299 | - public static function item_info( $post ) { |
|
300 | - $item_type = wpinv_get_item_type( $post->ID ); |
|
301 | - do_action( 'wpinv_item_info_metabox_before', $post ); |
|
299 | + public static function item_info($post) { |
|
300 | + $item_type = wpinv_get_item_type($post->ID); |
|
301 | + do_action('wpinv_item_info_metabox_before', $post); |
|
302 | 302 | ?> |
303 | - <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label> |
|
304 | - <?php echo wpinv_html_select( array( |
|
303 | + <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label> |
|
304 | + <?php echo wpinv_html_select(array( |
|
305 | 305 | 'options' => wpinv_get_item_types(), |
306 | 306 | 'name' => 'wpinv_item_type', |
307 | 307 | 'id' => 'wpinv_item_type', |
@@ -310,114 +310,114 @@ discard block |
||
310 | 310 | 'show_option_none' => false, |
311 | 311 | 'class' => 'gdmbx2-text-medium wpinv-item-type', |
312 | 312 | //'disabled' => $item_type == 'package' ? true : false, |
313 | - ) ); ?> |
|
313 | + )); ?> |
|
314 | 314 | </p> |
315 | - <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( 'Standard: standard item type', 'invoicing' );?><br><?php _e( 'Fee: like Registration Fee, Signup Fee etc.', 'invoicing' );?></p> |
|
315 | + <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('Standard: standard item type', 'invoicing'); ?><br><?php _e('Fee: like Registration Fee, Signup Fee etc.', 'invoicing'); ?></p> |
|
316 | 316 | <?php |
317 | - do_action( 'wpinv_item_info_metabox_after', $post ); |
|
317 | + do_action('wpinv_item_info_metabox_after', $post); |
|
318 | 318 | } |
319 | 319 | |
320 | - public static function meta_values( $post ) { |
|
321 | - $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array( |
|
320 | + public static function meta_values($post) { |
|
321 | + $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array( |
|
322 | 322 | 'type', |
323 | 323 | 'custom_id' |
324 | - ) ); |
|
324 | + )); |
|
325 | 325 | |
326 | - if ( empty( $meta_keys ) ) { |
|
326 | + if (empty($meta_keys)) { |
|
327 | 327 | return; |
328 | 328 | } |
329 | 329 | |
330 | - do_action( 'wpinv_meta_values_metabox_before', $post ); |
|
330 | + do_action('wpinv_meta_values_metabox_before', $post); |
|
331 | 331 | |
332 | - foreach ( $meta_keys as $meta_key ) { |
|
332 | + foreach ($meta_keys as $meta_key) { |
|
333 | 333 | ?> |
334 | - <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p> |
|
334 | + <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p> |
|
335 | 335 | <?php |
336 | 336 | } |
337 | 337 | |
338 | - do_action( 'wpinv_meta_values_metabox_after', $post ); |
|
338 | + do_action('wpinv_meta_values_metabox_after', $post); |
|
339 | 339 | } |
340 | 340 | |
341 | - public static function save( $post_id, $data, $post ) { |
|
342 | - $invoice = new WPInv_Invoice( $post_id ); |
|
341 | + public static function save($post_id, $data, $post) { |
|
342 | + $invoice = new WPInv_Invoice($post_id); |
|
343 | 343 | |
344 | 344 | // Billing |
345 | - $first_name = sanitize_text_field( $data['wpinv_first_name'] ); |
|
346 | - $last_name = sanitize_text_field( $data['wpinv_last_name'] ); |
|
347 | - $company = sanitize_text_field( $data['wpinv_company'] ); |
|
348 | - $vat_number = sanitize_text_field( $data['wpinv_vat_number'] ); |
|
349 | - $phone = sanitize_text_field( $data['wpinv_phone'] ); |
|
350 | - $address = sanitize_text_field( $data['wpinv_address'] ); |
|
351 | - $city = sanitize_text_field( $data['wpinv_city'] ); |
|
352 | - $zip = sanitize_text_field( $data['wpinv_zip'] ); |
|
353 | - $country = sanitize_text_field( $data['wpinv_country'] ); |
|
354 | - $state = sanitize_text_field( $data['wpinv_state'] ); |
|
345 | + $first_name = sanitize_text_field($data['wpinv_first_name']); |
|
346 | + $last_name = sanitize_text_field($data['wpinv_last_name']); |
|
347 | + $company = sanitize_text_field($data['wpinv_company']); |
|
348 | + $vat_number = sanitize_text_field($data['wpinv_vat_number']); |
|
349 | + $phone = sanitize_text_field($data['wpinv_phone']); |
|
350 | + $address = sanitize_text_field($data['wpinv_address']); |
|
351 | + $city = sanitize_text_field($data['wpinv_city']); |
|
352 | + $zip = sanitize_text_field($data['wpinv_zip']); |
|
353 | + $country = sanitize_text_field($data['wpinv_country']); |
|
354 | + $state = sanitize_text_field($data['wpinv_state']); |
|
355 | 355 | |
356 | 356 | // Details |
357 | - $status = sanitize_text_field( $data['wpinv_status'] ); |
|
358 | - $old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status; |
|
359 | - $number = sanitize_text_field( $data['wpinv_number'] ); |
|
360 | - $due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : ''; |
|
357 | + $status = sanitize_text_field($data['wpinv_status']); |
|
358 | + $old_status = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status; |
|
359 | + $number = sanitize_text_field($data['wpinv_number']); |
|
360 | + $due_date = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : ''; |
|
361 | 361 | //$discounts = sanitize_text_field( $data['wpinv_discounts'] ); |
362 | 362 | //$discount = sanitize_text_field( $data['wpinv_discount'] ); |
363 | 363 | |
364 | - $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
364 | + $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
365 | 365 | |
366 | - $invoice->set( 'due_date', $due_date ); |
|
367 | - $invoice->set( 'first_name', $first_name ); |
|
368 | - $invoice->set( 'last_name', $last_name ); |
|
369 | - $invoice->set( 'company', $company ); |
|
370 | - $invoice->set( 'vat_number', $vat_number ); |
|
371 | - $invoice->set( 'phone', $phone ); |
|
372 | - $invoice->set( 'address', $address ); |
|
373 | - $invoice->set( 'city', $city ); |
|
374 | - $invoice->set( 'zip', $zip ); |
|
375 | - $invoice->set( 'country', $country ); |
|
376 | - $invoice->set( 'state', $state ); |
|
377 | - $invoice->set( 'status', $status ); |
|
378 | - $invoice->set( 'number', $number ); |
|
366 | + $invoice->set('due_date', $due_date); |
|
367 | + $invoice->set('first_name', $first_name); |
|
368 | + $invoice->set('last_name', $last_name); |
|
369 | + $invoice->set('company', $company); |
|
370 | + $invoice->set('vat_number', $vat_number); |
|
371 | + $invoice->set('phone', $phone); |
|
372 | + $invoice->set('address', $address); |
|
373 | + $invoice->set('city', $city); |
|
374 | + $invoice->set('zip', $zip); |
|
375 | + $invoice->set('country', $country); |
|
376 | + $invoice->set('state', $state); |
|
377 | + $invoice->set('status', $status); |
|
378 | + $invoice->set('number', $number); |
|
379 | 379 | //$invoice->set( 'discounts', $discounts ); |
380 | 380 | //$invoice->set( 'discount', $discount ); |
381 | - $invoice->set( 'ip', $ip ); |
|
381 | + $invoice->set('ip', $ip); |
|
382 | 382 | $invoice->old_status = $_POST['original_post_status']; |
383 | 383 | $invoice->currency = wpinv_get_currency(); |
384 | - if ( !empty( $data['wpinv_gateway'] ) ) { |
|
385 | - $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) ); |
|
384 | + if (!empty($data['wpinv_gateway'])) { |
|
385 | + $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway'])); |
|
386 | 386 | } |
387 | 387 | $saved = $invoice->save(); |
388 | 388 | |
389 | 389 | // Check for payment notes |
390 | - if ( !empty( $data['invoice_note'] ) ) { |
|
391 | - $note = wp_kses( $data['invoice_note'], array() ); |
|
392 | - $note_type = sanitize_text_field( $data['invoice_note_type'] ); |
|
390 | + if (!empty($data['invoice_note'])) { |
|
391 | + $note = wp_kses($data['invoice_note'], array()); |
|
392 | + $note_type = sanitize_text_field($data['invoice_note_type']); |
|
393 | 393 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
394 | 394 | |
395 | - wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note ); |
|
395 | + wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | // Update user address if empty. |
399 | - if ( $saved && !empty( $invoice ) ) { |
|
400 | - if ( $user_id = $invoice->get_user_id() ) { |
|
401 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
399 | + if ($saved && !empty($invoice)) { |
|
400 | + if ($user_id = $invoice->get_user_id()) { |
|
401 | + $user_address = wpinv_get_user_address($user_id, false); |
|
402 | 402 | |
403 | 403 | if (empty($user_address['first_name'])) { |
404 | - update_user_meta( $user_id, '_wpinv_first_name', $first_name ); |
|
405 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
404 | + update_user_meta($user_id, '_wpinv_first_name', $first_name); |
|
405 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
406 | 406 | } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { |
407 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
407 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { |
411 | - update_user_meta( $user_id, '_wpinv_address', $address ); |
|
412 | - update_user_meta( $user_id, '_wpinv_city', $city ); |
|
413 | - update_user_meta( $user_id, '_wpinv_state', $state ); |
|
414 | - update_user_meta( $user_id, '_wpinv_country', $country ); |
|
415 | - update_user_meta( $user_id, '_wpinv_zip', $zip ); |
|
416 | - update_user_meta( $user_id, '_wpinv_phone', $phone ); |
|
411 | + update_user_meta($user_id, '_wpinv_address', $address); |
|
412 | + update_user_meta($user_id, '_wpinv_city', $city); |
|
413 | + update_user_meta($user_id, '_wpinv_state', $state); |
|
414 | + update_user_meta($user_id, '_wpinv_country', $country); |
|
415 | + update_user_meta($user_id, '_wpinv_zip', $zip); |
|
416 | + update_user_meta($user_id, '_wpinv_phone', $phone); |
|
417 | 417 | } |
418 | 418 | } |
419 | 419 | |
420 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
420 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
421 | 421 | } |
422 | 422 | |
423 | 423 | return $saved; |
@@ -1,65 +1,65 @@ 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 | -function wpinv_add_meta_boxes( $post_type, $post ) { |
|
7 | +function wpinv_add_meta_boxes($post_type, $post) { |
|
8 | 8 | global $wpi_mb_invoice; |
9 | - if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) { |
|
10 | - $wpi_mb_invoice = wpinv_get_invoice( $post->ID ); |
|
9 | + if ($post_type == 'wpi_invoice' && !empty($post->ID)) { |
|
10 | + $wpi_mb_invoice = wpinv_get_invoice($post->ID); |
|
11 | 11 | } |
12 | 12 | |
13 | - if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) { |
|
14 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' ); |
|
13 | + if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) { |
|
14 | + add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high'); |
|
15 | 15 | } |
16 | 16 | |
17 | - if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) { |
|
18 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' ); |
|
17 | + if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) { |
|
18 | + add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high'); |
|
19 | 19 | } |
20 | 20 | |
21 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
22 | - add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' ); |
|
21 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
22 | + add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high'); |
|
23 | 23 | } |
24 | 24 | |
25 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
26 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' ); |
|
25 | + add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default'); |
|
26 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default'); |
|
27 | 27 | |
28 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' ); |
|
29 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
30 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
28 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high'); |
|
29 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
30 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high'); |
|
31 | 31 | } |
32 | -add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
|
32 | +add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2); |
|
33 | 33 | |
34 | -function wpinv_save_meta_boxes( $post_id, $post, $update = false ) { |
|
35 | - remove_action( 'save_post', __FUNCTION__ ); |
|
34 | +function wpinv_save_meta_boxes($post_id, $post, $update = false) { |
|
35 | + remove_action('save_post', __FUNCTION__); |
|
36 | 36 | |
37 | 37 | // $post_id and $post are required |
38 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
38 | + if (empty($post_id) || empty($post)) { |
|
39 | 39 | return; |
40 | 40 | } |
41 | 41 | |
42 | - if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) { |
|
42 | + if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) { |
|
43 | 43 | return; |
44 | 44 | } |
45 | 45 | |
46 | 46 | // Dont' save meta boxes for revisions or autosaves |
47 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
47 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
48 | 48 | return; |
49 | 49 | } |
50 | 50 | |
51 | - if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) { |
|
52 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
51 | + if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') { |
|
52 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | - if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) { |
|
57 | - WPInv_Meta_Box_Items::save( $post_id, $_POST, $post ); |
|
56 | + if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) { |
|
57 | + WPInv_Meta_Box_Items::save($post_id, $_POST, $post); |
|
58 | 58 | } |
59 | - } else if ( $post->post_type == 'wpi_item' ) { |
|
59 | + } else if ($post->post_type == 'wpi_item') { |
|
60 | 60 | // verify nonce |
61 | - if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) { |
|
62 | - $fields = array(); |
|
61 | + if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) { |
|
62 | + $fields = array(); |
|
63 | 63 | $fields['_wpinv_price'] = 'wpinv_item_price'; |
64 | 64 | $fields['_wpinv_vat_class'] = 'wpinv_vat_class'; |
65 | 65 | $fields['_wpinv_vat_rule'] = 'wpinv_vat_rules'; |
@@ -72,296 +72,296 @@ discard block |
||
72 | 72 | $fields['_wpinv_trial_period'] = 'wpinv_trial_period'; |
73 | 73 | $fields['_wpinv_trial_interval'] = 'wpinv_trial_interval'; |
74 | 74 | |
75 | - if ( !isset( $_POST['wpinv_is_recurring'] ) ) { |
|
75 | + if (!isset($_POST['wpinv_is_recurring'])) { |
|
76 | 76 | $_POST['wpinv_is_recurring'] = 0; |
77 | 77 | } |
78 | 78 | |
79 | - if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) { |
|
79 | + if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) { |
|
80 | 80 | $_POST['wpinv_free_trial'] = 0; |
81 | 81 | } |
82 | 82 | |
83 | - foreach ( $fields as $field => $name ) { |
|
84 | - if ( isset( $_POST[ $name ] ) ) { |
|
85 | - if ( $field == '_wpinv_price' ) { |
|
86 | - if ( get_post_meta( $post_id, '_wpinv_type', true ) === 'package' ) { |
|
87 | - $value = wpinv_sanitize_amount( get_post_meta( $post_id, '_wpinv_price', true ) ); // Don't allow edit GD package item price. |
|
83 | + foreach ($fields as $field => $name) { |
|
84 | + if (isset($_POST[$name])) { |
|
85 | + if ($field == '_wpinv_price') { |
|
86 | + if (get_post_meta($post_id, '_wpinv_type', true) === 'package') { |
|
87 | + $value = wpinv_sanitize_amount(get_post_meta($post_id, '_wpinv_price', true)); // Don't allow edit GD package item price. |
|
88 | 88 | } else { |
89 | - $value = wpinv_sanitize_amount( $_POST[ $name ] ); |
|
89 | + $value = wpinv_sanitize_amount($_POST[$name]); |
|
90 | 90 | } |
91 | 91 | } else { |
92 | - $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ]; |
|
92 | + $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name]; |
|
93 | 93 | } |
94 | 94 | |
95 | - $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name ); |
|
96 | - update_post_meta( $post_id, $field, $value ); |
|
95 | + $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name); |
|
96 | + update_post_meta($post_id, $field, $value); |
|
97 | 97 | } |
98 | 98 | } |
99 | 99 | |
100 | - if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) { |
|
101 | - update_post_meta( $post_id, '_wpinv_custom_id', $post_id ); |
|
100 | + if (!get_post_meta($post_id, '_wpinv_custom_id', true)) { |
|
101 | + update_post_meta($post_id, '_wpinv_custom_id', $post_id); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 | } |
105 | 105 | } |
106 | -add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 ); |
|
106 | +add_action('save_post', 'wpinv_save_meta_boxes', 10, 3); |
|
107 | 107 | |
108 | -function wpinv_bulk_and_quick_edit_save( $post_id, $post, $update = false ) { |
|
109 | - if ( !( !empty( $_POST['action'] ) && $_POST['action'] == 'inline-save' ) ) { |
|
108 | +function wpinv_bulk_and_quick_edit_save($post_id, $post, $update = false) { |
|
109 | + if (!(!empty($_POST['action']) && $_POST['action'] == 'inline-save')) { |
|
110 | 110 | return; |
111 | 111 | } |
112 | 112 | |
113 | 113 | // $post_id and $post are required |
114 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
114 | + if (empty($post_id) || empty($post)) { |
|
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
118 | - if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) { |
|
118 | + if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) { |
|
119 | 119 | return; |
120 | 120 | } |
121 | 121 | |
122 | 122 | // Dont' save meta boxes for revisions or autosaves |
123 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
123 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | - if ( $post->post_type == 'wpi_item' ) { |
|
127 | + if ($post->post_type == 'wpi_item') { |
|
128 | 128 | // verify nonce |
129 | - if ( isset( $_POST['_wpinv_item_price'] ) && get_post_meta( $post->ID, '_wpinv_type', true ) !== 'package' ) { |
|
130 | - update_post_meta( $post_id, '_wpinv_price', wpinv_sanitize_amount( $_POST['_wpinv_item_price'] ) ); |
|
129 | + if (isset($_POST['_wpinv_item_price']) && get_post_meta($post->ID, '_wpinv_type', true) !== 'package') { |
|
130 | + update_post_meta($post_id, '_wpinv_price', wpinv_sanitize_amount($_POST['_wpinv_item_price'])); |
|
131 | 131 | } |
132 | 132 | |
133 | - if ( isset( $_POST['_wpinv_vat_class'] ) ) { |
|
134 | - update_post_meta( $post_id, '_wpinv_vat_class', sanitize_text_field( $_POST['_wpinv_vat_class'] ) ); |
|
133 | + if (isset($_POST['_wpinv_vat_class'])) { |
|
134 | + update_post_meta($post_id, '_wpinv_vat_class', sanitize_text_field($_POST['_wpinv_vat_class'])); |
|
135 | 135 | } |
136 | 136 | |
137 | - if ( isset( $_POST['_wpinv_vat_rules'] ) ) { |
|
138 | - update_post_meta( $post_id, '_wpinv_vat_rule', sanitize_text_field( $_POST['_wpinv_vat_rules'] ) ); |
|
137 | + if (isset($_POST['_wpinv_vat_rules'])) { |
|
138 | + update_post_meta($post_id, '_wpinv_vat_rule', sanitize_text_field($_POST['_wpinv_vat_rules'])); |
|
139 | 139 | } |
140 | 140 | |
141 | - if ( isset( $_POST['_wpinv_item_type'] ) ) { |
|
142 | - update_post_meta( $post_id, '_wpinv_type', sanitize_text_field( $_POST['_wpinv_item_type'] ) ); |
|
141 | + if (isset($_POST['_wpinv_item_type'])) { |
|
142 | + update_post_meta($post_id, '_wpinv_type', sanitize_text_field($_POST['_wpinv_item_type'])); |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | } |
146 | -add_action( 'save_post', 'wpinv_bulk_and_quick_edit_save', 10, 3 ); |
|
146 | +add_action('save_post', 'wpinv_bulk_and_quick_edit_save', 10, 3); |
|
147 | 147 | |
148 | 148 | function wpinv_register_item_meta_boxes() { |
149 | 149 | global $wpinv_euvat; |
150 | 150 | |
151 | - add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' ); |
|
151 | + add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high'); |
|
152 | 152 | |
153 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
154 | - add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' ); |
|
153 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
154 | + add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high'); |
|
155 | 155 | } |
156 | 156 | |
157 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
158 | - add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' ); |
|
157 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
158 | + add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high'); |
|
159 | 159 | } |
160 | 160 | |
161 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' ); |
|
162 | - add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' ); |
|
161 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core'); |
|
162 | + add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core'); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | function wpinv_register_discount_meta_boxes() { |
166 | - add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' ); |
|
166 | + add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high'); |
|
167 | 167 | } |
168 | 168 | |
169 | -function wpinv_discount_metabox_details( $post ) { |
|
169 | +function wpinv_discount_metabox_details($post) { |
|
170 | 170 | $discount_id = $post->ID; |
171 | - $discount = wpinv_get_discount( $discount_id ); |
|
171 | + $discount = wpinv_get_discount($discount_id); |
|
172 | 172 | |
173 | - $type = wpinv_get_discount_type( $discount_id ); |
|
174 | - $item_reqs = wpinv_get_discount_item_reqs( $discount_id ); |
|
175 | - $excluded_items = wpinv_get_discount_excluded_items( $discount_id ); |
|
176 | - $min_total = wpinv_get_discount_min_total( $discount_id ); |
|
177 | - $max_total = wpinv_get_discount_max_total( $discount_id ); |
|
178 | - $max_uses = wpinv_get_discount_max_uses( $discount_id ); |
|
179 | - $single_use = wpinv_discount_is_single_use( $discount_id ); |
|
180 | - $recurring = (bool)wpinv_discount_is_recurring( $discount_id ); |
|
173 | + $type = wpinv_get_discount_type($discount_id); |
|
174 | + $item_reqs = wpinv_get_discount_item_reqs($discount_id); |
|
175 | + $excluded_items = wpinv_get_discount_excluded_items($discount_id); |
|
176 | + $min_total = wpinv_get_discount_min_total($discount_id); |
|
177 | + $max_total = wpinv_get_discount_max_total($discount_id); |
|
178 | + $max_uses = wpinv_get_discount_max_uses($discount_id); |
|
179 | + $single_use = wpinv_discount_is_single_use($discount_id); |
|
180 | + $recurring = (bool)wpinv_discount_is_recurring($discount_id); |
|
181 | 181 | |
182 | 182 | $min_total = $min_total > 0 ? $min_total : ''; |
183 | 183 | $max_total = $max_total > 0 ? $max_total : ''; |
184 | 184 | $max_uses = $max_uses > 0 ? $max_uses : ''; |
185 | 185 | ?> |
186 | -<?php do_action( 'wpinv_discount_form_top', $post ); ?> |
|
187 | -<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?> |
|
186 | +<?php do_action('wpinv_discount_form_top', $post); ?> |
|
187 | +<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?> |
|
188 | 188 | <table class="form-table wpi-form-table"> |
189 | 189 | <tbody> |
190 | - <?php do_action( 'wpinv_discount_form_first', $post ); ?> |
|
191 | - <?php do_action( 'wpinv_discount_form_before_code', $post ); ?> |
|
190 | + <?php do_action('wpinv_discount_form_first', $post); ?> |
|
191 | + <?php do_action('wpinv_discount_form_before_code', $post); ?> |
|
192 | 192 | <tr> |
193 | 193 | <th valign="top" scope="row"> |
194 | - <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label> |
|
194 | + <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label> |
|
195 | 195 | </th> |
196 | 196 | <td> |
197 | - <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required> |
|
198 | - <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p> |
|
197 | + <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required> |
|
198 | + <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p> |
|
199 | 199 | </td> |
200 | 200 | </tr> |
201 | - <?php do_action( 'wpinv_discount_form_before_type', $post ); ?> |
|
201 | + <?php do_action('wpinv_discount_form_before_type', $post); ?> |
|
202 | 202 | <tr> |
203 | 203 | <th valign="top" scope="row"> |
204 | - <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label> |
|
204 | + <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label> |
|
205 | 205 | </th> |
206 | 206 | <td> |
207 | 207 | <select id="wpinv_discount_type" name="type" class="medium-text"> |
208 | - <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?> |
|
209 | - <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option> |
|
208 | + <?php foreach (wpinv_get_discount_types() as $value => $label) { ?> |
|
209 | + <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option> |
|
210 | 210 | <?php } ?> |
211 | 211 | </select> |
212 | - <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p> |
|
212 | + <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p> |
|
213 | 213 | </td> |
214 | 214 | </tr> |
215 | - <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?> |
|
215 | + <?php do_action('wpinv_discount_form_before_amount', $post); ?> |
|
216 | 216 | <tr> |
217 | 217 | <th valign="top" scope="row"> |
218 | - <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label> |
|
218 | + <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label> |
|
219 | 219 | </th> |
220 | 220 | <td> |
221 | - <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font> |
|
222 | - <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p> |
|
223 | - <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p> |
|
221 | + <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font> |
|
222 | + <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p> |
|
223 | + <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p> |
|
224 | 224 | </td> |
225 | 225 | </tr> |
226 | - <?php do_action( 'wpinv_discount_form_before_items', $post ); ?> |
|
226 | + <?php do_action('wpinv_discount_form_before_items', $post); ?> |
|
227 | 227 | <tr> |
228 | 228 | <th valign="top" scope="row"> |
229 | - <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label> |
|
229 | + <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label> |
|
230 | 230 | </th> |
231 | 231 | <td> |
232 | - <p><?php echo wpinv_item_dropdown( array( |
|
232 | + <p><?php echo wpinv_item_dropdown(array( |
|
233 | 233 | 'name' => 'items[]', |
234 | 234 | 'id' => 'items', |
235 | 235 | 'selected' => $item_reqs, |
236 | 236 | 'multiple' => true, |
237 | 237 | 'chosen' => true, |
238 | 238 | 'class' => 'medium-text', |
239 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
239 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
240 | 240 | 'show_recurring' => true, |
241 | - ) ); ?> |
|
241 | + )); ?> |
|
242 | 242 | </p> |
243 | - <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p> |
|
243 | + <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p> |
|
244 | 244 | </td> |
245 | 245 | </tr> |
246 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?> |
|
246 | + <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?> |
|
247 | 247 | <tr> |
248 | 248 | <th valign="top" scope="row"> |
249 | - <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label> |
|
249 | + <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label> |
|
250 | 250 | </th> |
251 | 251 | <td> |
252 | - <p><?php echo wpinv_item_dropdown( array( |
|
252 | + <p><?php echo wpinv_item_dropdown(array( |
|
253 | 253 | 'name' => 'excluded_items[]', |
254 | 254 | 'id' => 'excluded_items', |
255 | 255 | 'selected' => $excluded_items, |
256 | 256 | 'multiple' => true, |
257 | 257 | 'chosen' => true, |
258 | 258 | 'class' => 'medium-text', |
259 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
259 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
260 | 260 | 'show_recurring' => true, |
261 | - ) ); ?> |
|
261 | + )); ?> |
|
262 | 262 | </p> |
263 | - <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p> |
|
263 | + <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p> |
|
264 | 264 | </td> |
265 | 265 | </tr> |
266 | - <?php do_action( 'wpinv_discount_form_before_start', $post ); ?> |
|
266 | + <?php do_action('wpinv_discount_form_before_start', $post); ?> |
|
267 | 267 | <tr> |
268 | 268 | <th valign="top" scope="row"> |
269 | - <label for="wpinv_discount_start"><?php _e( 'Start date', 'invoicing' ); ?></label> |
|
269 | + <label for="wpinv_discount_start"><?php _e('Start date', 'invoicing'); ?></label> |
|
270 | 270 | </th> |
271 | 271 | <td> |
272 | - <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( wpinv_get_discount_start_date( $discount_id ) ); ?>"> |
|
273 | - <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p> |
|
272 | + <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr(wpinv_get_discount_start_date($discount_id)); ?>"> |
|
273 | + <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p> |
|
274 | 274 | </td> |
275 | 275 | </tr> |
276 | - <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?> |
|
276 | + <?php do_action('wpinv_discount_form_before_expiration', $post); ?> |
|
277 | 277 | <tr> |
278 | 278 | <th valign="top" scope="row"> |
279 | - <label for="wpinv_discount_expiration"><?php _e( 'Expiration date', 'invoicing' ); ?></label> |
|
279 | + <label for="wpinv_discount_expiration"><?php _e('Expiration date', 'invoicing'); ?></label> |
|
280 | 280 | </th> |
281 | 281 | <td> |
282 | - <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( wpinv_get_discount_expiration( $discount_id ) ); ?>"> |
|
283 | - <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p> |
|
282 | + <input type="text" class="medium-text wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr(wpinv_get_discount_expiration($discount_id)); ?>"> |
|
283 | + <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p> |
|
284 | 284 | </td> |
285 | 285 | </tr> |
286 | - <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?> |
|
286 | + <?php do_action('wpinv_discount_form_before_min_total', $post); ?> |
|
287 | 287 | <tr> |
288 | 288 | <th valign="top" scope="row"> |
289 | - <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label> |
|
289 | + <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label> |
|
290 | 290 | </th> |
291 | 291 | <td> |
292 | 292 | <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>"> |
293 | - <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
293 | + <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
294 | 294 | </td> |
295 | 295 | </tr> |
296 | - <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?> |
|
296 | + <?php do_action('wpinv_discount_form_before_max_total', $post); ?> |
|
297 | 297 | <tr> |
298 | 298 | <th valign="top" scope="row"> |
299 | - <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label> |
|
299 | + <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label> |
|
300 | 300 | </th> |
301 | 301 | <td> |
302 | 302 | <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>"> |
303 | - <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
303 | + <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
304 | 304 | </td> |
305 | 305 | </tr> |
306 | - <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?> |
|
306 | + <?php do_action('wpinv_discount_form_before_recurring', $post); ?> |
|
307 | 307 | <tr> |
308 | 308 | <th valign="top" scope="row"> |
309 | - <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label> |
|
309 | + <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label> |
|
310 | 310 | </th> |
311 | 311 | <td> |
312 | 312 | <select id="wpinv_discount_recurring" name="recurring" class="medium-text"> |
313 | - <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option> |
|
314 | - <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option> |
|
313 | + <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option> |
|
314 | + <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option> |
|
315 | 315 | </select> |
316 | - <p class="description"><?php _e( '<b>All payments:</b> apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p> |
|
316 | + <p class="description"><?php _e('<b>All payments:</b> apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p> |
|
317 | 317 | </td> |
318 | 318 | </tr> |
319 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?> |
|
319 | + <?php do_action('wpinv_discount_form_before_max_uses', $post); ?> |
|
320 | 320 | <tr> |
321 | 321 | <th valign="top" scope="row"> |
322 | - <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label> |
|
322 | + <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label> |
|
323 | 323 | </th> |
324 | 324 | <td> |
325 | 325 | <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>"> |
326 | - <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p> |
|
326 | + <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p> |
|
327 | 327 | </td> |
328 | 328 | </tr> |
329 | - <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?> |
|
329 | + <?php do_action('wpinv_discount_form_before_single_use', $post); ?> |
|
330 | 330 | <tr> |
331 | 331 | <th valign="top" scope="row"> |
332 | - <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label> |
|
332 | + <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label> |
|
333 | 333 | </th> |
334 | 334 | <td> |
335 | - <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>> |
|
336 | - <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span> |
|
335 | + <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>> |
|
336 | + <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span> |
|
337 | 337 | </td> |
338 | 338 | </tr> |
339 | - <?php do_action( 'wpinv_discount_form_last', $post ); ?> |
|
339 | + <?php do_action('wpinv_discount_form_last', $post); ?> |
|
340 | 340 | </tbody> |
341 | 341 | </table> |
342 | -<?php do_action( 'wpinv_discount_form_bottom', $post ); ?> |
|
342 | +<?php do_action('wpinv_discount_form_bottom', $post); ?> |
|
343 | 343 | <?php |
344 | 344 | } |
345 | 345 | |
346 | -function wpinv_discount_metabox_save( $post_id, $post, $update = false ) { |
|
347 | - $post_type = !empty( $post ) ? $post->post_type : ''; |
|
346 | +function wpinv_discount_metabox_save($post_id, $post, $update = false) { |
|
347 | + $post_type = !empty($post) ? $post->post_type : ''; |
|
348 | 348 | |
349 | - if ( $post_type != 'wpi_discount' ) { |
|
349 | + if ($post_type != 'wpi_discount') { |
|
350 | 350 | return; |
351 | 351 | } |
352 | 352 | |
353 | - if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) { |
|
353 | + if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) { |
|
354 | 354 | return; |
355 | 355 | } |
356 | 356 | |
357 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
357 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
358 | 358 | return; |
359 | 359 | } |
360 | 360 | |
361 | - if ( !current_user_can( 'manage_options', $post_id ) ) { |
|
361 | + if (!current_user_can('manage_options', $post_id)) { |
|
362 | 362 | return; |
363 | 363 | } |
364 | 364 | |
365 | - return wpinv_store_discount( $post_id, $_POST, $post, $update ); |
|
365 | + return wpinv_store_discount($post_id, $_POST, $post, $update); |
|
366 | 366 | } |
367 | -add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 ); |
|
368 | 367 | \ No newline at end of file |
368 | +add_action('save_post', 'wpinv_discount_metabox_save', 10, 3); |
|
369 | 369 | \ No newline at end of file |