@@ -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 |
@@ -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,291 +72,291 @@ 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 | 100 | } |
101 | 101 | } |
102 | -add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 ); |
|
102 | +add_action('save_post', 'wpinv_save_meta_boxes', 10, 3); |
|
103 | 103 | |
104 | -function wpinv_bulk_and_quick_edit_save( $post_id, $post, $update = false ) { |
|
105 | - if ( !( !empty( $_POST['action'] ) && $_POST['action'] == 'inline-save' ) ) { |
|
104 | +function wpinv_bulk_and_quick_edit_save($post_id, $post, $update = false) { |
|
105 | + if (!(!empty($_POST['action']) && $_POST['action'] == 'inline-save')) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | 109 | // $post_id and $post are required |
110 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
110 | + if (empty($post_id) || empty($post)) { |
|
111 | 111 | return; |
112 | 112 | } |
113 | 113 | |
114 | - if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) { |
|
114 | + if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) { |
|
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
118 | 118 | // Dont' save meta boxes for revisions or autosaves |
119 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
119 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
120 | 120 | return; |
121 | 121 | } |
122 | 122 | |
123 | - if ( $post->post_type == 'wpi_item' ) { |
|
123 | + if ($post->post_type == 'wpi_item') { |
|
124 | 124 | // verify nonce |
125 | - if ( isset( $_POST['_wpinv_item_price'] ) && get_post_meta( $post->ID, '_wpinv_type', true ) !== 'package' ) { |
|
126 | - update_post_meta( $post_id, '_wpinv_price', wpinv_sanitize_amount( $_POST['_wpinv_item_price'] ) ); |
|
125 | + if (isset($_POST['_wpinv_item_price']) && get_post_meta($post->ID, '_wpinv_type', true) !== 'package') { |
|
126 | + update_post_meta($post_id, '_wpinv_price', wpinv_sanitize_amount($_POST['_wpinv_item_price'])); |
|
127 | 127 | } |
128 | 128 | |
129 | - if ( isset( $_POST['_wpinv_vat_class'] ) ) { |
|
130 | - update_post_meta( $post_id, '_wpinv_vat_class', sanitize_text_field( $_POST['_wpinv_vat_class'] ) ); |
|
129 | + if (isset($_POST['_wpinv_vat_class'])) { |
|
130 | + update_post_meta($post_id, '_wpinv_vat_class', sanitize_text_field($_POST['_wpinv_vat_class'])); |
|
131 | 131 | } |
132 | 132 | |
133 | - if ( isset( $_POST['_wpinv_vat_rules'] ) ) { |
|
134 | - update_post_meta( $post_id, '_wpinv_vat_rule', sanitize_text_field( $_POST['_wpinv_vat_rules'] ) ); |
|
133 | + if (isset($_POST['_wpinv_vat_rules'])) { |
|
134 | + update_post_meta($post_id, '_wpinv_vat_rule', sanitize_text_field($_POST['_wpinv_vat_rules'])); |
|
135 | 135 | } |
136 | 136 | |
137 | - if ( isset( $_POST['_wpinv_item_type'] ) ) { |
|
138 | - update_post_meta( $post_id, '_wpinv_type', sanitize_text_field( $_POST['_wpinv_item_type'] ) ); |
|
137 | + if (isset($_POST['_wpinv_item_type'])) { |
|
138 | + update_post_meta($post_id, '_wpinv_type', sanitize_text_field($_POST['_wpinv_item_type'])); |
|
139 | 139 | } |
140 | 140 | } |
141 | 141 | } |
142 | -add_action( 'save_post', 'wpinv_bulk_and_quick_edit_save', 10, 3 ); |
|
142 | +add_action('save_post', 'wpinv_bulk_and_quick_edit_save', 10, 3); |
|
143 | 143 | |
144 | 144 | function wpinv_register_item_meta_boxes() { |
145 | 145 | global $wpinv_euvat; |
146 | 146 | |
147 | - add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' ); |
|
147 | + add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high'); |
|
148 | 148 | |
149 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
150 | - add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' ); |
|
149 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
150 | + add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high'); |
|
151 | 151 | } |
152 | 152 | |
153 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
154 | - add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' ); |
|
153 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
154 | + add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high'); |
|
155 | 155 | } |
156 | 156 | |
157 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' ); |
|
157 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core'); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | function wpinv_register_discount_meta_boxes() { |
161 | - add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' ); |
|
161 | + add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high'); |
|
162 | 162 | } |
163 | 163 | |
164 | -function wpinv_discount_metabox_details( $post ) { |
|
164 | +function wpinv_discount_metabox_details($post) { |
|
165 | 165 | $discount_id = $post->ID; |
166 | - $discount = wpinv_get_discount( $discount_id ); |
|
166 | + $discount = wpinv_get_discount($discount_id); |
|
167 | 167 | |
168 | - $type = wpinv_get_discount_type( $discount_id ); |
|
169 | - $item_reqs = wpinv_get_discount_item_reqs( $discount_id ); |
|
170 | - $excluded_items = wpinv_get_discount_excluded_items( $discount_id ); |
|
171 | - $min_total = wpinv_get_discount_min_total( $discount_id ); |
|
172 | - $max_total = wpinv_get_discount_max_total( $discount_id ); |
|
173 | - $max_uses = wpinv_get_discount_max_uses( $discount_id ); |
|
174 | - $single_use = wpinv_discount_is_single_use( $discount_id ); |
|
175 | - $recurring = (bool)wpinv_discount_is_recurring( $discount_id ); |
|
168 | + $type = wpinv_get_discount_type($discount_id); |
|
169 | + $item_reqs = wpinv_get_discount_item_reqs($discount_id); |
|
170 | + $excluded_items = wpinv_get_discount_excluded_items($discount_id); |
|
171 | + $min_total = wpinv_get_discount_min_total($discount_id); |
|
172 | + $max_total = wpinv_get_discount_max_total($discount_id); |
|
173 | + $max_uses = wpinv_get_discount_max_uses($discount_id); |
|
174 | + $single_use = wpinv_discount_is_single_use($discount_id); |
|
175 | + $recurring = (bool)wpinv_discount_is_recurring($discount_id); |
|
176 | 176 | |
177 | 177 | $min_total = $min_total > 0 ? $min_total : ''; |
178 | 178 | $max_total = $max_total > 0 ? $max_total : ''; |
179 | 179 | $max_uses = $max_uses > 0 ? $max_uses : ''; |
180 | 180 | ?> |
181 | -<?php do_action( 'wpinv_discount_form_top', $post ); ?> |
|
182 | -<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?> |
|
181 | +<?php do_action('wpinv_discount_form_top', $post); ?> |
|
182 | +<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?> |
|
183 | 183 | <table class="form-table wpi-form-table"> |
184 | 184 | <tbody> |
185 | - <?php do_action( 'wpinv_discount_form_first', $post ); ?> |
|
186 | - <?php do_action( 'wpinv_discount_form_before_code', $post ); ?> |
|
185 | + <?php do_action('wpinv_discount_form_first', $post); ?> |
|
186 | + <?php do_action('wpinv_discount_form_before_code', $post); ?> |
|
187 | 187 | <tr> |
188 | 188 | <th valign="top" scope="row"> |
189 | - <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label> |
|
189 | + <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label> |
|
190 | 190 | </th> |
191 | 191 | <td> |
192 | - <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required> |
|
193 | - <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p> |
|
192 | + <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required> |
|
193 | + <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p> |
|
194 | 194 | </td> |
195 | 195 | </tr> |
196 | - <?php do_action( 'wpinv_discount_form_before_type', $post ); ?> |
|
196 | + <?php do_action('wpinv_discount_form_before_type', $post); ?> |
|
197 | 197 | <tr> |
198 | 198 | <th valign="top" scope="row"> |
199 | - <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label> |
|
199 | + <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label> |
|
200 | 200 | </th> |
201 | 201 | <td> |
202 | 202 | <select id="wpinv_discount_type" name="type" class="medium-text"> |
203 | - <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?> |
|
204 | - <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option> |
|
203 | + <?php foreach (wpinv_get_discount_types() as $value => $label) { ?> |
|
204 | + <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option> |
|
205 | 205 | <?php } ?> |
206 | 206 | </select> |
207 | - <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p> |
|
207 | + <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p> |
|
208 | 208 | </td> |
209 | 209 | </tr> |
210 | - <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?> |
|
210 | + <?php do_action('wpinv_discount_form_before_amount', $post); ?> |
|
211 | 211 | <tr> |
212 | 212 | <th valign="top" scope="row"> |
213 | - <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label> |
|
213 | + <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label> |
|
214 | 214 | </th> |
215 | 215 | <td> |
216 | - <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> |
|
217 | - <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p> |
|
218 | - <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p> |
|
216 | + <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> |
|
217 | + <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p> |
|
218 | + <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p> |
|
219 | 219 | </td> |
220 | 220 | </tr> |
221 | - <?php do_action( 'wpinv_discount_form_before_items', $post ); ?> |
|
221 | + <?php do_action('wpinv_discount_form_before_items', $post); ?> |
|
222 | 222 | <tr> |
223 | 223 | <th valign="top" scope="row"> |
224 | - <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label> |
|
224 | + <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label> |
|
225 | 225 | </th> |
226 | 226 | <td> |
227 | - <p><?php echo wpinv_item_dropdown( array( |
|
227 | + <p><?php echo wpinv_item_dropdown(array( |
|
228 | 228 | 'name' => 'items[]', |
229 | 229 | 'id' => 'items', |
230 | 230 | 'selected' => $item_reqs, |
231 | 231 | 'multiple' => true, |
232 | 232 | 'chosen' => true, |
233 | 233 | 'class' => 'medium-text', |
234 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
234 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
235 | 235 | 'show_recurring' => true, |
236 | - ) ); ?> |
|
236 | + )); ?> |
|
237 | 237 | </p> |
238 | - <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> |
|
238 | + <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> |
|
239 | 239 | </td> |
240 | 240 | </tr> |
241 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?> |
|
241 | + <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?> |
|
242 | 242 | <tr> |
243 | 243 | <th valign="top" scope="row"> |
244 | - <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label> |
|
244 | + <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label> |
|
245 | 245 | </th> |
246 | 246 | <td> |
247 | - <p><?php echo wpinv_item_dropdown( array( |
|
247 | + <p><?php echo wpinv_item_dropdown(array( |
|
248 | 248 | 'name' => 'excluded_items[]', |
249 | 249 | 'id' => 'excluded_items', |
250 | 250 | 'selected' => $excluded_items, |
251 | 251 | 'multiple' => true, |
252 | 252 | 'chosen' => true, |
253 | 253 | 'class' => 'medium-text', |
254 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
254 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
255 | 255 | 'show_recurring' => true, |
256 | - ) ); ?> |
|
256 | + )); ?> |
|
257 | 257 | </p> |
258 | - <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p> |
|
258 | + <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p> |
|
259 | 259 | </td> |
260 | 260 | </tr> |
261 | - <?php do_action( 'wpinv_discount_form_before_start', $post ); ?> |
|
261 | + <?php do_action('wpinv_discount_form_before_start', $post); ?> |
|
262 | 262 | <tr> |
263 | 263 | <th valign="top" scope="row"> |
264 | - <label for="wpinv_discount_start"><?php _e( 'Start date', 'invoicing' ); ?></label> |
|
264 | + <label for="wpinv_discount_start"><?php _e('Start date', 'invoicing'); ?></label> |
|
265 | 265 | </th> |
266 | 266 | <td> |
267 | - <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 ) ); ?>"> |
|
268 | - <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> |
|
267 | + <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)); ?>"> |
|
268 | + <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> |
|
269 | 269 | </td> |
270 | 270 | </tr> |
271 | - <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?> |
|
271 | + <?php do_action('wpinv_discount_form_before_expiration', $post); ?> |
|
272 | 272 | <tr> |
273 | 273 | <th valign="top" scope="row"> |
274 | - <label for="wpinv_discount_expiration"><?php _e( 'Expiration date', 'invoicing' ); ?></label> |
|
274 | + <label for="wpinv_discount_expiration"><?php _e('Expiration date', 'invoicing'); ?></label> |
|
275 | 275 | </th> |
276 | 276 | <td> |
277 | - <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 ) ); ?>"> |
|
278 | - <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> |
|
277 | + <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)); ?>"> |
|
278 | + <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> |
|
279 | 279 | </td> |
280 | 280 | </tr> |
281 | - <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?> |
|
281 | + <?php do_action('wpinv_discount_form_before_min_total', $post); ?> |
|
282 | 282 | <tr> |
283 | 283 | <th valign="top" scope="row"> |
284 | - <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label> |
|
284 | + <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label> |
|
285 | 285 | </th> |
286 | 286 | <td> |
287 | 287 | <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>"> |
288 | - <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
288 | + <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
289 | 289 | </td> |
290 | 290 | </tr> |
291 | - <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?> |
|
291 | + <?php do_action('wpinv_discount_form_before_max_total', $post); ?> |
|
292 | 292 | <tr> |
293 | 293 | <th valign="top" scope="row"> |
294 | - <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label> |
|
294 | + <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label> |
|
295 | 295 | </th> |
296 | 296 | <td> |
297 | 297 | <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>"> |
298 | - <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
298 | + <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
299 | 299 | </td> |
300 | 300 | </tr> |
301 | - <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?> |
|
301 | + <?php do_action('wpinv_discount_form_before_recurring', $post); ?> |
|
302 | 302 | <tr> |
303 | 303 | <th valign="top" scope="row"> |
304 | - <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label> |
|
304 | + <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label> |
|
305 | 305 | </th> |
306 | 306 | <td> |
307 | 307 | <select id="wpinv_discount_recurring" name="recurring" class="medium-text"> |
308 | - <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option> |
|
309 | - <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option> |
|
308 | + <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option> |
|
309 | + <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option> |
|
310 | 310 | </select> |
311 | - <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> |
|
311 | + <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> |
|
312 | 312 | </td> |
313 | 313 | </tr> |
314 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?> |
|
314 | + <?php do_action('wpinv_discount_form_before_max_uses', $post); ?> |
|
315 | 315 | <tr> |
316 | 316 | <th valign="top" scope="row"> |
317 | - <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label> |
|
317 | + <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label> |
|
318 | 318 | </th> |
319 | 319 | <td> |
320 | 320 | <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>"> |
321 | - <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p> |
|
321 | + <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p> |
|
322 | 322 | </td> |
323 | 323 | </tr> |
324 | - <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?> |
|
324 | + <?php do_action('wpinv_discount_form_before_single_use', $post); ?> |
|
325 | 325 | <tr> |
326 | 326 | <th valign="top" scope="row"> |
327 | - <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label> |
|
327 | + <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label> |
|
328 | 328 | </th> |
329 | 329 | <td> |
330 | - <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>> |
|
331 | - <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span> |
|
330 | + <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>> |
|
331 | + <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span> |
|
332 | 332 | </td> |
333 | 333 | </tr> |
334 | - <?php do_action( 'wpinv_discount_form_last', $post ); ?> |
|
334 | + <?php do_action('wpinv_discount_form_last', $post); ?> |
|
335 | 335 | </tbody> |
336 | 336 | </table> |
337 | -<?php do_action( 'wpinv_discount_form_bottom', $post ); ?> |
|
337 | +<?php do_action('wpinv_discount_form_bottom', $post); ?> |
|
338 | 338 | <?php |
339 | 339 | } |
340 | 340 | |
341 | -function wpinv_discount_metabox_save( $post_id, $post, $update = false ) { |
|
342 | - $post_type = !empty( $post ) ? $post->post_type : ''; |
|
341 | +function wpinv_discount_metabox_save($post_id, $post, $update = false) { |
|
342 | + $post_type = !empty($post) ? $post->post_type : ''; |
|
343 | 343 | |
344 | - if ( $post_type != 'wpi_discount' ) { |
|
344 | + if ($post_type != 'wpi_discount') { |
|
345 | 345 | return; |
346 | 346 | } |
347 | 347 | |
348 | - 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' ) ) ) { |
|
348 | + 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'))) { |
|
349 | 349 | return; |
350 | 350 | } |
351 | 351 | |
352 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
352 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
353 | 353 | return; |
354 | 354 | } |
355 | 355 | |
356 | - if ( !current_user_can( 'manage_options', $post_id ) ) { |
|
356 | + if (!current_user_can('manage_options', $post_id)) { |
|
357 | 357 | return; |
358 | 358 | } |
359 | 359 | |
360 | - return wpinv_store_discount( $post_id, $_POST, $post, $update ); |
|
360 | + return wpinv_store_discount($post_id, $_POST, $post, $update); |
|
361 | 361 | } |
362 | -add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 ); |
|
363 | 362 | \ No newline at end of file |
363 | +add_action('save_post', 'wpinv_discount_metabox_save', 10, 3); |
|
364 | 364 | \ No newline at end of file |
@@ -1,66 +1,66 @@ 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 | -add_action( 'admin_menu', 'wpinv_add_options_link', 10 ); |
|
7 | +add_action('admin_menu', 'wpinv_add_options_link', 10); |
|
8 | 8 | function wpinv_add_options_link() { |
9 | 9 | global $menu; |
10 | 10 | |
11 | - if ( current_user_can( 'manage_options' ) ) { |
|
12 | - $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' ); |
|
11 | + if (current_user_can('manage_options')) { |
|
12 | + $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv'); |
|
13 | 13 | } |
14 | 14 | |
15 | - $wpi_invoice = get_post_type_object( 'wpi_invoice' ); |
|
15 | + $wpi_invoice = get_post_type_object('wpi_invoice'); |
|
16 | 16 | |
17 | - add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), 'manage_options', 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' ); |
|
17 | + add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), 'manage_options', 'wpinv', null, $wpi_invoice->menu_icon, '54.123460'); |
|
18 | 18 | |
19 | - $wpi_settings_page = add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), 'manage_options', 'wpinv-settings', 'wpinv_options_page' ); |
|
19 | + $wpi_settings_page = add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), 'manage_options', 'wpinv-settings', 'wpinv_options_page'); |
|
20 | 20 | } |
21 | 21 | |
22 | -add_action( 'admin_menu', 'wpinv_remove_admin_submenus', 999 ); |
|
22 | +add_action('admin_menu', 'wpinv_remove_admin_submenus', 999); |
|
23 | 23 | function wpinv_remove_admin_submenus() { |
24 | - remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' ); |
|
24 | + remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice'); |
|
25 | 25 | } |
26 | 26 | |
27 | -add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' ); |
|
28 | -function wpinv_discount_columns( $existing_columns ) { |
|
27 | +add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns'); |
|
28 | +function wpinv_discount_columns($existing_columns) { |
|
29 | 29 | $columns = array(); |
30 | 30 | $columns['cb'] = $existing_columns['cb']; |
31 | - $columns['name'] = __( 'Name', 'invoicing' ); |
|
32 | - $columns['code'] = __( 'Code', 'invoicing' ); |
|
33 | - $columns['amount'] = __( 'Amount', 'invoicing' ); |
|
34 | - $columns['usage'] = __( 'Usage / Limit', 'invoicing' ); |
|
35 | - $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' ); |
|
36 | - $columns['status'] = __( 'Status', 'invoicing' ); |
|
31 | + $columns['name'] = __('Name', 'invoicing'); |
|
32 | + $columns['code'] = __('Code', 'invoicing'); |
|
33 | + $columns['amount'] = __('Amount', 'invoicing'); |
|
34 | + $columns['usage'] = __('Usage / Limit', 'invoicing'); |
|
35 | + $columns['expiry_date'] = __('Expiry Date', 'invoicing'); |
|
36 | + $columns['status'] = __('Status', 'invoicing'); |
|
37 | 37 | |
38 | 38 | return $columns; |
39 | 39 | } |
40 | 40 | |
41 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
42 | -function wpinv_discount_custom_column( $column ) { |
|
41 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
42 | +function wpinv_discount_custom_column($column) { |
|
43 | 43 | global $post; |
44 | 44 | |
45 | 45 | $discount = $post; |
46 | 46 | |
47 | - switch ( $column ) { |
|
47 | + switch ($column) { |
|
48 | 48 | case 'name' : |
49 | - echo get_the_title( $discount->ID ); |
|
49 | + echo get_the_title($discount->ID); |
|
50 | 50 | break; |
51 | 51 | case 'code' : |
52 | - echo wpinv_get_discount_code( $discount->ID ); |
|
52 | + echo wpinv_get_discount_code($discount->ID); |
|
53 | 53 | break; |
54 | 54 | case 'amount' : |
55 | - echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
55 | + echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
56 | 56 | break; |
57 | 57 | case 'usage_limit' : |
58 | - echo wpinv_get_discount_uses( $discount->ID ); |
|
58 | + echo wpinv_get_discount_uses($discount->ID); |
|
59 | 59 | break; |
60 | 60 | case 'usage' : |
61 | - $usage = wpinv_get_discount_uses( $discount->ID ) . ' / '; |
|
62 | - if ( wpinv_get_discount_max_uses( $discount->ID ) ) { |
|
63 | - $usage .= wpinv_get_discount_max_uses( $discount->ID ); |
|
61 | + $usage = wpinv_get_discount_uses($discount->ID) . ' / '; |
|
62 | + if (wpinv_get_discount_max_uses($discount->ID)) { |
|
63 | + $usage .= wpinv_get_discount_max_uses($discount->ID); |
|
64 | 64 | } else { |
65 | 65 | $usage .= ' ∞'; |
66 | 66 | } |
@@ -68,162 +68,162 @@ discard block |
||
68 | 68 | echo $usage; |
69 | 69 | break; |
70 | 70 | case 'expiry_date' : |
71 | - if ( wpinv_get_discount_expiration( $discount->ID ) ) { |
|
72 | - $expiration = date_i18n( get_option( 'date_format' ), strtotime( wpinv_get_discount_expiration( $discount->ID ) ) ); |
|
71 | + if (wpinv_get_discount_expiration($discount->ID)) { |
|
72 | + $expiration = date_i18n(get_option('date_format'), strtotime(wpinv_get_discount_expiration($discount->ID))); |
|
73 | 73 | } else { |
74 | - $expiration = __( 'Never', 'invoicing' ); |
|
74 | + $expiration = __('Never', 'invoicing'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | echo $expiration; |
78 | 78 | break; |
79 | 79 | case 'description' : |
80 | - echo wp_kses_post( $post->post_excerpt ); |
|
80 | + echo wp_kses_post($post->post_excerpt); |
|
81 | 81 | break; |
82 | 82 | case 'status' : |
83 | - $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status; |
|
83 | + $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status; |
|
84 | 84 | |
85 | - echo wpinv_discount_status( $status ); |
|
85 | + echo wpinv_discount_status($status); |
|
86 | 86 | break; |
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
90 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 ); |
|
91 | -function wpinv_post_row_actions( $actions, $post ) { |
|
92 | - $post_type = !empty( $post->post_type ) ? $post->post_type : ''; |
|
90 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); |
|
91 | +function wpinv_post_row_actions($actions, $post) { |
|
92 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
93 | 93 | |
94 | - if ( $post_type == 'wpi_invoice' ) { |
|
94 | + if ($post_type == 'wpi_invoice') { |
|
95 | 95 | $actions = array(); |
96 | 96 | } |
97 | 97 | |
98 | - if ( $post_type == 'wpi_discount' ) { |
|
99 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
98 | + if ($post_type == 'wpi_discount') { |
|
99 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | return $actions; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
106 | - $row_actions = array(); |
|
107 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
108 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
105 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
106 | + $row_actions = array(); |
|
107 | + $edit_link = get_edit_post_link($discount->ID); |
|
108 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
109 | 109 | |
110 | - if( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
111 | - $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>'; |
|
112 | - } elseif( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
113 | - $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>'; |
|
110 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
111 | + $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>'; |
|
112 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
113 | + $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>'; |
|
114 | 114 | } |
115 | 115 | |
116 | - if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) { |
|
117 | - if ( isset( $row_actions['delete'] ) ) { |
|
118 | - unset( $row_actions['delete'] ); // Don't delete used discounts. |
|
116 | + if (wpinv_get_discount_uses($discount->ID) > 0) { |
|
117 | + if (isset($row_actions['delete'])) { |
|
118 | + unset($row_actions['delete']); // Don't delete used discounts. |
|
119 | 119 | } |
120 | 120 | } else { |
121 | - $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>'; |
|
121 | + $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>'; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | |
125 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
125 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
126 | 126 | |
127 | 127 | return $row_actions; |
128 | 128 | } |
129 | 129 | |
130 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 ); |
|
131 | -function wpinv_table_primary_column( $default, $screen_id ) { |
|
132 | - if ( 'edit-wpi_invoice' === $screen_id ) { |
|
130 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); |
|
131 | +function wpinv_table_primary_column($default, $screen_id) { |
|
132 | + if ('edit-wpi_invoice' === $screen_id) { |
|
133 | 133 | return 'name'; |
134 | 134 | } |
135 | 135 | |
136 | 136 | return $default; |
137 | 137 | } |
138 | 138 | |
139 | -function wpinv_discount_bulk_actions( $actions, $display = false ) { |
|
140 | - if ( !$display ) { |
|
139 | +function wpinv_discount_bulk_actions($actions, $display = false) { |
|
140 | + if (!$display) { |
|
141 | 141 | return array(); |
142 | 142 | } |
143 | 143 | |
144 | 144 | $actions = array( |
145 | - 'activate' => __( 'Activate', 'invoicing' ), |
|
146 | - 'deactivate' => __( 'Deactivate', 'invoicing' ), |
|
147 | - 'delete' => __( 'Delete', 'invoicing' ), |
|
145 | + 'activate' => __('Activate', 'invoicing'), |
|
146 | + 'deactivate' => __('Deactivate', 'invoicing'), |
|
147 | + 'delete' => __('Delete', 'invoicing'), |
|
148 | 148 | ); |
149 | 149 | $two = ''; |
150 | 150 | $which = 'top'; |
151 | 151 | echo '</div><div class="alignleft actions bulkactions">'; |
152 | - echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>'; |
|
153 | - echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">"; |
|
154 | - echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>"; |
|
152 | + echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>'; |
|
153 | + echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">"; |
|
154 | + echo '<option value="-1">' . __('Bulk Actions') . "</option>"; |
|
155 | 155 | |
156 | - foreach ( $actions as $name => $title ) { |
|
156 | + foreach ($actions as $name => $title) { |
|
157 | 157 | $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; |
158 | 158 | |
159 | 159 | echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>"; |
160 | 160 | } |
161 | 161 | echo "</select>"; |
162 | 162 | |
163 | - submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
|
163 | + submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two")); |
|
164 | 164 | |
165 | 165 | echo '</div><div class="alignleft actions">'; |
166 | 166 | } |
167 | -add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 ); |
|
167 | +add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10); |
|
168 | 168 | |
169 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { |
|
170 | - if ( $post_type == 'wpi_discount' ) { |
|
169 | +function wpinv_disable_months_dropdown($disable, $post_type) { |
|
170 | + if ($post_type == 'wpi_discount') { |
|
171 | 171 | $disable = true; |
172 | 172 | } |
173 | 173 | |
174 | 174 | return $disable; |
175 | 175 | } |
176 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 ); |
|
176 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); |
|
177 | 177 | |
178 | 178 | function wpinv_restrict_manage_posts() { |
179 | 179 | global $typenow; |
180 | 180 | |
181 | - if( 'wpi_discount' == $typenow ) { |
|
181 | + if ('wpi_discount' == $typenow) { |
|
182 | 182 | wpinv_discount_filters(); |
183 | 183 | } |
184 | 184 | } |
185 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
185 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
186 | 186 | |
187 | 187 | function wpinv_discount_filters() { |
188 | - echo wpinv_discount_bulk_actions( array(), true ); |
|
188 | + echo wpinv_discount_bulk_actions(array(), true); |
|
189 | 189 | |
190 | 190 | ?> |
191 | 191 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
192 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
192 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
193 | 193 | <?php |
194 | 194 | $types = wpinv_get_discount_types(); |
195 | 195 | |
196 | - foreach ( $types as $name => $type ) { |
|
197 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
196 | + foreach ($types as $name => $type) { |
|
197 | + echo '<option value="' . esc_attr($name) . '"'; |
|
198 | 198 | |
199 | - if ( isset( $_GET['discount_type'] ) ) |
|
200 | - selected( $name, $_GET['discount_type'] ); |
|
199 | + if (isset($_GET['discount_type'])) |
|
200 | + selected($name, $_GET['discount_type']); |
|
201 | 201 | |
202 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
202 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
203 | 203 | } |
204 | 204 | ?> |
205 | 205 | </select> |
206 | 206 | <?php |
207 | 207 | } |
208 | 208 | |
209 | -function wpinv_request( $vars ) { |
|
209 | +function wpinv_request($vars) { |
|
210 | 210 | global $typenow, $wp_query, $wp_post_statuses; |
211 | 211 | |
212 | - if ( 'wpi_invoice' === $typenow or 'wpi_quote' === $typenow ) { |
|
213 | - if ( !isset( $vars['post_status'] ) ) { |
|
212 | + if ('wpi_invoice' === $typenow or 'wpi_quote' === $typenow) { |
|
213 | + if (!isset($vars['post_status'])) { |
|
214 | 214 | $post_statuses = wpinv_get_invoice_statuses(); |
215 | 215 | |
216 | - foreach ( $post_statuses as $status => $value ) { |
|
217 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
218 | - unset( $post_statuses[ $status ] ); |
|
216 | + foreach ($post_statuses as $status => $value) { |
|
217 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
218 | + unset($post_statuses[$status]); |
|
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
222 | + $vars['post_status'] = array_keys($post_statuses); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( isset( $vars['orderby'] ) ) { |
|
226 | - if ( 'amount' == $vars['orderby'] ) { |
|
225 | + if (isset($vars['orderby'])) { |
|
226 | + if ('amount' == $vars['orderby']) { |
|
227 | 227 | $vars = array_merge( |
228 | 228 | $vars, |
229 | 229 | array( |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | 'orderby' => 'meta_value_num' |
232 | 232 | ) |
233 | 233 | ); |
234 | - } else if ( 'customer' == $vars['orderby'] ) { |
|
234 | + } else if ('customer' == $vars['orderby']) { |
|
235 | 235 | $vars = array_merge( |
236 | 236 | $vars, |
237 | 237 | array( |
@@ -241,9 +241,9 @@ discard block |
||
241 | 241 | ); |
242 | 242 | } |
243 | 243 | } |
244 | - } else if ( 'wpi_item' == $typenow ) { |
|
244 | + } else if ('wpi_item' == $typenow) { |
|
245 | 245 | // Check if 'orderby' is set to "price" |
246 | - if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) { |
|
246 | + if (isset($vars['orderby']) && 'price' == $vars['orderby']) { |
|
247 | 247 | $vars = array_merge( |
248 | 248 | $vars, |
249 | 249 | array( |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | } |
255 | 255 | |
256 | 256 | // Check if "orderby" is set to "vat_rule" |
257 | - if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) { |
|
257 | + if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) { |
|
258 | 258 | $vars = array_merge( |
259 | 259 | $vars, |
260 | 260 | array( |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | } |
266 | 266 | |
267 | 267 | // Check if "orderby" is set to "vat_class" |
268 | - if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) { |
|
268 | + if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) { |
|
269 | 269 | $vars = array_merge( |
270 | 270 | $vars, |
271 | 271 | array( |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | } |
277 | 277 | |
278 | 278 | // Check if "orderby" is set to "type" |
279 | - if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) { |
|
279 | + if (isset($vars['orderby']) && 'type' == $vars['orderby']) { |
|
280 | 280 | $vars = array_merge( |
281 | 281 | $vars, |
282 | 282 | array( |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | } |
288 | 288 | |
289 | 289 | // Check if "orderby" is set to "recurring" |
290 | - if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) { |
|
290 | + if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) { |
|
291 | 291 | $vars = array_merge( |
292 | 292 | $vars, |
293 | 293 | array( |
@@ -297,120 +297,120 @@ discard block |
||
297 | 297 | ); |
298 | 298 | } |
299 | 299 | |
300 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
300 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
301 | 301 | // Filter vat rule type |
302 | - if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) { |
|
302 | + if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') { |
|
303 | 303 | $meta_query[] = array( |
304 | 304 | 'key' => '_wpinv_vat_rule', |
305 | - 'value' => sanitize_text_field( $_GET['vat_rule'] ), |
|
305 | + 'value' => sanitize_text_field($_GET['vat_rule']), |
|
306 | 306 | 'compare' => '=' |
307 | 307 | ); |
308 | 308 | } |
309 | 309 | |
310 | 310 | // Filter vat class |
311 | - if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) { |
|
311 | + if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') { |
|
312 | 312 | $meta_query[] = array( |
313 | 313 | 'key' => '_wpinv_vat_class', |
314 | - 'value' => sanitize_text_field( $_GET['vat_class'] ), |
|
314 | + 'value' => sanitize_text_field($_GET['vat_class']), |
|
315 | 315 | 'compare' => '=' |
316 | 316 | ); |
317 | 317 | } |
318 | 318 | |
319 | 319 | // Filter item type |
320 | - if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) { |
|
320 | + if (isset($_GET['type']) && $_GET['type'] !== '') { |
|
321 | 321 | $meta_query[] = array( |
322 | 322 | 'key' => '_wpinv_type', |
323 | - 'value' => sanitize_text_field( $_GET['type'] ), |
|
323 | + 'value' => sanitize_text_field($_GET['type']), |
|
324 | 324 | 'compare' => '=' |
325 | 325 | ); |
326 | 326 | } |
327 | 327 | |
328 | - if ( !empty( $meta_query ) ) { |
|
328 | + if (!empty($meta_query)) { |
|
329 | 329 | $vars['meta_query'] = $meta_query; |
330 | 330 | } |
331 | - } else if ( 'wpi_discount' == $typenow ) { |
|
332 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
331 | + } else if ('wpi_discount' == $typenow) { |
|
332 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
333 | 333 | // Filter vat rule type |
334 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
334 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
335 | 335 | $meta_query[] = array( |
336 | 336 | 'key' => '_wpi_discount_type', |
337 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
337 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
338 | 338 | 'compare' => '=' |
339 | 339 | ); |
340 | 340 | } |
341 | 341 | |
342 | - if ( !empty( $meta_query ) ) { |
|
342 | + if (!empty($meta_query)) { |
|
343 | 343 | $vars['meta_query'] = $meta_query; |
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | 347 | return $vars; |
348 | 348 | } |
349 | -add_filter( 'request', 'wpinv_request' ); |
|
349 | +add_filter('request', 'wpinv_request'); |
|
350 | 350 | |
351 | 351 | function wpinv_options_page() { |
352 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
352 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
353 | 353 | |
354 | - if ( $page !== 'wpinv-settings' ) { |
|
354 | + if ($page !== 'wpinv-settings') { |
|
355 | 355 | return; |
356 | 356 | } |
357 | 357 | |
358 | 358 | $settings_tabs = wpinv_get_settings_tabs(); |
359 | 359 | $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs; |
360 | - $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general'; |
|
361 | - $sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
360 | + $active_tab = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general'; |
|
361 | + $sections = wpinv_get_settings_tab_sections($active_tab); |
|
362 | 362 | $key = 'main'; |
363 | 363 | |
364 | - if ( is_array( $sections ) ) { |
|
365 | - $key = key( $sections ); |
|
364 | + if (is_array($sections)) { |
|
365 | + $key = key($sections); |
|
366 | 366 | } |
367 | 367 | |
368 | - $registered_sections = wpinv_get_settings_tab_sections( $active_tab ); |
|
369 | - $section = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key; |
|
368 | + $registered_sections = wpinv_get_settings_tab_sections($active_tab); |
|
369 | + $section = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key; |
|
370 | 370 | ob_start(); |
371 | 371 | ?> |
372 | 372 | <div class="wrap"> |
373 | 373 | <h1 class="nav-tab-wrapper"> |
374 | 374 | <?php |
375 | - foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) { |
|
376 | - $tab_url = add_query_arg( array( |
|
375 | + foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) { |
|
376 | + $tab_url = add_query_arg(array( |
|
377 | 377 | 'settings-updated' => false, |
378 | 378 | 'tab' => $tab_id, |
379 | - ) ); |
|
379 | + )); |
|
380 | 380 | |
381 | 381 | // Remove the section from the tabs so we always end up at the main section |
382 | - $tab_url = remove_query_arg( 'section', $tab_url ); |
|
383 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
382 | + $tab_url = remove_query_arg('section', $tab_url); |
|
383 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
384 | 384 | |
385 | 385 | $active = $active_tab == $tab_id ? ' nav-tab-active' : ''; |
386 | 386 | |
387 | - echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">'; |
|
388 | - echo esc_html( $tab_name ); |
|
387 | + echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">'; |
|
388 | + echo esc_html($tab_name); |
|
389 | 389 | echo '</a>'; |
390 | 390 | } |
391 | 391 | ?> |
392 | 392 | </h1> |
393 | 393 | <?php |
394 | - $number_of_sections = count( $sections ); |
|
394 | + $number_of_sections = count($sections); |
|
395 | 395 | $number = 0; |
396 | - if ( $number_of_sections > 1 ) { |
|
396 | + if ($number_of_sections > 1) { |
|
397 | 397 | echo '<div><ul class="subsubsub">'; |
398 | - foreach( $sections as $section_id => $section_name ) { |
|
398 | + foreach ($sections as $section_id => $section_name) { |
|
399 | 399 | echo '<li>'; |
400 | 400 | $number++; |
401 | - $tab_url = add_query_arg( array( |
|
401 | + $tab_url = add_query_arg(array( |
|
402 | 402 | 'settings-updated' => false, |
403 | 403 | 'tab' => $active_tab, |
404 | 404 | 'section' => $section_id |
405 | - ) ); |
|
406 | - $tab_url = remove_query_arg( 'wpi_sub', $tab_url ); |
|
405 | + )); |
|
406 | + $tab_url = remove_query_arg('wpi_sub', $tab_url); |
|
407 | 407 | $class = ''; |
408 | - if ( $section == $section_id ) { |
|
408 | + if ($section == $section_id) { |
|
409 | 409 | $class = 'current'; |
410 | 410 | } |
411 | - echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>'; |
|
411 | + echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>'; |
|
412 | 412 | |
413 | - if ( $number != $number_of_sections ) { |
|
413 | + if ($number != $number_of_sections) { |
|
414 | 414 | echo ' | '; |
415 | 415 | } |
416 | 416 | echo '</li>'; |
@@ -422,19 +422,19 @@ discard block |
||
422 | 422 | <form method="post" action="options.php"> |
423 | 423 | <table class="form-table"> |
424 | 424 | <?php |
425 | - settings_fields( 'wpinv_settings' ); |
|
425 | + settings_fields('wpinv_settings'); |
|
426 | 426 | |
427 | - if ( 'main' === $section ) { |
|
428 | - do_action( 'wpinv_settings_tab_top', $active_tab ); |
|
427 | + if ('main' === $section) { |
|
428 | + do_action('wpinv_settings_tab_top', $active_tab); |
|
429 | 429 | } |
430 | 430 | |
431 | - do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section ); |
|
432 | - do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section ); |
|
433 | - do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section ); |
|
431 | + do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section); |
|
432 | + do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section); |
|
433 | + do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section); |
|
434 | 434 | |
435 | 435 | // For backwards compatibility |
436 | - if ( 'main' === $section ) { |
|
437 | - do_action( 'wpinv_settings_tab_bottom', $active_tab ); |
|
436 | + if ('main' === $section) { |
|
437 | + do_action('wpinv_settings_tab_bottom', $active_tab); |
|
438 | 438 | } |
439 | 439 | ?> |
440 | 440 | </table> |
@@ -447,12 +447,12 @@ discard block |
||
447 | 447 | echo $content; |
448 | 448 | } |
449 | 449 | |
450 | -function wpinv_item_type_class( $classes, $class, $post_id ) { |
|
450 | +function wpinv_item_type_class($classes, $class, $post_id) { |
|
451 | 451 | global $pagenow, $typenow; |
452 | 452 | |
453 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow && $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { |
|
454 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type ); |
|
453 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow && $type = get_post_meta($post_id, '_wpinv_type', true)) { |
|
454 | + $classes[] = 'wpi-type-' . sanitize_html_class($type); |
|
455 | 455 | } |
456 | 456 | return $classes; |
457 | 457 | } |
458 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 ); |
|
459 | 458 | \ No newline at end of file |
459 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); |
|
460 | 460 | \ No newline at end of file |
@@ -7,228 +7,228 @@ 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 | -function wpinv_columns( $columns ) { |
|
14 | +function wpinv_columns($columns) { |
|
15 | 15 | $columns = array( |
16 | 16 | 'cb' => $columns['cb'], |
17 | - 'ID' => __( 'ID', 'invoicing' ), |
|
18 | - 'details' => __( 'Details', 'invoicing' ), |
|
17 | + 'ID' => __('ID', 'invoicing'), |
|
18 | + 'details' => __('Details', 'invoicing'), |
|
19 | 19 | //'email' => __( 'Email', 'invoicing' ), |
20 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
21 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
22 | - 'invoice_date' => __( 'Date', 'invoicing' ), |
|
23 | - 'status' => __( 'Status', 'invoicing' ), |
|
24 | - 'wpi_actions' => __( 'Actions', 'invoicing' ), |
|
20 | + 'customer' => __('Customer', 'invoicing'), |
|
21 | + 'amount' => __('Amount', 'invoicing'), |
|
22 | + 'invoice_date' => __('Date', 'invoicing'), |
|
23 | + 'status' => __('Status', 'invoicing'), |
|
24 | + 'wpi_actions' => __('Actions', 'invoicing'), |
|
25 | 25 | ); |
26 | 26 | |
27 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
27 | + return apply_filters('wpi_invoice_table_columns', $columns); |
|
28 | 28 | } |
29 | -add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' ); |
|
29 | +add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns'); |
|
30 | 30 | |
31 | -function wpinv_bulk_actions( $actions ) { |
|
32 | - if ( isset( $actions['edit'] ) ) { |
|
33 | - unset( $actions['edit'] ); |
|
31 | +function wpinv_bulk_actions($actions) { |
|
32 | + if (isset($actions['edit'])) { |
|
33 | + unset($actions['edit']); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | return $actions; |
37 | 37 | } |
38 | -add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' ); |
|
38 | +add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions'); |
|
39 | 39 | |
40 | -function wpinv_sortable_columns( $columns ) { |
|
40 | +function wpinv_sortable_columns($columns) { |
|
41 | 41 | $columns = array( |
42 | - 'ID' => array( 'ID', true ), |
|
43 | - 'amount' => array( 'amount', false ), |
|
44 | - 'invoice_date' => array( 'date', false ), |
|
45 | - 'customer' => array( 'customer', false ), |
|
42 | + 'ID' => array('ID', true), |
|
43 | + 'amount' => array('amount', false), |
|
44 | + 'invoice_date' => array('date', false), |
|
45 | + 'customer' => array('customer', false), |
|
46 | 46 | ///'email' => array( 'email', false ), |
47 | - 'status' => array( 'status', false ), |
|
47 | + 'status' => array('status', false), |
|
48 | 48 | ); |
49 | 49 | |
50 | - return apply_filters( 'wpi_invoice_table_sortable_columns', $columns ); |
|
50 | + return apply_filters('wpi_invoice_table_sortable_columns', $columns); |
|
51 | 51 | } |
52 | -add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' ); |
|
52 | +add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns'); |
|
53 | 53 | |
54 | -add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
55 | -function wpinv_posts_custom_column( $column_name, $post_id = 0 ) { |
|
54 | +add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column'); |
|
55 | +function wpinv_posts_custom_column($column_name, $post_id = 0) { |
|
56 | 56 | global $post, $wpi_invoice; |
57 | 57 | |
58 | - if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) { |
|
59 | - $wpi_invoice = new WPInv_Invoice( $post->ID ); |
|
58 | + if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) { |
|
59 | + $wpi_invoice = new WPInv_Invoice($post->ID); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | $value = NULL; |
63 | 63 | |
64 | - switch ( $column_name ) { |
|
64 | + switch ($column_name) { |
|
65 | 65 | case 'email' : |
66 | - $value = $wpi_invoice->get_email(); |
|
66 | + $value = $wpi_invoice->get_email(); |
|
67 | 67 | break; |
68 | 68 | case 'customer' : |
69 | 69 | $customer_name = $wpi_invoice->get_user_full_name(); |
70 | - $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' ); |
|
71 | - $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>'; |
|
72 | - if ( $email = $wpi_invoice->get_email() ) { |
|
70 | + $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing'); |
|
71 | + $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>'; |
|
72 | + if ($email = $wpi_invoice->get_email()) { |
|
73 | 73 | $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>'; |
74 | 74 | } |
75 | 75 | break; |
76 | 76 | case 'amount' : |
77 | - echo $wpi_invoice->get_total( true ); |
|
77 | + echo $wpi_invoice->get_total(true); |
|
78 | 78 | break; |
79 | 79 | case 'invoice_date' : |
80 | - $date_format = get_option( 'date_format' ); |
|
81 | - $time_format = get_option( 'time_format' ); |
|
82 | - $date_time_format = $date_format . ' '. $time_format; |
|
80 | + $date_format = get_option('date_format'); |
|
81 | + $time_format = get_option('time_format'); |
|
82 | + $date_time_format = $date_format . ' ' . $time_format; |
|
83 | 83 | |
84 | - $t_time = get_the_time( $date_time_format ); |
|
84 | + $t_time = get_the_time($date_time_format); |
|
85 | 85 | $m_time = $post->post_date; |
86 | - $h_time = mysql2date( $date_format, $m_time ); |
|
86 | + $h_time = mysql2date($date_format, $m_time); |
|
87 | 87 | |
88 | 88 | $value = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>'; |
89 | 89 | break; |
90 | 90 | case 'status' : |
91 | - $value = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' ); |
|
91 | + $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : ''); |
|
92 | 92 | break; |
93 | 93 | case 'details' : |
94 | - $edit_link = get_edit_post_link( $post->ID ); |
|
95 | - $value = '<a href="' . esc_url( $edit_link ) . '">' . __( 'View Invoice Details', 'invoicing' ) . '</a>'; |
|
94 | + $edit_link = get_edit_post_link($post->ID); |
|
95 | + $value = '<a href="' . esc_url($edit_link) . '">' . __('View Invoice Details', 'invoicing') . '</a>'; |
|
96 | 96 | break; |
97 | 97 | case 'wpi_actions' : |
98 | 98 | $value = ''; |
99 | - if ( !empty( $post->post_name ) ) { |
|
100 | - $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>'; |
|
99 | + if (!empty($post->post_name)) { |
|
100 | + $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>'; |
|
101 | 101 | } |
102 | 102 | |
103 | - if ( $email = $wpi_invoice->get_email() ) { |
|
104 | - $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>'; |
|
103 | + if ($email = $wpi_invoice->get_email()) { |
|
104 | + $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>'; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | break; |
108 | 108 | default: |
109 | - $value = isset( $post->$column_name ) ? $post->$column_name : ''; |
|
109 | + $value = isset($post->$column_name) ? $post->$column_name : ''; |
|
110 | 110 | break; |
111 | 111 | |
112 | 112 | } |
113 | - $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name ); |
|
113 | + $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name); |
|
114 | 114 | |
115 | - if ( $value !== NULL ) { |
|
115 | + if ($value !== NULL) { |
|
116 | 116 | echo $value; |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | -function wpinv_admin_post_id( $id = 0 ) { |
|
120 | +function wpinv_admin_post_id($id = 0) { |
|
121 | 121 | global $post; |
122 | 122 | |
123 | - if ( isset( $id ) && ! empty( $id ) ) { |
|
123 | + if (isset($id) && !empty($id)) { |
|
124 | 124 | return (int)$id; |
125 | - } else if ( get_the_ID() ) { |
|
126 | - return (int) get_the_ID(); |
|
127 | - } else if ( isset( $post->ID ) && !empty( $post->ID ) ) { |
|
128 | - return (int) $post->ID; |
|
129 | - } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) { |
|
130 | - return (int) $_GET['post']; |
|
131 | - } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) { |
|
132 | - return (int) $_GET['id']; |
|
133 | - } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) { |
|
134 | - return (int) $_POST['id']; |
|
125 | + } else if (get_the_ID()) { |
|
126 | + return (int)get_the_ID(); |
|
127 | + } else if (isset($post->ID) && !empty($post->ID)) { |
|
128 | + return (int)$post->ID; |
|
129 | + } else if (isset($_GET['post']) && !empty($_GET['post'])) { |
|
130 | + return (int)$_GET['post']; |
|
131 | + } else if (isset($_GET['id']) && !empty($_GET['id'])) { |
|
132 | + return (int)$_GET['id']; |
|
133 | + } else if (isset($_POST['id']) && !empty($_POST['id'])) { |
|
134 | + return (int)$_POST['id']; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | return null; |
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_admin_post_type( $id = 0 ) { |
|
141 | - if ( !$id ) { |
|
140 | +function wpinv_admin_post_type($id = 0) { |
|
141 | + if (!$id) { |
|
142 | 142 | $id = wpinv_admin_post_id(); |
143 | 143 | } |
144 | 144 | |
145 | - $type = get_post_type( $id ); |
|
145 | + $type = get_post_type($id); |
|
146 | 146 | |
147 | - if ( !$type ) { |
|
148 | - $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null; |
|
147 | + if (!$type) { |
|
148 | + $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null; |
|
149 | 149 | } |
150 | 150 | |
151 | - return apply_filters( 'wpinv_admin_post_type', $type, $id ); |
|
151 | + return apply_filters('wpinv_admin_post_type', $type, $id); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | function wpinv_admin_messages() { |
155 | 155 | global $wpinv_options; |
156 | 156 | |
157 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
158 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' ); |
|
157 | + if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
158 | + add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated'); |
|
159 | 159 | } |
160 | 160 | |
161 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
162 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' ); |
|
161 | + if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
162 | + add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error'); |
|
163 | 163 | } |
164 | 164 | |
165 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
166 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' ); |
|
165 | + if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
166 | + add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error'); |
|
167 | 167 | } |
168 | 168 | |
169 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
170 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' ); |
|
169 | + if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
170 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated'); |
|
171 | 171 | } |
172 | 172 | |
173 | - if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
174 | - add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' ); |
|
173 | + if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
174 | + add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error'); |
|
175 | 175 | } |
176 | 176 | |
177 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
178 | - add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' ); |
|
177 | + if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
178 | + add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated'); |
|
179 | 179 | } |
180 | 180 | |
181 | - if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
182 | - add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' ); |
|
181 | + if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
182 | + add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated'); |
|
183 | 183 | } |
184 | 184 | |
185 | - if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
186 | - add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' ); |
|
185 | + if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
186 | + add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error'); |
|
187 | 187 | } |
188 | 188 | |
189 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
190 | - add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' ); |
|
189 | + if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
190 | + add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated'); |
|
191 | 191 | } |
192 | 192 | |
193 | - if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
194 | - add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' ); |
|
193 | + if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
194 | + add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated'); |
|
195 | 195 | } |
196 | 196 | |
197 | - if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
198 | - add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' ); |
|
197 | + if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
198 | + add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated'); |
|
199 | 199 | } |
200 | 200 | |
201 | - if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) { |
|
202 | - add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' ); |
|
201 | + if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) { |
|
202 | + add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated'); |
|
203 | 203 | } |
204 | 204 | |
205 | - settings_errors( 'wpinv-notices' ); |
|
205 | + settings_errors('wpinv-notices'); |
|
206 | 206 | } |
207 | -add_action( 'admin_notices', 'wpinv_admin_messages' ); |
|
207 | +add_action('admin_notices', 'wpinv_admin_messages'); |
|
208 | 208 | |
209 | -function wpinv_items_columns( $existing_columns ) { |
|
209 | +function wpinv_items_columns($existing_columns) { |
|
210 | 210 | global $wpinv_euvat; |
211 | 211 | |
212 | 212 | $columns = array(); |
213 | 213 | $columns['cb'] = $existing_columns['cb']; |
214 | - $columns['title'] = __( 'Title', 'invoicing' ); |
|
215 | - $columns['price'] = __( 'Price', 'invoicing' ); |
|
216 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
217 | - $columns['vat_rule'] = __( 'VAT rule type', 'invoicing' ); |
|
214 | + $columns['title'] = __('Title', 'invoicing'); |
|
215 | + $columns['price'] = __('Price', 'invoicing'); |
|
216 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
217 | + $columns['vat_rule'] = __('VAT rule type', 'invoicing'); |
|
218 | 218 | } |
219 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
220 | - $columns['vat_class'] = __( 'VAT class', 'invoicing' ); |
|
219 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
220 | + $columns['vat_class'] = __('VAT class', 'invoicing'); |
|
221 | 221 | } |
222 | - $columns['type'] = __( 'Type', 'invoicing' ); |
|
223 | - $columns['recurring'] = __( 'Recurring', 'invoicing' ); |
|
224 | - $columns['date'] = __( 'Date', 'invoicing' ); |
|
225 | - $columns['id'] = __( 'ID', 'invoicing' ); |
|
222 | + $columns['type'] = __('Type', 'invoicing'); |
|
223 | + $columns['recurring'] = __('Recurring', 'invoicing'); |
|
224 | + $columns['date'] = __('Date', 'invoicing'); |
|
225 | + $columns['id'] = __('ID', 'invoicing'); |
|
226 | 226 | |
227 | - return apply_filters( 'wpinv_items_columns', $columns ); |
|
227 | + return apply_filters('wpinv_items_columns', $columns); |
|
228 | 228 | } |
229 | -add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' ); |
|
229 | +add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns'); |
|
230 | 230 | |
231 | -function wpinv_items_sortable_columns( $columns ) { |
|
231 | +function wpinv_items_sortable_columns($columns) { |
|
232 | 232 | $columns['price'] = 'price'; |
233 | 233 | $columns['vat_rule'] = 'vat_rule'; |
234 | 234 | $columns['vat_class'] = 'vat_class'; |
@@ -238,10 +238,10 @@ discard block |
||
238 | 238 | |
239 | 239 | return $columns; |
240 | 240 | } |
241 | -add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' ); |
|
241 | +add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns'); |
|
242 | 242 | |
243 | -function wpinv_item_quick_edit( $column_name, $post_type ) { |
|
244 | - if ( !( $post_type == 'wpi_item' && $column_name == 'price' ) ) { |
|
243 | +function wpinv_item_quick_edit($column_name, $post_type) { |
|
244 | + if (!($post_type == 'wpi_item' && $column_name == 'price')) { |
|
245 | 245 | return; |
246 | 246 | } |
247 | 247 | global $wpinv_euvat, $post; |
@@ -249,23 +249,23 @@ discard block |
||
249 | 249 | $symbol = wpinv_currency_symbol(); |
250 | 250 | $position = wpinv_currency_position(); |
251 | 251 | |
252 | - $price = wpinv_get_item_price( $post->ID ); |
|
253 | - $item_type = wpinv_get_item_type( $post->ID ); |
|
252 | + $price = wpinv_get_item_price($post->ID); |
|
253 | + $item_type = wpinv_get_item_type($post->ID); |
|
254 | 254 | ?> |
255 | 255 | <fieldset class="inline-edit-col-right wpi-inline-item-col"> |
256 | 256 | <div class="inline-edit-col"> |
257 | 257 | <div class="inline-edit-group wp-clearfix"> |
258 | 258 | <label class="inline-edit-wpinv-price"> |
259 | - <span class="title"><?php _e( 'Item price', 'invoicing' );?></span> |
|
260 | - <span class="input-text-wrap"><?php echo ( $position != 'right' ? $symbol . ' ' : '' );?><input type="text" placeholder="<?php echo wpinv_format_amount( 0 ); ?>" value="<?php echo wpinv_format_amount( $price );?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID;?>"><?php echo ( $position == 'right' ? $symbol . ' ' : '' );?></span> |
|
259 | + <span class="title"><?php _e('Item price', 'invoicing'); ?></span> |
|
260 | + <span class="input-text-wrap"><?php echo ($position != 'right' ? $symbol . ' ' : ''); ?><input type="text" placeholder="<?php echo wpinv_format_amount(0); ?>" value="<?php echo wpinv_format_amount($price); ?>" name="_wpinv_item_price" class="wpi-field-price wpi-price" id="wpinv_item_price-<?php echo $post->ID; ?>"><?php echo ($position == 'right' ? $symbol . ' ' : ''); ?></span> |
|
261 | 261 | </label> |
262 | 262 | </div> |
263 | - <?php if ( $wpinv_euvat->allow_vat_rules() ) { $rule_type = $wpinv_euvat->get_item_rule( $post->ID ); ?> |
|
263 | + <?php if ($wpinv_euvat->allow_vat_rules()) { $rule_type = $wpinv_euvat->get_item_rule($post->ID); ?> |
|
264 | 264 | <div class="inline-edit-group wp-clearfix"> |
265 | 265 | <label class="inline-edit-wpinv-vat-rate"> |
266 | - <span class="title"><?php _e( 'VAT rule type to use', 'invoicing' );?></span> |
|
266 | + <span class="title"><?php _e('VAT rule type to use', 'invoicing'); ?></span> |
|
267 | 267 | <span class="input-text-wrap"> |
268 | - <?php echo wpinv_html_select( array( |
|
268 | + <?php echo wpinv_html_select(array( |
|
269 | 269 | 'options' => $wpinv_euvat->get_rules(), |
270 | 270 | 'name' => '_wpinv_vat_rules', |
271 | 271 | 'id' => 'wpinv_vat_rules-' . $post->ID, |
@@ -273,16 +273,16 @@ discard block |
||
273 | 273 | 'show_option_all' => false, |
274 | 274 | 'show_option_none' => false, |
275 | 275 | 'class' => 'gdmbx2-text-medium wpinv-vat-rules', |
276 | - ) ); ?> |
|
276 | + )); ?> |
|
277 | 277 | </span> |
278 | 278 | </label> |
279 | 279 | </div> |
280 | - <?php } if ( $wpinv_euvat->allow_vat_classes() ) { $vat_class = $wpinv_euvat->get_item_class( $post->ID ); ?> |
|
280 | + <?php } if ($wpinv_euvat->allow_vat_classes()) { $vat_class = $wpinv_euvat->get_item_class($post->ID); ?> |
|
281 | 281 | <div class="inline-edit-group wp-clearfix"> |
282 | 282 | <label class="inline-edit-wpinv-vat-class"> |
283 | - <span class="title"><?php _e( 'VAT class to use', 'invoicing' );?></span> |
|
283 | + <span class="title"><?php _e('VAT class to use', 'invoicing'); ?></span> |
|
284 | 284 | <span class="input-text-wrap"> |
285 | - <?php echo wpinv_html_select( array( |
|
285 | + <?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-' . $post->ID, |
@@ -290,16 +290,16 @@ 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 | </span> |
295 | 295 | </label> |
296 | 296 | </div> |
297 | 297 | <?php } ?> |
298 | 298 | <div class="inline-edit-group wp-clearfix"> |
299 | 299 | <label class="inline-edit-wpinv-type"> |
300 | - <span class="title"><?php _e( 'Item type', 'invoicing' );?></span> |
|
300 | + <span class="title"><?php _e('Item type', 'invoicing'); ?></span> |
|
301 | 301 | <span class="input-text-wrap"> |
302 | - <?php echo wpinv_html_select( array( |
|
302 | + <?php echo wpinv_html_select(array( |
|
303 | 303 | 'options' => wpinv_get_item_types(), |
304 | 304 | 'name' => '_wpinv_item_type', |
305 | 305 | 'id' => 'wpinv_item_type-' . $post->ID, |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | 'show_option_all' => false, |
308 | 308 | 'show_option_none' => false, |
309 | 309 | 'class' => 'gdmbx2-text-medium wpinv-item-type', |
310 | - ) ); ?> |
|
310 | + )); ?> |
|
311 | 311 | </span> |
312 | 312 | </label> |
313 | 313 | </div> |
@@ -315,150 +315,150 @@ discard block |
||
315 | 315 | </fieldset> |
316 | 316 | <?php |
317 | 317 | } |
318 | -add_action( 'quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 ); |
|
319 | -add_action( 'bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2 ); |
|
318 | +add_action('quick_edit_custom_box', 'wpinv_item_quick_edit', 10, 2); |
|
319 | +add_action('bulk_edit_custom_box', 'wpinv_item_quick_edit', 10, 2); |
|
320 | 320 | |
321 | -function wpinv_items_table_custom_column( $column ) { |
|
321 | +function wpinv_items_table_custom_column($column) { |
|
322 | 322 | global $wpinv_euvat, $post, $wpi_item; |
323 | 323 | |
324 | - if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) { |
|
325 | - $wpi_item = new WPInv_Item( $post->ID ); |
|
324 | + if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) { |
|
325 | + $wpi_item = new WPInv_Item($post->ID); |
|
326 | 326 | } |
327 | 327 | |
328 | - switch ( $column ) { |
|
328 | + switch ($column) { |
|
329 | 329 | case 'price' : |
330 | - echo wpinv_item_price( $post->ID ); |
|
330 | + echo wpinv_item_price($post->ID); |
|
331 | 331 | break; |
332 | 332 | case 'vat_rule' : |
333 | - echo $wpinv_euvat->item_rule_label( $post->ID ); |
|
333 | + echo $wpinv_euvat->item_rule_label($post->ID); |
|
334 | 334 | break; |
335 | 335 | case 'vat_class' : |
336 | - echo $wpinv_euvat->item_class_label( $post->ID ); |
|
336 | + echo $wpinv_euvat->item_class_label($post->ID); |
|
337 | 337 | break; |
338 | 338 | case 'type' : |
339 | - echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_cpt_singular_name() . '</span>'; |
|
339 | + echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_cpt_singular_name() . '</span>'; |
|
340 | 340 | break; |
341 | 341 | case 'recurring' : |
342 | - echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' ); |
|
342 | + echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>'); |
|
343 | 343 | break; |
344 | 344 | case 'id' : |
345 | 345 | echo $post->ID; |
346 | 346 | echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '"> |
347 | - <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>'; |
|
348 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
349 | - echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>'; |
|
347 | + <div class="price">' . wpinv_get_item_price($post->ID) . '</div>'; |
|
348 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
349 | + echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>'; |
|
350 | 350 | } |
351 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
352 | - echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>'; |
|
351 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
352 | + echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>'; |
|
353 | 353 | } |
354 | - echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div> |
|
354 | + echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div> |
|
355 | 355 | </div>'; |
356 | 356 | break; |
357 | 357 | } |
358 | 358 | |
359 | - do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post ); |
|
359 | + do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post); |
|
360 | 360 | } |
361 | -add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' ); |
|
361 | +add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column'); |
|
362 | 362 | |
363 | 363 | function wpinv_add_items_filters() { |
364 | 364 | global $wpinv_euvat, $typenow; |
365 | 365 | |
366 | 366 | // Checks if the current post type is 'item' |
367 | - if ( $typenow == 'wpi_item') { |
|
368 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
369 | - echo wpinv_html_select( array( |
|
370 | - 'options' => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ), |
|
367 | + if ($typenow == 'wpi_item') { |
|
368 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
369 | + echo wpinv_html_select(array( |
|
370 | + 'options' => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()), |
|
371 | 371 | 'name' => 'vat_rule', |
372 | 372 | 'id' => 'vat_rule', |
373 | - 'selected' => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ), |
|
373 | + 'selected' => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''), |
|
374 | 374 | 'show_option_all' => false, |
375 | 375 | 'show_option_none' => false, |
376 | 376 | 'class' => 'gdmbx2-text-medium', |
377 | - ) ); |
|
377 | + )); |
|
378 | 378 | } |
379 | 379 | |
380 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
381 | - echo wpinv_html_select( array( |
|
382 | - 'options' => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ), |
|
380 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
381 | + echo wpinv_html_select(array( |
|
382 | + 'options' => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()), |
|
383 | 383 | 'name' => 'vat_class', |
384 | 384 | 'id' => 'vat_class', |
385 | - 'selected' => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ), |
|
385 | + 'selected' => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''), |
|
386 | 386 | 'show_option_all' => false, |
387 | 387 | 'show_option_none' => false, |
388 | 388 | 'class' => 'gdmbx2-text-medium', |
389 | - ) ); |
|
389 | + )); |
|
390 | 390 | } |
391 | 391 | |
392 | - echo wpinv_html_select( array( |
|
393 | - 'options' => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ), |
|
392 | + echo wpinv_html_select(array( |
|
393 | + 'options' => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()), |
|
394 | 394 | 'name' => 'type', |
395 | 395 | 'id' => 'type', |
396 | - 'selected' => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ), |
|
396 | + 'selected' => (isset($_GET['type']) ? $_GET['type'] : ''), |
|
397 | 397 | 'show_option_all' => false, |
398 | 398 | 'show_option_none' => false, |
399 | 399 | 'class' => 'gdmbx2-text-medium', |
400 | - ) ); |
|
400 | + )); |
|
401 | 401 | |
402 | - if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) { |
|
402 | + if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) { |
|
403 | 403 | echo '<input type="hidden" name="all_posts" value="1" />'; |
404 | 404 | } |
405 | 405 | } |
406 | 406 | } |
407 | -add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 ); |
|
407 | +add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100); |
|
408 | 408 | |
409 | -function wpinv_send_invoice_after_save( $post_id ) { |
|
409 | +function wpinv_send_invoice_after_save($post_id) { |
|
410 | 410 | // If this is just a revision, don't send the email. |
411 | - if ( wp_is_post_revision( $post_id ) ) { |
|
411 | + if (wp_is_post_revision($post_id)) { |
|
412 | 412 | return; |
413 | 413 | } |
414 | 414 | |
415 | - if ( !current_user_can( 'manage_options' ) || !(get_post_type( $post_id ) == 'wpi_invoice' || get_post_type( $post_id ) == 'wpi_quote') ) { |
|
415 | + if (!current_user_can('manage_options') || !(get_post_type($post_id) == 'wpi_invoice' || get_post_type($post_id) == 'wpi_quote')) { |
|
416 | 416 | return; |
417 | 417 | } |
418 | 418 | |
419 | - if ( !empty( $_POST['wpi_save_send'] ) ) { |
|
420 | - wpinv_user_invoice_notification( $post_id ); |
|
419 | + if (!empty($_POST['wpi_save_send'])) { |
|
420 | + wpinv_user_invoice_notification($post_id); |
|
421 | 421 | } |
422 | 422 | } |
423 | -add_action( 'save_post_wpi_invoice', 'wpinv_send_invoice_after_save', 100, 1 ); |
|
423 | +add_action('save_post_wpi_invoice', 'wpinv_send_invoice_after_save', 100, 1); |
|
424 | 424 | |
425 | -function wpinv_send_register_new_user( $data, $postarr ) { |
|
426 | - if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && $data['post_type'] == 'wpi_invoice' ) { |
|
427 | - $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false; |
|
428 | - $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL; |
|
425 | +function wpinv_send_register_new_user($data, $postarr) { |
|
426 | + if (current_user_can('manage_options') && !empty($data['post_type']) && $data['post_type'] == 'wpi_invoice') { |
|
427 | + $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false; |
|
428 | + $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL; |
|
429 | 429 | |
430 | - if ( $is_new_user && $email && !email_exists( $email ) ) { |
|
431 | - $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : ''; |
|
432 | - $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : ''; |
|
433 | - $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : ''; |
|
434 | - $user_nicename = $display_name ? trim( $display_name ) : $email; |
|
435 | - $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : ''; |
|
430 | + if ($is_new_user && $email && !email_exists($email)) { |
|
431 | + $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : ''; |
|
432 | + $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : ''; |
|
433 | + $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : ''; |
|
434 | + $user_nicename = $display_name ? trim($display_name) : $email; |
|
435 | + $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : ''; |
|
436 | 436 | |
437 | - $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true ); |
|
438 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
439 | - $user_login = sanitize_user( str_replace( ' ', '', $user_company ), true ); |
|
437 | + $user_login = sanitize_user(str_replace(' ', '', $display_name), true); |
|
438 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
439 | + $user_login = sanitize_user(str_replace(' ', '', $user_company), true); |
|
440 | 440 | |
441 | - if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) { |
|
441 | + if (!(validate_username($user_login) && !username_exists($user_login))) { |
|
442 | 442 | $user_login = $email; |
443 | 443 | } |
444 | 444 | } |
445 | 445 | |
446 | 446 | $userdata = array( |
447 | 447 | 'user_login' => $user_login, |
448 | - 'user_pass' => wp_generate_password( 12, false ), |
|
449 | - 'user_email' => sanitize_text_field( $email ), |
|
448 | + 'user_pass' => wp_generate_password(12, false), |
|
449 | + 'user_email' => sanitize_text_field($email), |
|
450 | 450 | 'first_name' => $first_name, |
451 | 451 | 'last_name' => $last_name, |
452 | - 'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ), |
|
452 | + 'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50), |
|
453 | 453 | 'nickname' => $display_name, |
454 | 454 | 'display_name' => $display_name, |
455 | 455 | ); |
456 | 456 | |
457 | - $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata ); |
|
457 | + $userdata = apply_filters('wpinv_register_new_user_data', $userdata); |
|
458 | 458 | |
459 | - $new_user_id = wp_insert_user( $userdata ); |
|
459 | + $new_user_id = wp_insert_user($userdata); |
|
460 | 460 | |
461 | - if ( !is_wp_error( $new_user_id ) ) { |
|
461 | + if (!is_wp_error($new_user_id)) { |
|
462 | 462 | $data['post_author'] = $new_user_id; |
463 | 463 | $_POST['post_author'] = $new_user_id; |
464 | 464 | $_POST['post_author_override'] = $new_user_id; |
@@ -479,27 +479,27 @@ discard block |
||
479 | 479 | |
480 | 480 | $meta = array(); |
481 | 481 | ///$meta['_wpinv_user_id'] = $new_user_id; |
482 | - foreach ( $meta_fields as $field ) { |
|
483 | - $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : ''; |
|
482 | + foreach ($meta_fields as $field) { |
|
483 | + $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : ''; |
|
484 | 484 | } |
485 | 485 | |
486 | - $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id ); |
|
486 | + $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id); |
|
487 | 487 | |
488 | 488 | // Update user meta. |
489 | - foreach ( $meta as $key => $value ) { |
|
490 | - update_user_meta( $new_user_id, $key, $value ); |
|
489 | + foreach ($meta as $key => $value) { |
|
490 | + update_user_meta($new_user_id, $key, $value); |
|
491 | 491 | } |
492 | 492 | |
493 | - if ( function_exists( 'wp_send_new_user_notifications' ) ) { |
|
493 | + if (function_exists('wp_send_new_user_notifications')) { |
|
494 | 494 | // Send email notifications related to the creation of new user. |
495 | - wp_send_new_user_notifications( $new_user_id, 'user' ); |
|
495 | + wp_send_new_user_notifications($new_user_id, 'user'); |
|
496 | 496 | } |
497 | 497 | } else { |
498 | - wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ ); |
|
498 | + wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__); |
|
499 | 499 | } |
500 | 500 | } |
501 | 501 | } |
502 | 502 | |
503 | 503 | return $data; |
504 | 504 | } |
505 | -add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 ); |
|
506 | 505 | \ No newline at end of file |
506 | +add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2); |
|
507 | 507 | \ 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_format_amount( 0 ); ?>" value="<?php echo wpinv_format_amount( $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_format_amount(0); ?>" value="<?php echo wpinv_format_amount($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,93 +310,93 @@ 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 save( $post_id, $data, $post ) { |
|
321 | - $invoice = new WPInv_Invoice( $post_id ); |
|
320 | + public static function save($post_id, $data, $post) { |
|
321 | + $invoice = new WPInv_Invoice($post_id); |
|
322 | 322 | |
323 | 323 | // Billing |
324 | - $first_name = sanitize_text_field( $data['wpinv_first_name'] ); |
|
325 | - $last_name = sanitize_text_field( $data['wpinv_last_name'] ); |
|
326 | - $company = sanitize_text_field( $data['wpinv_company'] ); |
|
327 | - $vat_number = sanitize_text_field( $data['wpinv_vat_number'] ); |
|
328 | - $phone = sanitize_text_field( $data['wpinv_phone'] ); |
|
329 | - $address = sanitize_text_field( $data['wpinv_address'] ); |
|
330 | - $city = sanitize_text_field( $data['wpinv_city'] ); |
|
331 | - $zip = sanitize_text_field( $data['wpinv_zip'] ); |
|
332 | - $country = sanitize_text_field( $data['wpinv_country'] ); |
|
333 | - $state = sanitize_text_field( $data['wpinv_state'] ); |
|
324 | + $first_name = sanitize_text_field($data['wpinv_first_name']); |
|
325 | + $last_name = sanitize_text_field($data['wpinv_last_name']); |
|
326 | + $company = sanitize_text_field($data['wpinv_company']); |
|
327 | + $vat_number = sanitize_text_field($data['wpinv_vat_number']); |
|
328 | + $phone = sanitize_text_field($data['wpinv_phone']); |
|
329 | + $address = sanitize_text_field($data['wpinv_address']); |
|
330 | + $city = sanitize_text_field($data['wpinv_city']); |
|
331 | + $zip = sanitize_text_field($data['wpinv_zip']); |
|
332 | + $country = sanitize_text_field($data['wpinv_country']); |
|
333 | + $state = sanitize_text_field($data['wpinv_state']); |
|
334 | 334 | |
335 | 335 | // Details |
336 | - $status = sanitize_text_field( $data['wpinv_status'] ); |
|
337 | - $old_status = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status; |
|
338 | - $number = sanitize_text_field( $data['wpinv_number'] ); |
|
339 | - $due_date = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : ''; |
|
336 | + $status = sanitize_text_field($data['wpinv_status']); |
|
337 | + $old_status = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status; |
|
338 | + $number = sanitize_text_field($data['wpinv_number']); |
|
339 | + $due_date = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : ''; |
|
340 | 340 | //$discounts = sanitize_text_field( $data['wpinv_discounts'] ); |
341 | 341 | //$discount = sanitize_text_field( $data['wpinv_discount'] ); |
342 | 342 | |
343 | - $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
343 | + $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip(); |
|
344 | 344 | |
345 | - $invoice->set( 'due_date', $due_date ); |
|
346 | - $invoice->set( 'first_name', $first_name ); |
|
347 | - $invoice->set( 'last_name', $last_name ); |
|
348 | - $invoice->set( 'company', $company ); |
|
349 | - $invoice->set( 'vat_number', $vat_number ); |
|
350 | - $invoice->set( 'phone', $phone ); |
|
351 | - $invoice->set( 'address', $address ); |
|
352 | - $invoice->set( 'city', $city ); |
|
353 | - $invoice->set( 'zip', $zip ); |
|
354 | - $invoice->set( 'country', $country ); |
|
355 | - $invoice->set( 'state', $state ); |
|
356 | - $invoice->set( 'status', $status ); |
|
357 | - $invoice->set( 'number', $number ); |
|
345 | + $invoice->set('due_date', $due_date); |
|
346 | + $invoice->set('first_name', $first_name); |
|
347 | + $invoice->set('last_name', $last_name); |
|
348 | + $invoice->set('company', $company); |
|
349 | + $invoice->set('vat_number', $vat_number); |
|
350 | + $invoice->set('phone', $phone); |
|
351 | + $invoice->set('address', $address); |
|
352 | + $invoice->set('city', $city); |
|
353 | + $invoice->set('zip', $zip); |
|
354 | + $invoice->set('country', $country); |
|
355 | + $invoice->set('state', $state); |
|
356 | + $invoice->set('status', $status); |
|
357 | + $invoice->set('number', $number); |
|
358 | 358 | //$invoice->set( 'discounts', $discounts ); |
359 | 359 | //$invoice->set( 'discount', $discount ); |
360 | - $invoice->set( 'ip', $ip ); |
|
360 | + $invoice->set('ip', $ip); |
|
361 | 361 | $invoice->old_status = $_POST['original_post_status']; |
362 | 362 | $invoice->currency = wpinv_get_currency(); |
363 | - if ( !empty( $data['wpinv_gateway'] ) ) { |
|
364 | - $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) ); |
|
363 | + if (!empty($data['wpinv_gateway'])) { |
|
364 | + $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway'])); |
|
365 | 365 | } |
366 | 366 | $saved = $invoice->save(); |
367 | 367 | |
368 | 368 | // Check for payment notes |
369 | - if ( !empty( $data['invoice_note'] ) ) { |
|
370 | - $note = wp_kses( $data['invoice_note'], array() ); |
|
371 | - $note_type = sanitize_text_field( $data['invoice_note_type'] ); |
|
369 | + if (!empty($data['invoice_note'])) { |
|
370 | + $note = wp_kses($data['invoice_note'], array()); |
|
371 | + $note_type = sanitize_text_field($data['invoice_note_type']); |
|
372 | 372 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
373 | 373 | |
374 | - wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note ); |
|
374 | + wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | // Update user address if empty. |
378 | - if ( $saved && !empty( $invoice ) ) { |
|
379 | - if ( $user_id = $invoice->get_user_id() ) { |
|
380 | - $user_address = wpinv_get_user_address( $user_id, false ); |
|
378 | + if ($saved && !empty($invoice)) { |
|
379 | + if ($user_id = $invoice->get_user_id()) { |
|
380 | + $user_address = wpinv_get_user_address($user_id, false); |
|
381 | 381 | |
382 | 382 | if (empty($user_address['first_name'])) { |
383 | - update_user_meta( $user_id, '_wpinv_first_name', $first_name ); |
|
384 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
383 | + update_user_meta($user_id, '_wpinv_first_name', $first_name); |
|
384 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
385 | 385 | } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) { |
386 | - update_user_meta( $user_id, '_wpinv_last_name', $last_name ); |
|
386 | + update_user_meta($user_id, '_wpinv_last_name', $last_name); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) { |
390 | - update_user_meta( $user_id, '_wpinv_address', $address ); |
|
391 | - update_user_meta( $user_id, '_wpinv_city', $city ); |
|
392 | - update_user_meta( $user_id, '_wpinv_state', $state ); |
|
393 | - update_user_meta( $user_id, '_wpinv_country', $country ); |
|
394 | - update_user_meta( $user_id, '_wpinv_zip', $zip ); |
|
395 | - update_user_meta( $user_id, '_wpinv_phone', $phone ); |
|
390 | + update_user_meta($user_id, '_wpinv_address', $address); |
|
391 | + update_user_meta($user_id, '_wpinv_city', $city); |
|
392 | + update_user_meta($user_id, '_wpinv_state', $state); |
|
393 | + update_user_meta($user_id, '_wpinv_country', $country); |
|
394 | + update_user_meta($user_id, '_wpinv_zip', $zip); |
|
395 | + update_user_meta($user_id, '_wpinv_phone', $phone); |
|
396 | 396 | } |
397 | 397 | } |
398 | 398 | |
399 | - do_action( 'wpinv_invoice_metabox_saveed', $invoice ); |
|
399 | + do_action('wpinv_invoice_metabox_saveed', $invoice); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | return $saved; |
@@ -1,30 +1,30 @@ 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_Details { |
8 | - public static function output( $post ) { |
|
8 | + public static function output($post) { |
|
9 | 9 | $currency_symbol = wpinv_currency_symbol(); |
10 | 10 | $statuses = wpinv_get_invoice_statuses(); |
11 | 11 | |
12 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
13 | - $invoice = new WPInv_Invoice( $post_id ); |
|
12 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
13 | + $invoice = new WPInv_Invoice($post_id); |
|
14 | 14 | |
15 | - $status = $invoice->get_status( false ); // Current status |
|
15 | + $status = $invoice->get_status(false); // Current status |
|
16 | 16 | $discount = $invoice->get_discount(); |
17 | 17 | $discount_code = $discount > 0 ? $invoice->get_discount_code() : ''; |
18 | 18 | $invoice_number = $invoice->get_number(); |
19 | 19 | |
20 | 20 | $date_created = $invoice->get_created_date(); |
21 | - $datetime_created = strtotime( $date_created ); |
|
22 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : ''; |
|
21 | + $datetime_created = strtotime($date_created); |
|
22 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : ''; |
|
23 | 23 | $date_completed = $invoice->get_completed_date(); |
24 | - $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a'; |
|
25 | - $title['status'] = __( 'Invoice Status:', 'invoicing' ); |
|
26 | - $title['number'] = __( 'Invoice Number:', 'invoicing' ); |
|
27 | - $mail_notice = esc_attr__( 'After save invoice this will send a copy of the invoice to the user’s email address.', 'invoicing' ); |
|
24 | + $date_completed = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($date_completed)) : 'n/a'; |
|
25 | + $title['status'] = __('Invoice Status:', 'invoicing'); |
|
26 | + $title['number'] = __('Invoice Number:', 'invoicing'); |
|
27 | + $mail_notice = esc_attr__('After save invoice this will send a copy of the invoice to the user’s email address.', 'invoicing'); |
|
28 | 28 | |
29 | 29 | $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice); |
30 | 30 | $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice); |
@@ -34,29 +34,29 @@ discard block |
||
34 | 34 | <div class="gdmbx2-wrap form-table"> |
35 | 35 | <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details"> |
36 | 36 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created"> |
37 | - <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div> |
|
38 | - <div class="gdmbx-td"><?php echo $date_created;?></div> |
|
37 | + <div class="gdmbx-th"><label><?php _e('Date Created:', 'invoicing'); ?></label></div> |
|
38 | + <div class="gdmbx-td"><?php echo $date_created; ?></div> |
|
39 | 39 | </div> |
40 | - <?php if ( wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft' ) ) ) ) { ?> |
|
40 | + <?php if (wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft')))) { ?> |
|
41 | 41 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue"> |
42 | - <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div> |
|
42 | + <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div> |
|
43 | 43 | <div class="gdmbx-td"> |
44 | - <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd"> |
|
44 | + <input type="text" placeholder="<?php esc_attr_e('Y-m-d', 'invoicing'); ?>" value="<?php echo esc_attr($invoice->get_due_date()); ?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr(date_i18n('Y-m-d', $datetime_created)); ?>" data-dateFormat="yy-mm-dd"> |
|
45 | 45 | </div> |
46 | 46 | </div> |
47 | 47 | <?php } ?> |
48 | - <?php if ( $date_completed && $date_completed != 'n/a' ) { ?> |
|
48 | + <?php if ($date_completed && $date_completed != 'n/a') { ?> |
|
49 | 49 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed"> |
50 | - <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div> |
|
51 | - <div class="gdmbx-td"><?php echo $date_completed;?></div> |
|
50 | + <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div> |
|
51 | + <div class="gdmbx-td"><?php echo $date_completed; ?></div> |
|
52 | 52 | </div> |
53 | 53 | <?php } ?> |
54 | 54 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status"> |
55 | 55 | <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div> |
56 | 56 | <div class="gdmbx-td"> |
57 | 57 | <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select"> |
58 | - <?php foreach ( $statuses as $value => $label ) { ?> |
|
59 | - <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option> |
|
58 | + <?php foreach ($statuses as $value => $label) { ?> |
|
59 | + <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option> |
|
60 | 60 | <?php } ?> |
61 | 61 | </select> |
62 | 62 | </div> |
@@ -64,104 +64,104 @@ discard block |
||
64 | 64 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout"> |
65 | 65 | <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div> |
66 | 66 | <div class="gdmbx-td"> |
67 | - <input type="text" placeholder="<?php echo esc_attr( wpinv_format_invoice_number( 1 ) ); ?>" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text"> |
|
67 | + <input type="text" placeholder="<?php echo esc_attr(wpinv_format_invoice_number(1)); ?>" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text"> |
|
68 | 68 | </div> |
69 | 69 | </div> |
70 | - <?php do_action( 'wpinv_meta_box_details_inner', $post_id ); ?> |
|
71 | - <?php if ( !( $is_paid = $invoice->is_paid() ) || $discount_code ) { ?> |
|
70 | + <?php do_action('wpinv_meta_box_details_inner', $post_id); ?> |
|
71 | + <?php if (!($is_paid = $invoice->is_paid()) || $discount_code) { ?> |
|
72 | 72 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout"> |
73 | - <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div> |
|
73 | + <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div> |
|
74 | 74 | <div class="gdmbx-td"> |
75 | - <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
|
75 | + <input type="text" value="<?php echo esc_attr($discount_code); ?>" id="wpinv_discount" class="medium-text" <?php echo ($discount_code ? 'readonly' : ''); ?> /><?php if (!$is_paid) { ?><input value="<?php echo esc_attr_e('Apply', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-hide' : 'wpi-inlineb'); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e('Remove', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-inlineb' : 'wpi-hide'); ?>" id="wpinv-remove-code" type="button" /><?php } ?> |
|
76 | 76 | </div> |
77 | 77 | </div> |
78 | 78 | <?php } ?> |
79 | 79 | </div> |
80 | 80 | </div> |
81 | 81 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout"> |
82 | - <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__( 'Send %s:', 'invoicing' ),$post_obj->labels->singular_name) ; ?></label> |
|
82 | + <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__('Send %s:', 'invoicing'), $post_obj->labels->singular_name); ?></label> |
|
83 | 83 | <select id="wpi_save_send" name="wpi_save_send"> |
84 | - <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option> |
|
85 | - <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option> |
|
84 | + <option value="1"><?php _e('Yes', 'invoicing'); ?></option> |
|
85 | + <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option> |
|
86 | 86 | </select> |
87 | 87 | </p> |
88 | 88 | <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p> |
89 | 89 | </div> |
90 | -<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?> |
|
90 | +<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?> |
|
91 | 91 | <?php |
92 | 92 | } |
93 | 93 | |
94 | - public static function resend_invoice( $post ) { |
|
94 | + public static function resend_invoice($post) { |
|
95 | 95 | global $wpi_mb_invoice; |
96 | 96 | |
97 | - if ( empty( $wpi_mb_invoice ) ) { |
|
97 | + if (empty($wpi_mb_invoice)) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
101 | 101 | $text = array( |
102 | - 'message' => esc_attr__( 'This will send a copy of the invoice to the user’s email address.', 'invoicing' ), |
|
103 | - 'button_text' => __( 'Resend Invoice', 'invoicing' ), |
|
102 | + 'message' => esc_attr__('This will send a copy of the invoice to the user’s email address.', 'invoicing'), |
|
103 | + 'button_text' => __('Resend Invoice', 'invoicing'), |
|
104 | 104 | ); |
105 | 105 | |
106 | 106 | $text = apply_filters('resend_invoice_metabox_text', $text); |
107 | - do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice ); |
|
107 | + do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice); |
|
108 | 108 | |
109 | - if ( $email = $wpi_mb_invoice->get_email() ) { |
|
110 | - $email_url = add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ); |
|
111 | - $reminder_url = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) ); |
|
109 | + if ($email = $wpi_mb_invoice->get_email()) { |
|
110 | + $email_url = add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID)); |
|
111 | + $reminder_url = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID)); |
|
112 | 112 | ?> |
113 | 113 | <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p> |
114 | - <p class="wpi-meta-row wpi-resend-email"><a title="<?php esc_attr_e( 'Send invoice to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_url ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
115 | - <?php if ( wpinv_get_option( 'overdue_active' ) && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?> |
|
116 | - <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $reminder_url ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p> |
|
114 | + <p class="wpi-meta-row wpi-resend-email"><a title="<?php esc_attr_e('Send invoice to customer', 'invoicing'); ?>" href="<?php echo esc_url($email_url); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
115 | + <?php if (wpinv_get_option('overdue_active') && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?> |
|
116 | + <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo esc_url($reminder_url); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p> |
|
117 | 117 | <?php } ?> |
118 | 118 | <?php |
119 | 119 | } |
120 | 120 | |
121 | - do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice ); |
|
121 | + do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice); |
|
122 | 122 | } |
123 | 123 | |
124 | - public static function subscriptions( $post ) { |
|
124 | + public static function subscriptions($post) { |
|
125 | 125 | global $wpi_mb_invoice; |
126 | 126 | |
127 | 127 | $invoice = $wpi_mb_invoice; |
128 | 128 | |
129 | - if ( !empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) { |
|
129 | + if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) { |
|
130 | 130 | $payments = $invoice->get_child_payments(); |
131 | 131 | |
132 | 132 | $total_payments = (int)$invoice->get_total_payments(); |
133 | 133 | $subscription = $invoice->get_subscription_data(); |
134 | 134 | |
135 | - $billing_cycle = wpinv_get_billing_cycle( $subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency() ); |
|
136 | - $times_billed = $total_payments . ' / ' . ( ( (int)$subscription['bill_times'] == 0 ) ? __( 'Until cancelled', 'invoicing' ) : $subscription['bill_times'] ); |
|
135 | + $billing_cycle = wpinv_get_billing_cycle($subscription['initial_amount'], $subscription['recurring_amount'], $subscription['period'], $subscription['interval'], $subscription['bill_times'], $subscription['trial_period'], $subscription['trial_interval'], $invoice->get_currency()); |
|
136 | + $times_billed = $total_payments . ' / ' . (((int)$subscription['bill_times'] == 0) ? __('Until cancelled', 'invoicing') : $subscription['bill_times']); |
|
137 | 137 | $subscription_status = $invoice->get_subscription_status(); |
138 | 138 | ?> |
139 | - <p class="wpi-meta-row wpi-sub-label"><?php _e( 'Recurring Payment', 'invoicing' );?></p> |
|
140 | - <?php if ( $subscription_id = $invoice->get_subscription_id() ) { ?> |
|
141 | - <p class="wpi-meta-row wpi-sub-id"><label><?php _e( 'Subscription ID:', 'invoicing' );?> </label><?php echo $subscription_id; ?></p> |
|
139 | + <p class="wpi-meta-row wpi-sub-label"><?php _e('Recurring Payment', 'invoicing'); ?></p> |
|
140 | + <?php if ($subscription_id = $invoice->get_subscription_id()) { ?> |
|
141 | + <p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><?php echo $subscription_id; ?></p> |
|
142 | 142 | <?php } ?> |
143 | - <p class="wpi-meta-row wpi-bill-cycle"><label><?php _e( 'Billing Cycle:', 'invoicing' );?> </label><?php echo $billing_cycle; ?></p> |
|
144 | - <p class="wpi-meta-row wpi-billed-times"><label><?php _e( 'Times Billed:', 'invoicing' );?> </label><?php echo $times_billed; ?></p> |
|
145 | - <?php if ( !empty( $payments ) || $invoice->is_paid() ) { ?> |
|
146 | - <p class="wpi-meta-row wpi-start-date"><label><?php _e( 'Start Date:', 'invoicing' );?> </label><?php echo $invoice->get_subscription_start(); ?></p> |
|
147 | - <p class="wpi-meta-row wpi-end-date"><label><?php _e( 'Expiration Date:', 'invoicing' );?> </label><?php echo $invoice->get_subscription_end(); ?></p> |
|
148 | - <?php if ( $status_label = $invoice->get_subscription_status_label( $subscription_status ) ) { ?> |
|
149 | - <p class="wpi-meta-row wpi-sub-status"><label><?php _e( 'Subscription Status:', 'invoicing' );?> </label><?php echo $status_label; ?></p> |
|
143 | + <p class="wpi-meta-row wpi-bill-cycle"><label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php echo $billing_cycle; ?></p> |
|
144 | + <p class="wpi-meta-row wpi-billed-times"><label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $times_billed; ?></p> |
|
145 | + <?php if (!empty($payments) || $invoice->is_paid()) { ?> |
|
146 | + <p class="wpi-meta-row wpi-start-date"><label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo $invoice->get_subscription_start(); ?></p> |
|
147 | + <p class="wpi-meta-row wpi-end-date"><label><?php _e('Expiration Date:', 'invoicing'); ?> </label><?php echo $invoice->get_subscription_end(); ?></p> |
|
148 | + <?php if ($status_label = $invoice->get_subscription_status_label($subscription_status)) { ?> |
|
149 | + <p class="wpi-meta-row wpi-sub-status"><label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $status_label; ?></p> |
|
150 | 150 | <?php } ?> |
151 | - <?php if ( $subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date() ) { ?> |
|
152 | - <p class="wpi-meta-row wpi-trial-date"><label><?php _e( 'Trial Until:', 'invoicing' );?> </label><?php echo $trial_end_date; ?></p> |
|
151 | + <?php if ($subscription_status == 'trialing' && $trial_end_date = $invoice->get_trial_end_date()) { ?> |
|
152 | + <p class="wpi-meta-row wpi-trial-date"><label><?php _e('Trial Until:', 'invoicing'); ?> </label><?php echo $trial_end_date; ?></p> |
|
153 | 153 | <?php } ?> |
154 | - <?php if ( $cancelled_date = $invoice->get_cancelled_date() ) { ?> |
|
155 | - <p class="wpi-meta-row wpi-cancel-date"><label><?php _e( 'Cancelled On:', 'invoicing' );?> </label><?php echo $cancelled_date; ?></p> |
|
154 | + <?php if ($cancelled_date = $invoice->get_cancelled_date()) { ?> |
|
155 | + <p class="wpi-meta-row wpi-cancel-date"><label><?php _e('Cancelled On:', 'invoicing'); ?> </label><?php echo $cancelled_date; ?></p> |
|
156 | 156 | <?php } ?> |
157 | - <?php if ( !empty( $payments ) ) { ?> |
|
158 | - <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p> |
|
157 | + <?php if (!empty($payments)) { ?> |
|
158 | + <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p> |
|
159 | 159 | <ul id="wpi-sub-payments"> |
160 | - <?php foreach ( $payments as $invoice_id ) { ?> |
|
160 | + <?php foreach ($payments as $invoice_id) { ?> |
|
161 | 161 | <li> |
162 | - <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a> – |
|
163 | - <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?> – </span> |
|
164 | - <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span> |
|
162 | + <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a> – |
|
163 | + <span><?php echo wpinv_get_invoice_date($invoice_id); ?> – </span> |
|
164 | + <span><?php echo wpinv_payment_total($invoice_id, true); ?></span> |
|
165 | 165 | </li> |
166 | 166 | <?php } ?> |
167 | 167 | </ul> |
@@ -169,47 +169,47 @@ discard block |
||
169 | 169 | } |
170 | 170 | } |
171 | 171 | |
172 | - public static function renewals( $post ) { |
|
172 | + public static function renewals($post) { |
|
173 | 173 | global $wpi_mb_invoice; |
174 | 174 | |
175 | - if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) { |
|
176 | - $parent_url = get_edit_post_link( $wpi_mb_invoice->parent_invoice ); |
|
177 | - $parent_id = wpinv_get_invoice_number( $wpi_mb_invoice->parent_invoice ); |
|
175 | + if (wpinv_is_subscription_payment($wpi_mb_invoice)) { |
|
176 | + $parent_url = get_edit_post_link($wpi_mb_invoice->parent_invoice); |
|
177 | + $parent_id = wpinv_get_invoice_number($wpi_mb_invoice->parent_invoice); |
|
178 | 178 | ?> |
179 | - <p class="wpi-meta-row wpi-sub-id"><label><?php _e( 'Subscription ID:', 'invoicing' );?> </label><?php echo $wpi_mb_invoice->get_subscription_id(); ?></p> |
|
180 | - <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p> |
|
179 | + <p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><?php echo $wpi_mb_invoice->get_subscription_id(); ?></p> |
|
180 | + <p class="wpi-meta-row wpi-parent-id"><label><?php _e('Parent Invoice:', 'invoicing'); ?> </label><a href="<?php echo esc_url($parent_url); ?>"><?php echo $parent_id; ?></a></p> |
|
181 | 181 | <?php |
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
185 | - public static function payment_meta( $post ) { |
|
185 | + public static function payment_meta($post) { |
|
186 | 186 | global $wpi_mb_invoice; |
187 | 187 | |
188 | - $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false; |
|
189 | - if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() ) { |
|
188 | + $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false; |
|
189 | + if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid()) { |
|
190 | 190 | $set_dateway = true; |
191 | 191 | } |
192 | 192 | |
193 | 193 | ?> |
194 | 194 | <p class="wpi-meta-row"> |
195 | - <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?> |
|
196 | - <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label> |
|
195 | + <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?> |
|
196 | + <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label> |
|
197 | 197 | <select required="required" id="wpinv_gateway" name="wpinv_gateway"> |
198 | - <?php foreach ( $gateways as $name => $gateway ) { |
|
199 | - if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) { |
|
198 | + <?php foreach ($gateways as $name => $gateway) { |
|
199 | + if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) { |
|
200 | 200 | continue; |
201 | 201 | } |
202 | 202 | ?> |
203 | - <option value="<?php echo $name;?>" <?php selected( $wpi_mb_invoice->gateway, $name );?>><?php echo !empty( $gateway['admin_label'] ) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option> |
|
203 | + <option value="<?php echo $name; ?>" <?php selected($wpi_mb_invoice->gateway, $name); ?>><?php echo !empty($gateway['admin_label']) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option> |
|
204 | 204 | <?php } ?> |
205 | 205 | </select> |
206 | 206 | <?php } else { |
207 | - echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_checkout_label( $wpi_mb_invoice->gateway ) ); |
|
207 | + echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_checkout_label($wpi_mb_invoice->gateway)); |
|
208 | 208 | } ?> |
209 | 209 | </p> |
210 | - <?php if ( $wpi_mb_invoice->is_paid() ) { ?> |
|
211 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $wpi_mb_invoice->get_key() ); ?></p> |
|
212 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p> |
|
210 | + <?php if ($wpi_mb_invoice->is_paid()) { ?> |
|
211 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $wpi_mb_invoice->get_key()); ?></p> |
|
212 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p> |
|
213 | 213 | <?php } ?> |
214 | 214 | <?php |
215 | 215 | } |
@@ -7,440 +7,440 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | function wpinv_get_invoice_cart_id() { |
15 | 15 | $wpinv_checkout = wpinv_get_checkout_session(); |
16 | 16 | |
17 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
17 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
18 | 18 | return $wpinv_checkout['invoice_id']; |
19 | 19 | } |
20 | 20 | |
21 | 21 | return NULL; |
22 | 22 | } |
23 | 23 | |
24 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
25 | - if ( $cart && empty( $invoice_id ) ) { |
|
24 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
25 | + if ($cart && empty($invoice_id)) { |
|
26 | 26 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
27 | 27 | } |
28 | 28 | |
29 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
29 | + $invoice = new WPInv_Invoice($invoice_id); |
|
30 | 30 | return $invoice; |
31 | 31 | } |
32 | 32 | |
33 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
34 | - return wpinv_get_invoice( $invoice_id, true ); |
|
33 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
34 | + return wpinv_get_invoice($invoice_id, true); |
|
35 | 35 | } |
36 | 36 | |
37 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
38 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
37 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
38 | + $invoice = new WPInv_Invoice($invoice_id); |
|
39 | 39 | return $invoice->get_description(); |
40 | 40 | } |
41 | 41 | |
42 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
43 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
42 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
43 | + $invoice = new WPInv_Invoice($invoice_id); |
|
44 | 44 | return $invoice->get_currency(); |
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
48 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
47 | +function wpinv_get_payment_user_email($invoice_id) { |
|
48 | + $invoice = new WPInv_Invoice($invoice_id); |
|
49 | 49 | return $invoice->get_email(); |
50 | 50 | } |
51 | 51 | |
52 | -function wpinv_get_user_id( $invoice_id ) { |
|
53 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
52 | +function wpinv_get_user_id($invoice_id) { |
|
53 | + $invoice = new WPInv_Invoice($invoice_id); |
|
54 | 54 | return $invoice->get_user_id(); |
55 | 55 | } |
56 | 56 | |
57 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
58 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
57 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
58 | + $invoice = new WPInv_Invoice($invoice_id); |
|
59 | 59 | |
60 | - return $invoice->get_status( $return_label ); |
|
60 | + return $invoice->get_status($return_label); |
|
61 | 61 | } |
62 | 62 | |
63 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
64 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
63 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
64 | + $invoice = new WPInv_Invoice($invoice_id); |
|
65 | 65 | |
66 | - return $invoice->get_gateway( $return_label ); |
|
66 | + return $invoice->get_gateway($return_label); |
|
67 | 67 | } |
68 | 68 | |
69 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
70 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
69 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
70 | + $invoice = new WPInv_Invoice($invoice_id); |
|
71 | 71 | |
72 | 72 | return $invoice->get_gateway_title(); |
73 | 73 | } |
74 | 74 | |
75 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
76 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
75 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
76 | + $invoice = new WPInv_Invoice($invoice_id); |
|
77 | 77 | |
78 | 78 | return $invoice->get_transaction_id(); |
79 | 79 | } |
80 | 80 | |
81 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
81 | +function wpinv_get_id_by_transaction_id($key) { |
|
82 | 82 | global $wpdb; |
83 | 83 | |
84 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
84 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
85 | 85 | |
86 | - if ( $invoice_id != NULL ) |
|
86 | + if ($invoice_id != NULL) |
|
87 | 87 | return $invoice_id; |
88 | 88 | |
89 | 89 | return 0; |
90 | 90 | } |
91 | 91 | |
92 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
93 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
92 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
93 | + $invoice = new WPInv_Invoice($invoice_id); |
|
94 | 94 | |
95 | - return $invoice->get_meta( $meta_key, $single ); |
|
95 | + return $invoice->get_meta($meta_key, $single); |
|
96 | 96 | } |
97 | 97 | |
98 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
99 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
98 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
99 | + $invoice = new WPInv_Invoice($invoice_id); |
|
100 | 100 | |
101 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
101 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
102 | 102 | } |
103 | 103 | |
104 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
105 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
104 | +function wpinv_get_items($invoice_id = 0) { |
|
105 | + $invoice = wpinv_get_invoice($invoice_id); |
|
106 | 106 | |
107 | 107 | $items = $invoice->get_items(); |
108 | 108 | $invoice_currency = $invoice->get_currency(); |
109 | 109 | |
110 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
111 | - foreach ( $items as $key => $item ) { |
|
110 | + if (!empty($items) && is_array($items)) { |
|
111 | + foreach ($items as $key => $item) { |
|
112 | 112 | $items[$key]['currency'] = $invoice_currency; |
113 | 113 | |
114 | - if ( !isset( $cart_item['subtotal'] ) ) { |
|
114 | + if (!isset($cart_item['subtotal'])) { |
|
115 | 115 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
116 | 116 | } |
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
120 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
121 | 121 | } |
122 | 122 | |
123 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
124 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
123 | +function wpinv_get_fees($invoice_id = 0) { |
|
124 | + $invoice = wpinv_get_invoice($invoice_id); |
|
125 | 125 | $fees = $invoice->get_fees(); |
126 | 126 | |
127 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
127 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
128 | 128 | } |
129 | 129 | |
130 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
131 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
130 | +function wpinv_get_invoice_ip($invoice_id) { |
|
131 | + $invoice = new WPInv_Invoice($invoice_id); |
|
132 | 132 | return $invoice->get_ip(); |
133 | 133 | } |
134 | 134 | |
135 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
136 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
135 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
136 | + $invoice = new WPInv_Invoice($invoice_id); |
|
137 | 137 | return $invoice->get_user_info(); |
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
141 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
140 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
141 | + $invoice = new WPInv_Invoice($invoice_id); |
|
142 | 142 | |
143 | - return $invoice->get_subtotal( $currency ); |
|
143 | + return $invoice->get_subtotal($currency); |
|
144 | 144 | } |
145 | 145 | |
146 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
147 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
146 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
147 | + $invoice = new WPInv_Invoice($invoice_id); |
|
148 | 148 | |
149 | - return $invoice->get_tax( $currency ); |
|
149 | + return $invoice->get_tax($currency); |
|
150 | 150 | } |
151 | 151 | |
152 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
153 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
152 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
153 | + $invoice = wpinv_get_invoice($invoice_id); |
|
154 | 154 | |
155 | - return $invoice->get_discount( $currency, $dash ); |
|
155 | + return $invoice->get_discount($currency, $dash); |
|
156 | 156 | } |
157 | 157 | |
158 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
159 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
158 | +function wpinv_discount_code($invoice_id = 0) { |
|
159 | + $invoice = new WPInv_Invoice($invoice_id); |
|
160 | 160 | |
161 | 161 | return $invoice->get_discount_code(); |
162 | 162 | } |
163 | 163 | |
164 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
165 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
164 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
165 | + $invoice = new WPInv_Invoice($invoice_id); |
|
166 | 166 | |
167 | - return $invoice->get_total( $currency ); |
|
167 | + return $invoice->get_total($currency); |
|
168 | 168 | } |
169 | 169 | |
170 | -function wpinv_get_date_created( $invoice_id = 0 ) { |
|
171 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
170 | +function wpinv_get_date_created($invoice_id = 0) { |
|
171 | + $invoice = new WPInv_Invoice($invoice_id); |
|
172 | 172 | |
173 | 173 | $date_created = $invoice->get_created_date(); |
174 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : ''; |
|
174 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : ''; |
|
175 | 175 | |
176 | 176 | return $date_created; |
177 | 177 | } |
178 | 178 | |
179 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) { |
|
180 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
179 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '') { |
|
180 | + $invoice = new WPInv_Invoice($invoice_id); |
|
181 | 181 | |
182 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
182 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
183 | 183 | $date_completed = $invoice->get_completed_date(); |
184 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
185 | - if ( $invoice_date == '' ) { |
|
184 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
185 | + if ($invoice_date == '') { |
|
186 | 186 | $date_created = $invoice->get_created_date(); |
187 | - $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
187 | + $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | return $invoice_date; |
191 | 191 | } |
192 | 192 | |
193 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
194 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
193 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
194 | + $invoice = new WPInv_Invoice($invoice_id); |
|
195 | 195 | |
196 | 196 | return $invoice->vat_number; |
197 | 197 | } |
198 | 198 | |
199 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) { |
|
200 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
199 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) { |
|
200 | + $invoice = new WPInv_Invoice($invoice_id); |
|
201 | 201 | |
202 | - return $invoice->add_note( $note, $user_type, $added_by_user ); |
|
202 | + return $invoice->add_note($note, $user_type, $added_by_user); |
|
203 | 203 | } |
204 | 204 | |
205 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
205 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
206 | 206 | global $invoicing; |
207 | 207 | |
208 | - if ( empty( $invoice_id ) ) { |
|
208 | + if (empty($invoice_id)) { |
|
209 | 209 | return NULL; |
210 | 210 | } |
211 | 211 | |
212 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
212 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
213 | 213 | |
214 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
214 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
215 | 215 | } |
216 | 216 | |
217 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
218 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
217 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
218 | + $invoice = new WPInv_Invoice($invoice_id); |
|
219 | 219 | return $invoice->get_key(); |
220 | 220 | } |
221 | 221 | |
222 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
223 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
222 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
223 | + $invoice = new WPInv_Invoice($invoice_id); |
|
224 | 224 | return $invoice->get_number(); |
225 | 225 | } |
226 | 226 | |
227 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
227 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
228 | 228 | $cart_items = wpinv_get_cart_content_details(); |
229 | 229 | $items = array(); |
230 | 230 | |
231 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
231 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
232 | 232 | |
233 | - if( $cart_items ) { |
|
233 | + if ($cart_items) { |
|
234 | 234 | |
235 | - foreach( $cart_items as $item ) { |
|
235 | + foreach ($cart_items as $item) { |
|
236 | 236 | |
237 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
238 | - $items[] = $item; |
|
237 | + if (!in_array($item['id'], $excluded_items)) { |
|
238 | + $items[] = $item; |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
243 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
243 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
244 | 244 | |
245 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
245 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
246 | 246 | } |
247 | 247 | |
248 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
248 | +function wpinv_get_cart_items_subtotal($items) { |
|
249 | 249 | $subtotal = 0.00; |
250 | 250 | |
251 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
252 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
251 | + if (is_array($items) && !empty($items)) { |
|
252 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
253 | 253 | |
254 | - if( is_array( $prices ) ) { |
|
255 | - $subtotal = array_sum( $prices ); |
|
254 | + if (is_array($prices)) { |
|
255 | + $subtotal = array_sum($prices); |
|
256 | 256 | } else { |
257 | 257 | $subtotal = 0.00; |
258 | 258 | } |
259 | 259 | |
260 | - if( $subtotal < 0 ) { |
|
260 | + if ($subtotal < 0) { |
|
261 | 261 | $subtotal = 0.00; |
262 | 262 | } |
263 | 263 | } |
264 | 264 | |
265 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
265 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
266 | 266 | } |
267 | 267 | |
268 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
269 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
270 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
268 | +function wpinv_get_cart_subtotal($items = array()) { |
|
269 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
270 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
271 | 271 | |
272 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
272 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
273 | 273 | } |
274 | 274 | |
275 | -function wpinv_cart_subtotal( $items = array() ) { |
|
276 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) ); |
|
275 | +function wpinv_cart_subtotal($items = array()) { |
|
276 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items))); |
|
277 | 277 | |
278 | 278 | // Todo - Show tax labels here (if needed) |
279 | 279 | |
280 | 280 | return $price; |
281 | 281 | } |
282 | 282 | |
283 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
284 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
285 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
286 | - $cart_tax = (float)wpinv_get_cart_tax( $items ); |
|
283 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
284 | + $subtotal = (float)wpinv_get_cart_subtotal($items); |
|
285 | + $discounts = (float)wpinv_get_cart_discounted_amount($items); |
|
286 | + $cart_tax = (float)wpinv_get_cart_tax($items); |
|
287 | 287 | $fees = (float)wpinv_get_cart_fee_total(); |
288 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
288 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
289 | 289 | $total = 0; |
290 | 290 | } else { |
291 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
291 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
292 | 292 | } |
293 | 293 | |
294 | - if ( $total < 0 ) { |
|
294 | + if ($total < 0) { |
|
295 | 295 | $total = 0.00; |
296 | 296 | } |
297 | 297 | |
298 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
298 | + $total = (float)apply_filters('wpinv_get_cart_total', $total, $items); |
|
299 | 299 | |
300 | - return wpinv_sanitize_amount( $total ); |
|
300 | + return wpinv_sanitize_amount($total); |
|
301 | 301 | } |
302 | 302 | |
303 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
303 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
304 | 304 | global $cart_total; |
305 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) ); |
|
306 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
305 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice))); |
|
306 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
307 | 307 | |
308 | 308 | // Todo - Show tax labels here (if needed) |
309 | 309 | |
310 | 310 | $cart_total = $total; |
311 | 311 | |
312 | - if ( !$echo ) { |
|
312 | + if (!$echo) { |
|
313 | 313 | return $total; |
314 | 314 | } |
315 | 315 | |
316 | 316 | echo $total; |
317 | 317 | } |
318 | 318 | |
319 | -function wpinv_get_cart_tax( $items = array() ) { |
|
319 | +function wpinv_get_cart_tax($items = array()) { |
|
320 | 320 | $cart_tax = 0; |
321 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
321 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
322 | 322 | |
323 | - if ( $items ) { |
|
324 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
323 | + if ($items) { |
|
324 | + $taxes = wp_list_pluck($items, 'tax'); |
|
325 | 325 | |
326 | - if( is_array( $taxes ) ) { |
|
327 | - $cart_tax = array_sum( $taxes ); |
|
326 | + if (is_array($taxes)) { |
|
327 | + $cart_tax = array_sum($taxes); |
|
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
331 | 331 | $cart_tax += wpinv_get_cart_fee_tax(); |
332 | 332 | |
333 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
333 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
334 | 334 | } |
335 | 335 | |
336 | -function wpinv_cart_tax( $items = array(), $echo = false ) { |
|
337 | - $cart_tax = wpinv_get_cart_tax( $items ); |
|
338 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) ); |
|
336 | +function wpinv_cart_tax($items = array(), $echo = false) { |
|
337 | + $cart_tax = wpinv_get_cart_tax($items); |
|
338 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax)); |
|
339 | 339 | |
340 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
340 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
341 | 341 | |
342 | - if ( !$echo ) { |
|
342 | + if (!$echo) { |
|
343 | 343 | return $tax; |
344 | 344 | } |
345 | 345 | |
346 | 346 | echo $tax; |
347 | 347 | } |
348 | 348 | |
349 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
349 | +function wpinv_get_cart_discount_code($items = array()) { |
|
350 | 350 | $invoice = wpinv_get_invoice_cart(); |
351 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
351 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
352 | 352 | |
353 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
353 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
354 | 354 | } |
355 | 355 | |
356 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
357 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
356 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
357 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
358 | 358 | |
359 | - if ( $cart_discount_code != '' ) { |
|
359 | + if ($cart_discount_code != '') { |
|
360 | 360 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
361 | 361 | } |
362 | 362 | |
363 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
363 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
364 | 364 | |
365 | - if ( !$echo ) { |
|
365 | + if (!$echo) { |
|
366 | 366 | return $discount_code; |
367 | 367 | } |
368 | 368 | |
369 | 369 | echo $discount_code; |
370 | 370 | } |
371 | 371 | |
372 | -function wpinv_get_cart_discount( $items = array() ) { |
|
372 | +function wpinv_get_cart_discount($items = array()) { |
|
373 | 373 | $invoice = wpinv_get_invoice_cart(); |
374 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
374 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
375 | 375 | |
376 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
376 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
377 | 377 | } |
378 | 378 | |
379 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
380 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
381 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
379 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
380 | + $cart_discount = wpinv_get_cart_discount($items); |
|
381 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
382 | 382 | |
383 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
383 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
384 | 384 | |
385 | - if ( !$echo ) { |
|
385 | + if (!$echo) { |
|
386 | 386 | return $discount; |
387 | 387 | } |
388 | 388 | |
389 | 389 | echo $discount; |
390 | 390 | } |
391 | 391 | |
392 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
393 | - $item = new WPInv_Item( $item_id ); |
|
392 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
393 | + $item = new WPInv_Item($item_id); |
|
394 | 394 | |
395 | - return $item->get_fees( $type, $item_id ); |
|
395 | + return $item->get_fees($type, $item_id); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | function wpinv_get_cart_fee_total() { |
399 | - $total = 0; |
|
399 | + $total = 0; |
|
400 | 400 | $fees = wpinv_get_cart_fees(); |
401 | 401 | |
402 | - if ( $fees ) { |
|
403 | - foreach ( $fees as $fee_id => $fee ) { |
|
402 | + if ($fees) { |
|
403 | + foreach ($fees as $fee_id => $fee) { |
|
404 | 404 | $total += $fee['amount']; |
405 | 405 | } |
406 | 406 | } |
407 | 407 | |
408 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
408 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | function wpinv_get_cart_fee_tax() { |
412 | 412 | $tax = 0; |
413 | 413 | $fees = wpinv_get_cart_fees(); |
414 | 414 | |
415 | - if ( $fees ) { |
|
416 | - foreach ( $fees as $fee_id => $fee ) { |
|
417 | - if( ! empty( $fee['no_tax'] ) ) { |
|
415 | + if ($fees) { |
|
416 | + foreach ($fees as $fee_id => $fee) { |
|
417 | + if (!empty($fee['no_tax'])) { |
|
418 | 418 | continue; |
419 | 419 | } |
420 | 420 | |
421 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
421 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
425 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | function wpinv_cart_has_recurring_item() { |
429 | 429 | $cart_items = wpinv_get_cart_contents(); |
430 | 430 | |
431 | - if ( empty( $cart_items ) ) { |
|
431 | + if (empty($cart_items)) { |
|
432 | 432 | return false; |
433 | 433 | } |
434 | 434 | |
435 | 435 | $has_subscription = false; |
436 | - foreach( $cart_items as $cart_item ) { |
|
437 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
436 | + foreach ($cart_items as $cart_item) { |
|
437 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
438 | 438 | $has_subscription = true; |
439 | 439 | break; |
440 | 440 | } |
441 | 441 | } |
442 | 442 | |
443 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
443 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | function wpinv_cart_has_free_trial() { |
@@ -448,85 +448,85 @@ discard block |
||
448 | 448 | |
449 | 449 | $free_trial = false; |
450 | 450 | |
451 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
451 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
452 | 452 | $free_trial = true; |
453 | 453 | } |
454 | 454 | |
455 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
455 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | function wpinv_get_cart_contents() { |
459 | 459 | $cart_details = wpinv_get_cart_details(); |
460 | 460 | |
461 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
461 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | function wpinv_get_cart_content_details() { |
465 | 465 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
466 | 466 | $cart_items = wpinv_get_cart_contents(); |
467 | 467 | |
468 | - if ( empty( $cart_items ) ) { |
|
468 | + if (empty($cart_items)) { |
|
469 | 469 | return false; |
470 | 470 | } |
471 | 471 | $invoice = wpinv_get_invoice_cart(); |
472 | 472 | |
473 | 473 | $details = array(); |
474 | - $length = count( $cart_items ) - 1; |
|
474 | + $length = count($cart_items) - 1; |
|
475 | 475 | |
476 | - if ( empty( $_POST['country'] ) ) { |
|
476 | + if (empty($_POST['country'])) { |
|
477 | 477 | $_POST['country'] = $invoice->country; |
478 | 478 | } |
479 | - if ( !isset( $_POST['state'] ) ) { |
|
479 | + if (!isset($_POST['state'])) { |
|
480 | 480 | $_POST['state'] = $invoice->state; |
481 | 481 | } |
482 | 482 | |
483 | - foreach( $cart_items as $key => $item ) { |
|
484 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
485 | - if ( empty( $item_id ) ) { |
|
483 | + foreach ($cart_items as $key => $item) { |
|
484 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
485 | + if (empty($item_id)) { |
|
486 | 486 | continue; |
487 | 487 | } |
488 | 488 | |
489 | 489 | $wpi_current_id = $invoice->ID; |
490 | 490 | $wpi_item_id = $item_id; |
491 | 491 | |
492 | - $item_price = wpinv_get_item_price( $item_id ); |
|
493 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
494 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
495 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
496 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
492 | + $item_price = wpinv_get_item_price($item_id); |
|
493 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
494 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
495 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
496 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
497 | 497 | |
498 | 498 | $subtotal = $item_price * $quantity; |
499 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
500 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
501 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
499 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
500 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
501 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
502 | 502 | |
503 | - if ( wpinv_prices_include_tax() ) { |
|
504 | - $subtotal -= wpinv_format_amount( $tax, NULL, true ); |
|
503 | + if (wpinv_prices_include_tax()) { |
|
504 | + $subtotal -= wpinv_format_amount($tax, NULL, true); |
|
505 | 505 | } |
506 | 506 | |
507 | - $total = $subtotal - $discount + $tax; |
|
507 | + $total = $subtotal - $discount + $tax; |
|
508 | 508 | |
509 | 509 | // Do not allow totals to go negatve |
510 | - if( $total < 0 ) { |
|
510 | + if ($total < 0) { |
|
511 | 511 | $total = 0; |
512 | 512 | } |
513 | 513 | |
514 | - $details[ $key ] = array( |
|
514 | + $details[$key] = array( |
|
515 | 515 | 'id' => $item_id, |
516 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
517 | - 'item_price' => wpinv_format_amount( $item_price, NULL, true ), |
|
516 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
517 | + 'item_price' => wpinv_format_amount($item_price, NULL, true), |
|
518 | 518 | 'quantity' => $quantity, |
519 | - 'discount' => wpinv_format_amount( $discount, NULL, true ), |
|
520 | - 'subtotal' => wpinv_format_amount( $subtotal, NULL, true ), |
|
521 | - 'tax' => wpinv_format_amount( $tax, NULL, true ), |
|
522 | - 'price' => wpinv_format_amount( $total, NULL, true ), |
|
519 | + 'discount' => wpinv_format_amount($discount, NULL, true), |
|
520 | + 'subtotal' => wpinv_format_amount($subtotal, NULL, true), |
|
521 | + 'tax' => wpinv_format_amount($tax, NULL, true), |
|
522 | + 'price' => wpinv_format_amount($total, NULL, true), |
|
523 | 523 | 'vat_rates_class' => $tax_class, |
524 | - 'vat_rate' => wpinv_format_amount( $tax_rate, NULL, true ), |
|
525 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
524 | + 'vat_rate' => wpinv_format_amount($tax_rate, NULL, true), |
|
525 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
526 | 526 | 'fees' => $fees, |
527 | 527 | ); |
528 | 528 | |
529 | - if ( $wpinv_is_last_cart_item ) { |
|
529 | + if ($wpinv_is_last_cart_item) { |
|
530 | 530 | $wpinv_is_last_cart_item = false; |
531 | 531 | $wpinv_flat_discount_total = 0.00; |
532 | 532 | } |
@@ -535,56 +535,56 @@ discard block |
||
535 | 535 | return $details; |
536 | 536 | } |
537 | 537 | |
538 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
538 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
539 | 539 | global $ajax_cart_details; |
540 | 540 | |
541 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
542 | - $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details; |
|
541 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
542 | + $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details; |
|
543 | 543 | |
544 | 544 | $invoice_currency = $invoice->currency; |
545 | 545 | |
546 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
547 | - foreach ( $cart_details as $key => $cart_item ) { |
|
548 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
546 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
547 | + foreach ($cart_details as $key => $cart_item) { |
|
548 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
549 | 549 | |
550 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
551 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
550 | + if (!isset($cart_item['subtotal'])) { |
|
551 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
552 | 552 | } |
553 | 553 | } |
554 | 554 | } |
555 | 555 | |
556 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
556 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
557 | 557 | } |
558 | 558 | |
559 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
560 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
559 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
560 | + $invoice = wpinv_get_invoice($invoice_id); |
|
561 | 561 | |
562 | - $old_status = wpinv_status_nicename( $old_status ); |
|
563 | - $new_status = wpinv_status_nicename( $new_status ); |
|
562 | + $old_status = wpinv_status_nicename($old_status); |
|
563 | + $new_status = wpinv_status_nicename($new_status); |
|
564 | 564 | |
565 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
565 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
566 | 566 | |
567 | 567 | // Add note |
568 | - return $invoice->add_note( $status_change, 0 ); |
|
568 | + return $invoice->add_note($status_change, 0); |
|
569 | 569 | } |
570 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
570 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
571 | 571 | |
572 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
572 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
573 | 573 | global $wpi_has_free_trial; |
574 | 574 | |
575 | 575 | $wpi_has_free_trial = false; |
576 | 576 | |
577 | - if ( $old_status == 'publish' ) { |
|
577 | + if ($old_status == 'publish') { |
|
578 | 578 | return; // Make sure that payments are only paid once |
579 | 579 | } |
580 | 580 | |
581 | 581 | // Make sure the payment completion is only processed when new status is paid |
582 | - if ( $new_status != 'publish' ) { |
|
582 | + if ($new_status != 'publish') { |
|
583 | 583 | return; |
584 | 584 | } |
585 | 585 | |
586 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
587 | - if ( empty( $invoice ) ) { |
|
586 | + $invoice = new WPInv_Invoice($invoice_id); |
|
587 | + if (empty($invoice)) { |
|
588 | 588 | return; |
589 | 589 | } |
590 | 590 | |
@@ -592,58 +592,58 @@ discard block |
||
592 | 592 | $completed_date = $invoice->completed_date; |
593 | 593 | $cart_details = $invoice->cart_details; |
594 | 594 | |
595 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
595 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
596 | 596 | |
597 | - if ( is_array( $cart_details ) ) { |
|
597 | + if (is_array($cart_details)) { |
|
598 | 598 | // Increase purchase count and earnings |
599 | - foreach ( $cart_details as $cart_index => $item ) { |
|
599 | + foreach ($cart_details as $cart_index => $item) { |
|
600 | 600 | // Ensure these actions only run once, ever |
601 | - if ( empty( $completed_date ) ) { |
|
602 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
601 | + if (empty($completed_date)) { |
|
602 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
603 | 603 | } |
604 | 604 | } |
605 | 605 | } |
606 | 606 | |
607 | 607 | // Check for discount codes and increment their use counts |
608 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
609 | - if( ! empty( $discounts ) ) { |
|
610 | - foreach( $discounts as $code ) { |
|
611 | - wpinv_increase_discount_usage( $code ); |
|
608 | + if ($discounts = $invoice->get_discounts(true)) { |
|
609 | + if (!empty($discounts)) { |
|
610 | + foreach ($discounts as $code) { |
|
611 | + wpinv_increase_discount_usage($code); |
|
612 | 612 | } |
613 | 613 | } |
614 | 614 | } |
615 | 615 | |
616 | 616 | // Ensure this action only runs once ever |
617 | - if( empty( $completed_date ) ) { |
|
617 | + if (empty($completed_date)) { |
|
618 | 618 | // Save the completed date |
619 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
619 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
620 | 620 | $invoice->save(); |
621 | 621 | |
622 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
622 | + do_action('wpinv_complete_payment', $invoice_id); |
|
623 | 623 | } |
624 | 624 | |
625 | 625 | // Empty the shopping cart |
626 | 626 | wpinv_empty_cart(); |
627 | 627 | } |
628 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
628 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
629 | 629 | |
630 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
631 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
630 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
631 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id); |
|
632 | 632 | |
633 | - if ( empty( $invoice ) ) { |
|
633 | + if (empty($invoice)) { |
|
634 | 634 | return false; |
635 | 635 | } |
636 | 636 | |
637 | - return $invoice->update_status( $new_status ); |
|
637 | + return $invoice->update_status($new_status); |
|
638 | 638 | } |
639 | 639 | |
640 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
640 | +function wpinv_cart_has_fees($type = 'all') { |
|
641 | 641 | return false; |
642 | 642 | } |
643 | 643 | |
644 | 644 | function wpinv_validate_checkout_fields() { |
645 | 645 | // Check if there is $_POST |
646 | - if ( empty( $_POST ) ) { |
|
646 | + if (empty($_POST)) { |
|
647 | 647 | return false; |
648 | 648 | } |
649 | 649 | |
@@ -655,11 +655,11 @@ discard block |
||
655 | 655 | ); |
656 | 656 | |
657 | 657 | // Validate agree to terms |
658 | - if ( wpinv_get_option( 'show_agree_to_terms', false ) ) { |
|
658 | + if (wpinv_get_option('show_agree_to_terms', false)) { |
|
659 | 659 | wpinv_checkout_validate_agree_to_terms(); |
660 | 660 | } |
661 | 661 | |
662 | - $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user(); |
|
662 | + $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user(); |
|
663 | 663 | |
664 | 664 | // Return collected data |
665 | 665 | return $valid_data; |
@@ -671,20 +671,20 @@ discard block |
||
671 | 671 | $has_subscription = wpinv_cart_has_recurring_item(); |
672 | 672 | |
673 | 673 | // Check if a gateway value is present |
674 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
675 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
674 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
675 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
676 | 676 | |
677 | - if ( '0.00' == wpinv_get_cart_total() ) { |
|
677 | + if ('0.00' == wpinv_get_cart_total()) { |
|
678 | 678 | $gateway = 'manual'; |
679 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
680 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
681 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
682 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) ); |
|
679 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
680 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
681 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
682 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing')); |
|
683 | 683 | } |
684 | 684 | } |
685 | 685 | |
686 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
687 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
686 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
687 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | return $gateway; |
@@ -696,10 +696,10 @@ discard block |
||
696 | 696 | |
697 | 697 | $error = false; |
698 | 698 | // If we have discounts, loop through them |
699 | - if ( ! empty( $discounts ) ) { |
|
700 | - foreach ( $discounts as $discount ) { |
|
699 | + if (!empty($discounts)) { |
|
700 | + foreach ($discounts as $discount) { |
|
701 | 701 | // Check if valid |
702 | - if ( !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) { |
|
702 | + if (!wpinv_is_discount_valid($discount, get_current_user_id())) { |
|
703 | 703 | // Discount is not valid |
704 | 704 | $error = true; |
705 | 705 | } |
@@ -709,20 +709,20 @@ discard block |
||
709 | 709 | return NULL; |
710 | 710 | } |
711 | 711 | |
712 | - if ( $error && !wpinv_get_errors() ) { |
|
713 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
712 | + if ($error && !wpinv_get_errors()) { |
|
713 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
714 | 714 | } |
715 | 715 | |
716 | - return implode( ',', $discounts ); |
|
716 | + return implode(',', $discounts); |
|
717 | 717 | } |
718 | 718 | |
719 | 719 | function wpinv_checkout_validate_cc() { |
720 | 720 | $card_data = wpinv_checkout_get_cc_info(); |
721 | 721 | |
722 | 722 | // Validate the card zip |
723 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
724 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
725 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
723 | + if (!empty($card_data['wpinv_zip'])) { |
|
724 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
725 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
726 | 726 | } |
727 | 727 | } |
728 | 728 | |
@@ -732,28 +732,28 @@ discard block |
||
732 | 732 | |
733 | 733 | function wpinv_checkout_get_cc_info() { |
734 | 734 | $cc_info = array(); |
735 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
736 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
737 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
738 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
739 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
740 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
741 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
742 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
743 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
744 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
735 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
736 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
737 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
738 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
739 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
740 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
741 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
742 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
743 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
744 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
745 | 745 | |
746 | 746 | // Return cc info |
747 | 747 | return $cc_info; |
748 | 748 | } |
749 | 749 | |
750 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
750 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
751 | 751 | $ret = false; |
752 | 752 | |
753 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
753 | + if (empty($zip) || empty($country_code)) |
|
754 | 754 | return $ret; |
755 | 755 | |
756 | - $country_code = strtoupper( $country_code ); |
|
756 | + $country_code = strtoupper($country_code); |
|
757 | 757 | |
758 | 758 | $zip_regex = array( |
759 | 759 | "AD" => "AD\d{3}", |
@@ -913,17 +913,17 @@ discard block |
||
913 | 913 | "ZM" => "\d{5}" |
914 | 914 | ); |
915 | 915 | |
916 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
916 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
917 | 917 | $ret = true; |
918 | 918 | |
919 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
919 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
920 | 920 | } |
921 | 921 | |
922 | 922 | function wpinv_checkout_validate_agree_to_terms() { |
923 | 923 | // Validate agree to terms |
924 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
924 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
925 | 925 | // User did not agree |
926 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
926 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
927 | 927 | } |
928 | 928 | } |
929 | 929 | |
@@ -936,36 +936,36 @@ discard block |
||
936 | 936 | ); |
937 | 937 | |
938 | 938 | // Verify there is a user_ID |
939 | - if ( $user_ID > 0 ) { |
|
939 | + if ($user_ID > 0) { |
|
940 | 940 | // Get the logged in user data |
941 | - $user_data = get_userdata( $user_ID ); |
|
942 | - $required_fields = wpinv_checkout_required_fields(); |
|
941 | + $user_data = get_userdata($user_ID); |
|
942 | + $required_fields = wpinv_checkout_required_fields(); |
|
943 | 943 | |
944 | 944 | // Loop through required fields and show error messages |
945 | - if ( !empty( $required_fields ) ) { |
|
946 | - foreach ( $required_fields as $field_name => $value ) { |
|
947 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
948 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
945 | + if (!empty($required_fields)) { |
|
946 | + foreach ($required_fields as $field_name => $value) { |
|
947 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
948 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
949 | 949 | } |
950 | 950 | } |
951 | 951 | } |
952 | 952 | |
953 | 953 | // Verify data |
954 | - if ( $user_data ) { |
|
954 | + if ($user_data) { |
|
955 | 955 | // Collected logged in user data |
956 | 956 | $valid_user_data = array( |
957 | 957 | 'user_id' => $user_ID, |
958 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
959 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
960 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
958 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
959 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
960 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
961 | 961 | ); |
962 | 962 | |
963 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
964 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
963 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
964 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
965 | 965 | } |
966 | 966 | } else { |
967 | 967 | // Set invalid user error |
968 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
968 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
969 | 969 | } |
970 | 970 | } |
971 | 971 | |
@@ -973,21 +973,21 @@ discard block |
||
973 | 973 | return $valid_user_data; |
974 | 974 | } |
975 | 975 | |
976 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
976 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
977 | 977 | // Initialize user |
978 | 978 | $user = false; |
979 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
979 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
980 | 980 | |
981 | 981 | /*if ( $is_ajax ) { |
982 | 982 | // Do not create or login the user during the ajax submission (check for errors only) |
983 | 983 | return true; |
984 | - } else */if ( is_user_logged_in() ) { |
|
984 | + } else */if (is_user_logged_in()) { |
|
985 | 985 | // Set the valid user as the logged in collected data |
986 | 986 | $user = $valid_data['logged_in_user']; |
987 | 987 | } |
988 | 988 | |
989 | 989 | // Verify we have an user |
990 | - if ( false === $user || empty( $user ) ) { |
|
990 | + if (false === $user || empty($user)) { |
|
991 | 991 | // Return false |
992 | 992 | return false; |
993 | 993 | } |
@@ -1006,11 +1006,11 @@ discard block |
||
1006 | 1006 | 'zip', |
1007 | 1007 | ); |
1008 | 1008 | |
1009 | - foreach ( $address_fields as $field ) { |
|
1010 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
1009 | + foreach ($address_fields as $field) { |
|
1010 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
1011 | 1011 | |
1012 | - if ( !empty( $user['user_id'] ) ) { |
|
1013 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
1012 | + if (!empty($user['user_id'])) { |
|
1013 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
1014 | 1014 | } |
1015 | 1015 | } |
1016 | 1016 | |
@@ -1018,28 +1018,28 @@ discard block |
||
1018 | 1018 | return $user; |
1019 | 1019 | } |
1020 | 1020 | |
1021 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
1021 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
1022 | 1022 | global $wpi_session; |
1023 | 1023 | |
1024 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
1024 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | function wpinv_get_checkout_session() { |
1028 | 1028 | global $wpi_session; |
1029 | 1029 | |
1030 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
1030 | + return $wpi_session->get('wpinv_checkout'); |
|
1031 | 1031 | } |
1032 | 1032 | |
1033 | 1033 | function wpinv_empty_cart() { |
1034 | 1034 | global $wpi_session; |
1035 | 1035 | |
1036 | 1036 | // Remove cart contents |
1037 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
1037 | + $wpi_session->set('wpinv_checkout', NULL); |
|
1038 | 1038 | |
1039 | 1039 | // Remove all cart fees |
1040 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
1040 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
1041 | 1041 | |
1042 | - do_action( 'wpinv_empty_cart' ); |
|
1042 | + do_action('wpinv_empty_cart'); |
|
1043 | 1043 | } |
1044 | 1044 | |
1045 | 1045 | function wpinv_process_checkout() { |
@@ -1051,42 +1051,42 @@ discard block |
||
1051 | 1051 | |
1052 | 1052 | $wpi_checkout_id = $invoice->ID; |
1053 | 1053 | |
1054 | - do_action( 'wpinv_pre_process_checkout' ); |
|
1054 | + do_action('wpinv_pre_process_checkout'); |
|
1055 | 1055 | |
1056 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
1056 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
1057 | 1057 | $valid_data = false; |
1058 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
1058 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
1059 | 1059 | } else { |
1060 | 1060 | // Validate the form $_POST data |
1061 | 1061 | $valid_data = wpinv_validate_checkout_fields(); |
1062 | 1062 | |
1063 | 1063 | // Allow themes and plugins to hook to errors |
1064 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
1064 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
1065 | 1065 | } |
1066 | 1066 | |
1067 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1067 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1068 | 1068 | |
1069 | 1069 | // Validate the user |
1070 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
1070 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
1071 | 1071 | |
1072 | 1072 | // Let extensions validate fields after user is logged in if user has used login/registration form |
1073 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
1073 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
1074 | 1074 | |
1075 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
1076 | - if ( $is_ajax ) { |
|
1077 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
1075 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
1076 | + if ($is_ajax) { |
|
1077 | + do_action('wpinv_ajax_checkout_errors'); |
|
1078 | 1078 | die(); |
1079 | 1079 | } else { |
1080 | 1080 | return false; |
1081 | 1081 | } |
1082 | 1082 | } |
1083 | 1083 | |
1084 | - if ( $is_ajax ) { |
|
1084 | + if ($is_ajax) { |
|
1085 | 1085 | // Save address fields. |
1086 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
1087 | - foreach ( $address_fields as $field ) { |
|
1088 | - if ( isset( $user[$field] ) ) { |
|
1089 | - $invoice->set( $field, $user[$field] ); |
|
1086 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
1087 | + foreach ($address_fields as $field) { |
|
1088 | + if (isset($user[$field])) { |
|
1089 | + $invoice->set($field, $user[$field]); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | $invoice->save(); |
@@ -1094,15 +1094,15 @@ discard block |
||
1094 | 1094 | |
1095 | 1095 | $response['success'] = true; |
1096 | 1096 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
1097 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
1097 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
1098 | 1098 | $response['data']['discount'] = $invoice->get_discount(); |
1099 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
1099 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
1100 | 1100 | $response['data']['tax'] = $invoice->get_tax(); |
1101 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
1101 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
1102 | 1102 | $response['data']['total'] = $invoice->get_total(); |
1103 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
1103 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
1104 | 1104 | |
1105 | - wp_send_json( $response ); |
|
1105 | + wp_send_json($response); |
|
1106 | 1106 | } |
1107 | 1107 | |
1108 | 1108 | $user_info = array( |
@@ -1124,42 +1124,42 @@ discard block |
||
1124 | 1124 | |
1125 | 1125 | // Setup invoice information |
1126 | 1126 | $invoice_data = array( |
1127 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
1127 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
1128 | 1128 | 'items' => $cart_items, |
1129 | 1129 | 'cart_discounts' => $discounts, |
1130 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1131 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
1132 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
1133 | - 'tax' => wpinv_get_cart_tax( $cart_items ), // Taxed amount |
|
1134 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
1130 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1131 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
1132 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
1133 | + 'tax' => wpinv_get_cart_tax($cart_items), // Taxed amount |
|
1134 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
1135 | 1135 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
1136 | 1136 | 'user_email' => $user['email'], |
1137 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
1138 | - 'user_info' => stripslashes_deep( $user_info ), |
|
1137 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
1138 | + 'user_info' => stripslashes_deep($user_info), |
|
1139 | 1139 | 'post_data' => $_POST, |
1140 | 1140 | 'cart_details' => $cart_items, |
1141 | 1141 | 'gateway' => $valid_data['gateway'], |
1142 | 1142 | 'card_info' => $valid_data['cc_info'] |
1143 | 1143 | ); |
1144 | 1144 | |
1145 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
1146 | - if ( is_array( $vat_info ) ) { |
|
1145 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
1146 | + if (is_array($vat_info)) { |
|
1147 | 1147 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
1148 | 1148 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
1149 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1149 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1150 | 1150 | |
1151 | 1151 | // Add the VAT rate to each item in the cart |
1152 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
1152 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
1153 | 1153 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
1154 | - $invoice_data['cart_details'][$key]['vat_rate'] = round( $rate, 3 ); |
|
1154 | + $invoice_data['cart_details'][$key]['vat_rate'] = round($rate, 3); |
|
1155 | 1155 | } |
1156 | 1156 | } |
1157 | 1157 | |
1158 | 1158 | // Save vat fields. |
1159 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
1160 | - foreach ( $address_fields as $field ) { |
|
1161 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
1162 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
1159 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
1160 | + foreach ($address_fields as $field) { |
|
1161 | + if (isset($invoice_data['user_info'][$field])) { |
|
1162 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
1163 | 1163 | } |
1164 | 1164 | |
1165 | 1165 | $invoice->save(); |
@@ -1169,49 +1169,49 @@ discard block |
||
1169 | 1169 | $valid_data['user'] = $user; |
1170 | 1170 | |
1171 | 1171 | // Allow themes and plugins to hook before the gateway |
1172 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
1172 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
1173 | 1173 | |
1174 | 1174 | // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice |
1175 | - if ( !$invoice_data['price'] ) { |
|
1175 | + if (!$invoice_data['price']) { |
|
1176 | 1176 | // Revert to manual |
1177 | 1177 | $invoice_data['gateway'] = 'manual'; |
1178 | 1178 | $_POST['wpi-gateway'] = 'manual'; |
1179 | 1179 | } |
1180 | 1180 | |
1181 | 1181 | // Allow the invoice data to be modified before it is sent to the gateway |
1182 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
1182 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
1183 | 1183 | |
1184 | 1184 | // Setup the data we're storing in the purchase session |
1185 | 1185 | $session_data = $invoice_data; |
1186 | 1186 | // Make sure credit card numbers are never stored in sessions |
1187 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
1188 | - unset( $session_data['card_info']['card_number'] ); |
|
1187 | + if (!empty($session_data['card_info']['card_number'])) { |
|
1188 | + unset($session_data['card_info']['card_number']); |
|
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
1192 | - wpinv_set_checkout_session( $invoice_data ); |
|
1192 | + wpinv_set_checkout_session($invoice_data); |
|
1193 | 1193 | |
1194 | 1194 | // Set gateway |
1195 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
1196 | - $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) ); |
|
1197 | - $invoice->update_meta( '_wpinv_checkout', true ); |
|
1195 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
1196 | + $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live')); |
|
1197 | + $invoice->update_meta('_wpinv_checkout', true); |
|
1198 | 1198 | |
1199 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
1199 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
1200 | 1200 | |
1201 | 1201 | // Send info to the gateway for payment processing |
1202 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
1202 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
1203 | 1203 | die(); |
1204 | 1204 | } |
1205 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
1205 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
1206 | 1206 | |
1207 | -function wpinv_get_invoices( $args ) { |
|
1208 | - $args = wp_parse_args( $args, array( |
|
1209 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
1207 | +function wpinv_get_invoices($args) { |
|
1208 | + $args = wp_parse_args($args, array( |
|
1209 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
1210 | 1210 | 'type' => 'wpi_invoice', |
1211 | 1211 | 'parent' => null, |
1212 | 1212 | 'user' => null, |
1213 | 1213 | 'email' => '', |
1214 | - 'limit' => get_option( 'posts_per_page' ), |
|
1214 | + 'limit' => get_option('posts_per_page'), |
|
1215 | 1215 | 'offset' => null, |
1216 | 1216 | 'page' => 1, |
1217 | 1217 | 'exclude' => array(), |
@@ -1219,7 +1219,7 @@ discard block |
||
1219 | 1219 | 'order' => 'DESC', |
1220 | 1220 | 'return' => 'objects', |
1221 | 1221 | 'paginate' => false, |
1222 | - ) ); |
|
1222 | + )); |
|
1223 | 1223 | |
1224 | 1224 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
1225 | 1225 | $map_legacy = array( |
@@ -1232,18 +1232,18 @@ discard block |
||
1232 | 1232 | 'paged' => 'page', |
1233 | 1233 | ); |
1234 | 1234 | |
1235 | - foreach ( $map_legacy as $from => $to ) { |
|
1236 | - if ( isset( $args[ $from ] ) ) { |
|
1237 | - $args[ $to ] = $args[ $from ]; |
|
1235 | + foreach ($map_legacy as $from => $to) { |
|
1236 | + if (isset($args[$from])) { |
|
1237 | + $args[$to] = $args[$from]; |
|
1238 | 1238 | } |
1239 | 1239 | } |
1240 | 1240 | |
1241 | - if ( get_query_var( 'paged' ) ) |
|
1241 | + if (get_query_var('paged')) |
|
1242 | 1242 | $args['page'] = get_query_var('paged'); |
1243 | - else if ( get_query_var( 'page' ) ) |
|
1244 | - $args['page'] = get_query_var( 'page' ); |
|
1245 | - else if ( !empty( $args[ 'page' ] ) ) |
|
1246 | - $args['page'] = $args[ 'page' ]; |
|
1243 | + else if (get_query_var('page')) |
|
1244 | + $args['page'] = get_query_var('page'); |
|
1245 | + else if (!empty($args['page'])) |
|
1246 | + $args['page'] = $args['page']; |
|
1247 | 1247 | else |
1248 | 1248 | $args['page'] = 1; |
1249 | 1249 | |
@@ -1256,47 +1256,47 @@ discard block |
||
1256 | 1256 | 'post_status' => $args['status'], |
1257 | 1257 | 'posts_per_page' => $args['limit'], |
1258 | 1258 | 'meta_query' => array(), |
1259 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
1259 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
1260 | 1260 | 'fields' => 'ids', |
1261 | 1261 | 'orderby' => $args['orderby'], |
1262 | 1262 | 'order' => $args['order'], |
1263 | 1263 | ); |
1264 | 1264 | |
1265 | - if ( !empty( $args['user'] ) ) { |
|
1266 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
1265 | + if (!empty($args['user'])) { |
|
1266 | + $wp_query_args['author'] = absint($args['user']); |
|
1267 | 1267 | } |
1268 | 1268 | |
1269 | - if ( ! is_null( $args['parent'] ) ) { |
|
1270 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
1269 | + if (!is_null($args['parent'])) { |
|
1270 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
1271 | 1271 | } |
1272 | 1272 | |
1273 | - if ( ! is_null( $args['offset'] ) ) { |
|
1274 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
1273 | + if (!is_null($args['offset'])) { |
|
1274 | + $wp_query_args['offset'] = absint($args['offset']); |
|
1275 | 1275 | } else { |
1276 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
1276 | + $wp_query_args['paged'] = absint($args['page']); |
|
1277 | 1277 | } |
1278 | 1278 | |
1279 | - if ( ! empty( $args['exclude'] ) ) { |
|
1280 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
1279 | + if (!empty($args['exclude'])) { |
|
1280 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
1281 | 1281 | } |
1282 | 1282 | |
1283 | - if ( ! $args['paginate' ] ) { |
|
1283 | + if (!$args['paginate']) { |
|
1284 | 1284 | $wp_query_args['no_found_rows'] = true; |
1285 | 1285 | } |
1286 | 1286 | |
1287 | 1287 | // Get results. |
1288 | - $invoices = new WP_Query( $wp_query_args ); |
|
1288 | + $invoices = new WP_Query($wp_query_args); |
|
1289 | 1289 | |
1290 | - if ( 'objects' === $args['return'] ) { |
|
1291 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
1292 | - } elseif ( 'self' === $args['return'] ) { |
|
1290 | + if ('objects' === $args['return']) { |
|
1291 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
1292 | + } elseif ('self' === $args['return']) { |
|
1293 | 1293 | return $invoices; |
1294 | 1294 | } else { |
1295 | 1295 | $return = $invoices->posts; |
1296 | 1296 | } |
1297 | 1297 | |
1298 | - if ( $args['paginate' ] ) { |
|
1299 | - return (object) array( |
|
1298 | + if ($args['paginate']) { |
|
1299 | + return (object)array( |
|
1300 | 1300 | 'invoices' => $return, |
1301 | 1301 | 'total' => $invoices->found_posts, |
1302 | 1302 | 'max_num_pages' => $invoices->max_num_pages, |
@@ -1308,21 +1308,21 @@ discard block |
||
1308 | 1308 | |
1309 | 1309 | function wpinv_get_user_invoices_columns() { |
1310 | 1310 | $columns = array( |
1311 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
1312 | - 'invoice-date' => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1313 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
1314 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
1315 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
1311 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
1312 | + 'invoice-date' => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'), |
|
1313 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
1314 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
1315 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
1316 | 1316 | ); |
1317 | 1317 | |
1318 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
1318 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
1319 | 1319 | } |
1320 | 1320 | |
1321 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
1321 | +function wpinv_payment_receipt($atts, $content = null) { |
|
1322 | 1322 | global $wpinv_receipt_args; |
1323 | 1323 | |
1324 | - $wpinv_receipt_args = shortcode_atts( array( |
|
1325 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
1324 | + $wpinv_receipt_args = shortcode_atts(array( |
|
1325 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
1326 | 1326 | 'price' => true, |
1327 | 1327 | 'discount' => true, |
1328 | 1328 | 'items' => true, |
@@ -1331,185 +1331,185 @@ discard block |
||
1331 | 1331 | 'invoice_key' => false, |
1332 | 1332 | 'payment_method' => true, |
1333 | 1333 | 'invoice_id' => true |
1334 | - ), $atts, 'wpinv_receipt' ); |
|
1334 | + ), $atts, 'wpinv_receipt'); |
|
1335 | 1335 | |
1336 | 1336 | $session = wpinv_get_checkout_session(); |
1337 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1338 | - $invoice_key = urldecode( $_GET['invoice_key'] ); |
|
1339 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
1337 | + if (isset($_GET['invoice_key'])) { |
|
1338 | + $invoice_key = urldecode($_GET['invoice_key']); |
|
1339 | + } else if ($session && isset($session['invoice_key'])) { |
|
1340 | 1340 | $invoice_key = $session['invoice_key']; |
1341 | - } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
1341 | + } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
1342 | 1342 | $invoice_key = $wpinv_receipt_args['invoice_key']; |
1343 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
1344 | - $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] ); |
|
1343 | + } else if (isset($_GET['invoice-id'])) { |
|
1344 | + $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']); |
|
1345 | 1345 | } |
1346 | 1346 | |
1347 | 1347 | // No key found |
1348 | - if ( ! isset( $invoice_key ) ) { |
|
1348 | + if (!isset($invoice_key)) { |
|
1349 | 1349 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1350 | 1350 | } |
1351 | 1351 | |
1352 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1353 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1354 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1352 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1353 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1354 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1355 | 1355 | $invoice_id = (int)$_GET['invoice-id']; |
1356 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1356 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
1357 | 1357 | } |
1358 | 1358 | |
1359 | 1359 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
1360 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
1360 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
1361 | 1361 | // login redirect |
1362 | - return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>'; |
|
1362 | + return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>'; |
|
1363 | 1363 | } |
1364 | 1364 | |
1365 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
1365 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
1366 | 1366 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1367 | 1367 | } |
1368 | 1368 | |
1369 | 1369 | ob_start(); |
1370 | 1370 | |
1371 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
1371 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
1372 | 1372 | |
1373 | 1373 | $display = ob_get_clean(); |
1374 | 1374 | |
1375 | 1375 | return $display; |
1376 | 1376 | } |
1377 | 1377 | |
1378 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
1378 | +function wpinv_get_invoice_id_by_key($key) { |
|
1379 | 1379 | global $wpdb; |
1380 | 1380 | |
1381 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) ); |
|
1381 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key)); |
|
1382 | 1382 | |
1383 | - if ( $invoice_id != NULL ) |
|
1383 | + if ($invoice_id != NULL) |
|
1384 | 1384 | return $invoice_id; |
1385 | 1385 | |
1386 | 1386 | return 0; |
1387 | 1387 | } |
1388 | 1388 | |
1389 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
1389 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
1390 | 1390 | $return = false; |
1391 | 1391 | |
1392 | - if ( empty( $invoice_key ) ) { |
|
1392 | + if (empty($invoice_key)) { |
|
1393 | 1393 | return $return; |
1394 | 1394 | } |
1395 | 1395 | |
1396 | 1396 | global $wpinv_receipt_args; |
1397 | 1397 | |
1398 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1399 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
1400 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
1398 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
1399 | + if (isset($_GET['invoice-id'])) { |
|
1400 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0; |
|
1401 | 1401 | } |
1402 | 1402 | |
1403 | - $user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] ); |
|
1404 | - $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] ); |
|
1403 | + $user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']); |
|
1404 | + $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']); |
|
1405 | 1405 | |
1406 | - if ( is_user_logged_in() ) { |
|
1407 | - if ( $user_id === (int) get_current_user_id() ) { |
|
1406 | + if (is_user_logged_in()) { |
|
1407 | + if ($user_id === (int)get_current_user_id()) { |
|
1408 | 1408 | $return = true; |
1409 | 1409 | } |
1410 | 1410 | } |
1411 | 1411 | |
1412 | 1412 | $session = wpinv_get_checkout_session(); |
1413 | - if ( ! empty( $session ) && ! is_user_logged_in() ) { |
|
1414 | - if ( $session['invoice_key'] === $invoice_meta['key'] ) { |
|
1413 | + if (!empty($session) && !is_user_logged_in()) { |
|
1414 | + if ($session['invoice_key'] === $invoice_meta['key']) { |
|
1415 | 1415 | $return = true; |
1416 | 1416 | } |
1417 | 1417 | } |
1418 | 1418 | |
1419 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
1419 | + return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
1420 | 1420 | } |
1421 | 1421 | |
1422 | 1422 | function wpinv_pay_for_invoice() { |
1423 | 1423 | global $wpinv_euvat; |
1424 | 1424 | |
1425 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1425 | + if (isset($_GET['invoice_key'])) { |
|
1426 | 1426 | $checkout_uri = wpinv_get_checkout_uri(); |
1427 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
1427 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
1428 | 1428 | |
1429 | - if ( empty( $invoice_key ) ) { |
|
1430 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
1431 | - wp_redirect( $checkout_uri ); |
|
1429 | + if (empty($invoice_key)) { |
|
1430 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
1431 | + wp_redirect($checkout_uri); |
|
1432 | 1432 | wpinv_die(); |
1433 | 1433 | } |
1434 | 1434 | |
1435 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
1435 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
1436 | 1436 | |
1437 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
1438 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1439 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1437 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
1438 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1439 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1440 | 1440 | $invoice_id = (int)$_GET['invoice-id']; |
1441 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
1441 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false; |
|
1442 | 1442 | } |
1443 | 1443 | |
1444 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
1445 | - if ( $invoice->needs_payment() ) { |
|
1444 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
1445 | + if ($invoice->needs_payment()) { |
|
1446 | 1446 | $data = array(); |
1447 | 1447 | $data['invoice_id'] = $invoice_id; |
1448 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
1448 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
1449 | 1449 | |
1450 | - wpinv_set_checkout_session( $data ); |
|
1450 | + wpinv_set_checkout_session($data); |
|
1451 | 1451 | |
1452 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
1452 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
1453 | 1453 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
1454 | 1454 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
1455 | 1455 | |
1456 | - wpinv_recalculate_tax( true ); |
|
1456 | + wpinv_recalculate_tax(true); |
|
1457 | 1457 | } |
1458 | 1458 | |
1459 | 1459 | } else { |
1460 | 1460 | $checkout_uri = $invoice->get_view_url(); |
1461 | 1461 | } |
1462 | 1462 | } else { |
1463 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
1463 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
1464 | 1464 | |
1465 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
1465 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
1466 | 1466 | } |
1467 | 1467 | |
1468 | - wp_redirect( $checkout_uri ); |
|
1468 | + wp_redirect($checkout_uri); |
|
1469 | 1469 | wpinv_die(); |
1470 | 1470 | } |
1471 | 1471 | } |
1472 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
1472 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
1473 | 1473 | |
1474 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
1475 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
1476 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
1474 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
1475 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
1476 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
1477 | 1477 | $user_id = $invoice->get_user_id(); |
1478 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
1478 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
1479 | 1479 | |
1480 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
1481 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
1480 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
1481 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
1482 | 1482 | |
1483 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
1483 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
1484 | 1484 | wpinv_die(); |
1485 | 1485 | } |
1486 | 1486 | } |
1487 | 1487 | } |
1488 | 1488 | } |
1489 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
1489 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
1490 | 1490 | |
1491 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
1492 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
1491 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
1492 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
1493 | 1493 | |
1494 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
1494 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
1495 | 1495 | return false; |
1496 | 1496 | } |
1497 | 1497 | |
1498 | - if ( empty( $transaction_id ) ) { |
|
1498 | + if (empty($transaction_id)) { |
|
1499 | 1499 | $transaction_id = $invoice_id; |
1500 | 1500 | } |
1501 | 1501 | |
1502 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
1502 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
1503 | 1503 | |
1504 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
1504 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
1505 | 1505 | } |
1506 | 1506 | |
1507 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
1508 | - if ( empty( $status_display ) ) { |
|
1509 | - $status_display = wpinv_status_nicename( $status ); |
|
1507 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
1508 | + if (empty($status_display)) { |
|
1509 | + $status_display = wpinv_status_nicename($status); |
|
1510 | 1510 | } |
1511 | 1511 | |
1512 | - switch ( $status ) { |
|
1512 | + switch ($status) { |
|
1513 | 1513 | case 'publish' : |
1514 | 1514 | case 'wpi-renewal' : |
1515 | 1515 | $class = 'label-success'; |
@@ -1534,28 +1534,28 @@ discard block |
||
1534 | 1534 | |
1535 | 1535 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
1536 | 1536 | |
1537 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
1537 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
1538 | 1538 | } |
1539 | 1539 | |
1540 | -function wpinv_format_invoice_number( $number ) { |
|
1541 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
1540 | +function wpinv_format_invoice_number($number) { |
|
1541 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
1542 | 1542 | |
1543 | 1543 | // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release. |
1544 | - if ( $padd === '' || $padd === false || $padd === NULL ) { |
|
1545 | - return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number ); |
|
1544 | + if ($padd === '' || $padd === false || $padd === NULL) { |
|
1545 | + return wp_sprintf(__('WPINV-%d', 'invoicing'), $number); |
|
1546 | 1546 | } |
1547 | 1547 | |
1548 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
1549 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
1548 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
1549 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
1550 | 1550 | |
1551 | - $padd = absint( $padd ); |
|
1552 | - $formatted_number = absint( $number ); |
|
1551 | + $padd = absint($padd); |
|
1552 | + $formatted_number = absint($number); |
|
1553 | 1553 | |
1554 | - if ( $padd > 0 ) { |
|
1555 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
1554 | + if ($padd > 0) { |
|
1555 | + $formatted_number = zeroise($formatted_number, $padd); |
|
1556 | 1556 | } |
1557 | 1557 | |
1558 | 1558 | $formatted_number = $prefix . $formatted_number . $postfix; |
1559 | 1559 | |
1560 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
1560 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
1561 | 1561 | } |
1562 | 1562 | \ No newline at end of file |
@@ -1,121 +1,121 @@ 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_use_taxes() { |
8 | - $ret = wpinv_get_option( 'enable_taxes', false ); |
|
8 | + $ret = wpinv_get_option('enable_taxes', false); |
|
9 | 9 | |
10 | - return (bool) apply_filters( 'wpinv_use_taxes', $ret ); |
|
10 | + return (bool)apply_filters('wpinv_use_taxes', $ret); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | function wpinv_get_tax_rates() { |
14 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
14 | + $rates = get_option('wpinv_tax_rates', array()); |
|
15 | 15 | |
16 | - return apply_filters( 'wpinv_get_tax_rates', $rates ); |
|
16 | + return apply_filters('wpinv_get_tax_rates', $rates); |
|
17 | 17 | } |
18 | 18 | |
19 | -function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) { |
|
19 | +function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) { |
|
20 | 20 | global $wpinv_euvat, $wpi_tax_rates, $wpi_userID; |
21 | - $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array(); |
|
21 | + $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array(); |
|
22 | 22 | |
23 | - if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) { |
|
23 | + if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) { |
|
24 | 24 | return $wpi_tax_rates[$item_id]; |
25 | 25 | } |
26 | 26 | |
27 | - if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) { |
|
27 | + if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) { |
|
28 | 28 | $wpi_tax_rates[$item_id] = 0; |
29 | 29 | return 0; |
30 | 30 | } |
31 | 31 | |
32 | 32 | $is_global = false; |
33 | - if ( $item_id == 'global' ) { |
|
33 | + if ($item_id == 'global') { |
|
34 | 34 | $is_global = true; |
35 | 35 | $item_id = 0; |
36 | 36 | } |
37 | 37 | |
38 | - $rate = (float)wpinv_get_option( 'tax_rate', 0 ); |
|
39 | - $user_address = wpinv_get_user_address( $wpi_userID ); |
|
38 | + $rate = (float)wpinv_get_option('tax_rate', 0); |
|
39 | + $user_address = wpinv_get_user_address($wpi_userID); |
|
40 | 40 | |
41 | - if( empty( $country ) ) { |
|
42 | - if( !empty( $_POST['wpinv_country'] ) ) { |
|
41 | + if (empty($country)) { |
|
42 | + if (!empty($_POST['wpinv_country'])) { |
|
43 | 43 | $country = $_POST['wpinv_country']; |
44 | - } elseif( !empty( $_POST['wpinv_country'] ) ) { |
|
44 | + } elseif (!empty($_POST['wpinv_country'])) { |
|
45 | 45 | $country = $_POST['wpinv_country']; |
46 | - } elseif( !empty( $_POST['country'] ) ) { |
|
46 | + } elseif (!empty($_POST['country'])) { |
|
47 | 47 | $country = $_POST['country']; |
48 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
48 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
49 | 49 | $country = $user_address['country']; |
50 | 50 | } |
51 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
51 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
52 | 52 | } |
53 | 53 | |
54 | - if( empty( $state ) ) { |
|
55 | - if( !empty( $_POST['wpinv_state'] ) ) { |
|
54 | + if (empty($state)) { |
|
55 | + if (!empty($_POST['wpinv_state'])) { |
|
56 | 56 | $state = $_POST['wpinv_state']; |
57 | - } elseif( !empty( $_POST['wpinv_state'] ) ) { |
|
57 | + } elseif (!empty($_POST['wpinv_state'])) { |
|
58 | 58 | $state = $_POST['wpinv_state']; |
59 | - } elseif( !empty( $_POST['state'] ) ) { |
|
59 | + } elseif (!empty($_POST['state'])) { |
|
60 | 60 | $state = $_POST['state']; |
61 | - } elseif( is_user_logged_in() && !empty( $user_address ) ) { |
|
61 | + } elseif (is_user_logged_in() && !empty($user_address)) { |
|
62 | 62 | $state = $user_address['state']; |
63 | 63 | } |
64 | - $state = !empty( $state ) ? $state : wpinv_get_default_state(); |
|
64 | + $state = !empty($state) ? $state : wpinv_get_default_state(); |
|
65 | 65 | } |
66 | 66 | |
67 | - if( !empty( $country ) ) { |
|
68 | - $tax_rates = wpinv_get_tax_rates(); |
|
67 | + if (!empty($country)) { |
|
68 | + $tax_rates = wpinv_get_tax_rates(); |
|
69 | 69 | |
70 | - if( !empty( $tax_rates ) ) { |
|
70 | + if (!empty($tax_rates)) { |
|
71 | 71 | // Locate the tax rate for this country / state, if it exists |
72 | - foreach( $tax_rates as $key => $tax_rate ) { |
|
73 | - if( $country != $tax_rate['country'] ) |
|
72 | + foreach ($tax_rates as $key => $tax_rate) { |
|
73 | + if ($country != $tax_rate['country']) |
|
74 | 74 | continue; |
75 | 75 | |
76 | - if( !empty( $tax_rate['global'] ) ) { |
|
77 | - if( !empty( $tax_rate['rate'] ) ) { |
|
78 | - $rate = number_format( $tax_rate['rate'], 4 ); |
|
76 | + if (!empty($tax_rate['global'])) { |
|
77 | + if (!empty($tax_rate['rate'])) { |
|
78 | + $rate = number_format($tax_rate['rate'], 4); |
|
79 | 79 | } |
80 | 80 | } else { |
81 | 81 | |
82 | - if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) |
|
82 | + if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state'])) |
|
83 | 83 | continue; |
84 | 84 | |
85 | 85 | $state_rate = $tax_rate['rate']; |
86 | - if( 0 !== $state_rate || !empty( $state_rate ) ) { |
|
87 | - $rate = number_format( $state_rate, 4 ); |
|
86 | + if (0 !== $state_rate || !empty($state_rate)) { |
|
87 | + $rate = number_format($state_rate, 4); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
94 | - $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id ); |
|
94 | + $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id); |
|
95 | 95 | |
96 | - if ( !empty( $item_id ) ) { |
|
96 | + if (!empty($item_id)) { |
|
97 | 97 | $wpi_tax_rates[$item_id] = $rate; |
98 | - } else if ( $is_global ) { |
|
98 | + } else if ($is_global) { |
|
99 | 99 | $wpi_tax_rates['global'] = $rate; |
100 | 100 | } |
101 | 101 | |
102 | 102 | return $rate; |
103 | 103 | } |
104 | 104 | |
105 | -function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) { |
|
106 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
107 | - $rate = round( $rate, 4 ); |
|
105 | +function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) { |
|
106 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
107 | + $rate = round($rate, 4); |
|
108 | 108 | $formatted = $rate .= '%'; |
109 | - return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id ); |
|
109 | + return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id); |
|
110 | 110 | } |
111 | 111 | |
112 | -function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) { |
|
113 | - $rate = wpinv_get_tax_rate( $country, $state, $item_id ); |
|
112 | +function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) { |
|
113 | + $rate = wpinv_get_tax_rate($country, $state, $item_id); |
|
114 | 114 | $tax = 0.00; |
115 | 115 | |
116 | - if ( wpinv_use_taxes() ) { |
|
117 | - if ( wpinv_prices_include_tax() ) { |
|
118 | - $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) ); |
|
116 | + if (wpinv_use_taxes()) { |
|
117 | + if (wpinv_prices_include_tax()) { |
|
118 | + $pre_tax = ($amount / ((1 + $rate) * 0.01)); |
|
119 | 119 | $tax = $amount - $pre_tax; |
120 | 120 | } else { |
121 | 121 | $tax = $amount * $rate * 0.01; |
@@ -123,46 +123,46 @@ discard block |
||
123 | 123 | |
124 | 124 | } |
125 | 125 | |
126 | - return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id ); |
|
126 | + return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | function wpinv_prices_include_tax() { |
130 | 130 | return false; // TODO |
131 | - $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
131 | + $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
132 | 132 | |
133 | - return apply_filters( 'wpinv_prices_include_tax', $ret ); |
|
133 | + return apply_filters('wpinv_prices_include_tax', $ret); |
|
134 | 134 | } |
135 | 135 | |
136 | -function wpinv_sales_tax_for_year( $year = null ) { |
|
137 | - return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) ); |
|
136 | +function wpinv_sales_tax_for_year($year = null) { |
|
137 | + return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year))); |
|
138 | 138 | } |
139 | 139 | |
140 | -function wpinv_get_sales_tax_for_year( $year = null ) { |
|
140 | +function wpinv_get_sales_tax_for_year($year = null) { |
|
141 | 141 | global $wpdb; |
142 | 142 | |
143 | 143 | // Start at zero |
144 | 144 | $tax = 0; |
145 | 145 | |
146 | - if ( ! empty( $year ) ) { |
|
146 | + if (!empty($year)) { |
|
147 | 147 | $args = array( |
148 | 148 | 'post_type' => 'wpi_invoice', |
149 | - 'post_status' => array( 'publish' ), |
|
149 | + 'post_status' => array('publish'), |
|
150 | 150 | 'posts_per_page' => -1, |
151 | 151 | 'year' => $year, |
152 | 152 | 'fields' => 'ids' |
153 | 153 | ); |
154 | 154 | |
155 | - $payments = get_posts( $args ); |
|
156 | - $payment_ids = implode( ',', $payments ); |
|
155 | + $payments = get_posts($args); |
|
156 | + $payment_ids = implode(',', $payments); |
|
157 | 157 | |
158 | - if ( count( $payments ) > 0 ) { |
|
158 | + if (count($payments) > 0) { |
|
159 | 159 | $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )"; |
160 | - $tax = $wpdb->get_var( $sql ); |
|
160 | + $tax = $wpdb->get_var($sql); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | - return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year ); |
|
165 | + return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | function wpinv_is_cart_taxed() { |
@@ -171,33 +171,33 @@ discard block |
||
171 | 171 | |
172 | 172 | function wpinv_prices_show_tax_on_checkout() { |
173 | 173 | return false; // TODO |
174 | - $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() ); |
|
174 | + $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes()); |
|
175 | 175 | |
176 | - return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret ); |
|
176 | + return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | function wpinv_display_tax_rate() { |
180 | - $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false ); |
|
180 | + $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false); |
|
181 | 181 | |
182 | - return apply_filters( 'wpinv_display_tax_rate', $ret ); |
|
182 | + return apply_filters('wpinv_display_tax_rate', $ret); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | function wpinv_cart_needs_tax_address_fields() { |
186 | - if( !wpinv_is_cart_taxed() ) |
|
186 | + if (!wpinv_is_cart_taxed()) |
|
187 | 187 | return false; |
188 | 188 | |
189 | - return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' ); |
|
189 | + return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields'); |
|
190 | 190 | } |
191 | 191 | |
192 | -function wpinv_item_is_tax_exclusive( $item_id = 0 ) { |
|
193 | - $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false ); |
|
194 | - return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id ); |
|
192 | +function wpinv_item_is_tax_exclusive($item_id = 0) { |
|
193 | + $ret = (bool)get_post_meta($item_id, '_wpinv_tax_exclusive', false); |
|
194 | + return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id); |
|
195 | 195 | } |
196 | 196 | |
197 | -function wpinv_currency_decimal_filter( $decimals = 2 ) { |
|
197 | +function wpinv_currency_decimal_filter($decimals = 2) { |
|
198 | 198 | $currency = wpinv_get_currency(); |
199 | 199 | |
200 | - switch ( $currency ) { |
|
200 | + switch ($currency) { |
|
201 | 201 | case 'RIAL' : |
202 | 202 | case 'JPY' : |
203 | 203 | case 'TWD' : |
@@ -206,48 +206,48 @@ discard block |
||
206 | 206 | break; |
207 | 207 | } |
208 | 208 | |
209 | - return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency ); |
|
209 | + return apply_filters('wpinv_currency_decimal_count', $decimals, $currency); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | function wpinv_tax_amount() { |
213 | 213 | $output = 0.00; |
214 | 214 | |
215 | - return apply_filters( 'wpinv_tax_amount', $output ); |
|
215 | + return apply_filters('wpinv_tax_amount', $output); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | function wpinv_recalculated_tax() { |
219 | - define( 'WPINV_RECALCTAX', true ); |
|
219 | + define('WPINV_RECALCTAX', true); |
|
220 | 220 | } |
221 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 ); |
|
221 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1); |
|
222 | 222 | |
223 | -function wpinv_recalculate_tax( $return = false ) { |
|
223 | +function wpinv_recalculate_tax($return = false) { |
|
224 | 224 | $invoice_id = (int)wpinv_get_invoice_cart_id(); |
225 | - if ( empty( $invoice_id ) ) { |
|
225 | + if (empty($invoice_id)) { |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
229 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
229 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
230 | 230 | |
231 | - if ( empty( $invoice ) ) { |
|
231 | + if (empty($invoice)) { |
|
232 | 232 | return false; |
233 | 233 | } |
234 | 234 | |
235 | - if ( empty( $_POST['country'] ) ) { |
|
235 | + if (empty($_POST['country'])) { |
|
236 | 236 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
237 | 237 | } |
238 | 238 | |
239 | 239 | $invoice->country = sanitize_text_field($_POST['country']); |
240 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
240 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
241 | 241 | if (isset($_POST['state'])) { |
242 | 242 | $invoice->state = sanitize_text_field($_POST['state']); |
243 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
243 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | $invoice->cart_details = wpinv_get_cart_content_details(); |
247 | 247 | |
248 | - $subtotal = wpinv_get_cart_subtotal( $invoice->cart_details ); |
|
249 | - $tax = wpinv_get_cart_tax( $invoice->cart_details ); |
|
250 | - $total = wpinv_get_cart_total( $invoice->cart_details ); |
|
248 | + $subtotal = wpinv_get_cart_subtotal($invoice->cart_details); |
|
249 | + $tax = wpinv_get_cart_tax($invoice->cart_details); |
|
250 | + $total = wpinv_get_cart_total($invoice->cart_details); |
|
251 | 251 | |
252 | 252 | $invoice->tax = $tax; |
253 | 253 | $invoice->subtotal = $subtotal; |
@@ -255,60 +255,60 @@ discard block |
||
255 | 255 | |
256 | 256 | $invoice->save(); |
257 | 257 | |
258 | - if ( $invoice->is_free_trial() ) { |
|
258 | + if ($invoice->is_free_trial()) { |
|
259 | 259 | $total = 0; |
260 | 260 | } |
261 | 261 | |
262 | 262 | $response = array( |
263 | - 'total' => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ), |
|
263 | + 'total' => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'), |
|
264 | 264 | 'total_raw' => $total, |
265 | - 'html' => wpinv_checkout_cart( $invoice->cart_details, false ), |
|
265 | + 'html' => wpinv_checkout_cart($invoice->cart_details, false), |
|
266 | 266 | ); |
267 | 267 | |
268 | - if ( $return ) { |
|
268 | + if ($return) { |
|
269 | 269 | return $response; |
270 | 270 | } |
271 | 271 | |
272 | - wp_send_json( $response ); |
|
272 | + wp_send_json($response); |
|
273 | 273 | } |
274 | -add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
275 | -add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' ); |
|
274 | +add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
275 | +add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax'); |
|
276 | 276 | |
277 | 277 | // VAT Settings |
278 | -function wpinv_vat_rate_add_callback( $args ) { |
|
278 | +function wpinv_vat_rate_add_callback($args) { |
|
279 | 279 | ?> |
280 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
280 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
281 | 281 | <?php |
282 | 282 | } |
283 | 283 | |
284 | -function wpinv_vat_rate_delete_callback( $args ) { |
|
284 | +function wpinv_vat_rate_delete_callback($args) { |
|
285 | 285 | global $wpinv_euvat; |
286 | 286 | |
287 | 287 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
288 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : ''; |
|
289 | - if ( isset( $vat_classes[$vat_class] ) ) { |
|
288 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : ''; |
|
289 | + if (isset($vat_classes[$vat_class])) { |
|
290 | 290 | ?> |
291 | - <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
291 | + <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" /> <i style="display:none;" class="fa fa-refresh fa-spin"></i></p> |
|
292 | 292 | <?php |
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
296 | -function wpinv_vat_rates_callback( $args ) { |
|
296 | +function wpinv_vat_rates_callback($args) { |
|
297 | 297 | global $wpinv_euvat; |
298 | 298 | |
299 | 299 | $vat_classes = $wpinv_euvat->get_rate_classes(); |
300 | - $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard'; |
|
300 | + $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard'; |
|
301 | 301 | |
302 | 302 | $eu_states = $wpinv_euvat->get_eu_states(); |
303 | 303 | $countries = wpinv_get_country_list(); |
304 | 304 | $vat_groups = $wpinv_euvat->get_vat_groups(); |
305 | - $rates = $wpinv_euvat->get_vat_rates( $vat_class ); |
|
305 | + $rates = $wpinv_euvat->get_vat_rates($vat_class); |
|
306 | 306 | ob_start(); |
307 | 307 | ?> |
308 | 308 | </td><tr> |
309 | 309 | <td colspan="2" class="wpinv_vat_tdbox"> |
310 | - <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" /> |
|
311 | - <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p> |
|
310 | + <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" /> |
|
311 | + <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p> |
|
312 | 312 | <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts"> |
313 | 313 | <colgroup> |
314 | 314 | <col width="50px" /> |
@@ -320,43 +320,43 @@ discard block |
||
320 | 320 | </colgroup> |
321 | 321 | <thead> |
322 | 322 | <tr> |
323 | - <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
324 | - <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
325 | - <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
326 | - <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th> |
|
327 | - <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th> |
|
323 | + <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th> |
|
324 | + <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
325 | + <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
326 | + <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th> |
|
327 | + <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th> |
|
328 | 328 | </tr> |
329 | 329 | </thead> |
330 | 330 | <tbody> |
331 | - <?php if( !empty( $eu_states ) ) { ?> |
|
331 | + <?php if (!empty($eu_states)) { ?> |
|
332 | 332 | <?php |
333 | - foreach ( $eu_states as $state ) { |
|
334 | - $country_name = isset( $countries[$state] ) ? $countries[$state] : ''; |
|
333 | + foreach ($eu_states as $state) { |
|
334 | + $country_name = isset($countries[$state]) ? $countries[$state] : ''; |
|
335 | 335 | |
336 | 336 | // Filter the rate for each country |
337 | - $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } ); |
|
337 | + $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } ); |
|
338 | 338 | |
339 | 339 | // If one does not exist create a default |
340 | - $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array(); |
|
340 | + $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array(); |
|
341 | 341 | |
342 | - $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true; |
|
343 | - $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : ''; |
|
344 | - $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : ''; |
|
345 | - $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' ); |
|
342 | + $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true; |
|
343 | + $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : ''; |
|
344 | + $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : ''; |
|
345 | + $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced'); |
|
346 | 346 | ?> |
347 | 347 | <tr> |
348 | 348 | <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td> |
349 | 349 | <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td> |
350 | 350 | <td class="wpinv_vat_global"> |
351 | - <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" /> |
|
352 | - <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
353 | - <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" /> |
|
351 | + <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" /> |
|
352 | + <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
353 | + <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" /> |
|
354 | 354 | </td> |
355 | - <td class="wpinv_vat_rate"><input type="number" class="small-text" step="0.10" min="0.00" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
356 | - <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
355 | + <td class="wpinv_vat_rate"><input type="number" class="small-text" step="0.10" min="0.00" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td> |
|
356 | + <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td> |
|
357 | 357 | <td class="wpinv_vat_group"> |
358 | 358 | <?php |
359 | - echo wpinv_html_select( array( |
|
359 | + echo wpinv_html_select(array( |
|
360 | 360 | 'name' => 'vat_rates[' . $state . '][group]', |
361 | 361 | 'selected' => $vat_group, |
362 | 362 | 'id' => 'vat_rates[' . $state . '][group]', |
@@ -366,14 +366,14 @@ discard block |
||
366 | 366 | 'chosen' => false, |
367 | 367 | 'show_option_all' => false, |
368 | 368 | 'show_option_none' => false |
369 | - ) ); |
|
369 | + )); |
|
370 | 370 | ?> |
371 | 371 | </td> |
372 | 372 | </tr> |
373 | 373 | <?php } ?> |
374 | 374 | <tr> |
375 | 375 | <td colspan="6" style="background-color:#fafafa;"> |
376 | - <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
376 | + <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span> |
|
377 | 377 | </td> |
378 | 378 | </tr> |
379 | 379 | <?php } ?> |
@@ -385,35 +385,35 @@ discard block |
||
385 | 385 | echo $content; |
386 | 386 | } |
387 | 387 | |
388 | -function wpinv_vat_number_callback( $args ) { |
|
388 | +function wpinv_vat_number_callback($args) { |
|
389 | 389 | global $wpinv_euvat; |
390 | 390 | |
391 | 391 | $vat_number = $wpinv_euvat->get_vat_number(); |
392 | 392 | $vat_valid = $wpinv_euvat->is_vat_validated(); |
393 | 393 | |
394 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
395 | - $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' ); |
|
394 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
395 | + $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing'); |
|
396 | 396 | $disabled = $vat_valid ? 'disabled="disabled"' : " "; |
397 | 397 | |
398 | - $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>'; |
|
399 | - $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>'; |
|
398 | + $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>'; |
|
399 | + $html .= '<span> <input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>'; |
|
400 | 400 | $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>'; |
401 | - $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>'; |
|
402 | - $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">'; |
|
401 | + $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>'; |
|
402 | + $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">'; |
|
403 | 403 | |
404 | 404 | echo $html; |
405 | 405 | } |
406 | 406 | |
407 | -function wpinv_eu_fallback_rate_callback( $args ) { |
|
407 | +function wpinv_eu_fallback_rate_callback($args) { |
|
408 | 408 | global $wpinv_options; |
409 | 409 | |
410 | - $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' ); |
|
411 | - $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small'; |
|
410 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : ''); |
|
411 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small'; |
|
412 | 412 | |
413 | - $html = '<input type="number" min="0", max="99.99" step="0.10" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
414 | - $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>'; |
|
415 | - $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>'; |
|
416 | - $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
413 | + $html = '<input type="number" min="0", max="99.99" step="0.10" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />'; |
|
414 | + $html .= '<span> <input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>'; |
|
415 | + $html .= '<span> <input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>'; |
|
416 | + $html .= '<span> <input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" /> <i style="display:none" class="fa fa-refresh fa-spin"></i></span>'; |
|
417 | 417 | $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>'; |
418 | 418 | echo $html; |
419 | 419 | ?> |
@@ -421,36 +421,36 @@ discard block |
||
421 | 421 | <?php |
422 | 422 | } |
423 | 423 | |
424 | -function wpinv_vat_ip_lookup_callback( $args ) { |
|
424 | +function wpinv_vat_ip_lookup_callback($args) { |
|
425 | 425 | global $wpinv_options, $wpinv_euvat; |
426 | 426 | |
427 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : 'default' ); |
|
427 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default'); |
|
428 | 428 | |
429 | 429 | $options = array(); |
430 | - if ( function_exists( 'geoip_country_code_by_name' ) ) { |
|
431 | - $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' ); |
|
430 | + if (function_exists('geoip_country_code_by_name')) { |
|
431 | + $options['geoip'] = __('PHP GeoIP extension', 'invoicing'); |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | $geoip2_database = $wpinv_euvat->geoip2_country_dbfile(); |
435 | 435 | |
436 | - if ( !function_exists( 'bcadd' ) ) { |
|
437 | - $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' ); |
|
436 | + if (!function_exists('bcadd')) { |
|
437 | + $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing'); |
|
438 | 438 | } else { |
439 | - $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : ''; |
|
439 | + $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : ''; |
|
440 | 440 | } |
441 | 441 | |
442 | - if ( $geoip2_database !== false && empty( $geoip2_message ) ) { |
|
443 | - $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' ); |
|
442 | + if ($geoip2_database !== false && empty($geoip2_message)) { |
|
443 | + $options['geoip2'] = __('GeoIP2 Database', 'invoicing'); |
|
444 | 444 | } |
445 | 445 | |
446 | - if ( function_exists( 'simplexml_load_file' ) ) { |
|
447 | - $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' ); |
|
446 | + if (function_exists('simplexml_load_file')) { |
|
447 | + $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing'); |
|
448 | 448 | } |
449 | 449 | |
450 | - $options['site'] = __( 'Use default country', 'invoicing' ); |
|
451 | - $options['default'] = __( 'Auto', 'invoicing' ); |
|
450 | + $options['site'] = __('Use default country', 'invoicing'); |
|
451 | + $options['default'] = __('Auto', 'invoicing'); |
|
452 | 452 | |
453 | - $html = wpinv_html_select( array( |
|
453 | + $html = wpinv_html_select(array( |
|
454 | 454 | 'name' => "wpinv_settings[{$args['id']}]", |
455 | 455 | 'selected' => $value, |
456 | 456 | 'id' => "wpinv_settings[{$args['id']}]", |
@@ -463,23 +463,23 @@ discard block |
||
463 | 463 | )); |
464 | 464 | |
465 | 465 | $desc = '<label for="wpinv_settings[' . $args['id'] . ']">'; |
466 | - $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' ); |
|
466 | + $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing'); |
|
467 | 467 | $desc .= '<p>'; |
468 | - if ( empty( $geoip2_message ) ) { |
|
469 | - if ( $geoip2_database ) { |
|
468 | + if (empty($geoip2_message)) { |
|
469 | + if ($geoip2_database) { |
|
470 | 470 | $last_updated = ''; |
471 | - if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) { |
|
472 | - $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated ); |
|
473 | - $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated ); |
|
471 | + if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) { |
|
472 | + $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated); |
|
473 | + $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated); |
|
474 | 474 | } |
475 | - $desc .= __( 'GeoIP2 database exists:', 'invoicing' ) . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>'; |
|
475 | + $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . ' <input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>'; |
|
476 | 476 | } else { |
477 | - $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __( 'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' ); |
|
477 | + $desc .= __('GeoIP2 database does not exist:', 'invoicing') . ' <input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing'); |
|
478 | 478 | } |
479 | 479 | } else { |
480 | 480 | $desc .= $geoip2_message; |
481 | 481 | } |
482 | - $desc .= '</p><p>'. __( 'GeoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
482 | + $desc .= '</p><p>' . __('GeoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>'; |
|
483 | 483 | $desc .= '</label>'; |
484 | 484 | |
485 | 485 | $html .= $desc; |
@@ -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_format_amount( $subtotal, NULL, true ); |
|
137 | - $invoice->tax = wpinv_format_amount( $tax, NULL, true ); |
|
138 | - $invoice->discount = wpinv_format_amount( $discount, NULL, true ); |
|
139 | - $invoice->total = wpinv_format_amount( $total, NULL, true ); |
|
136 | + $invoice->subtotal = wpinv_format_amount($subtotal, NULL, true); |
|
137 | + $invoice->tax = wpinv_format_amount($tax, NULL, true); |
|
138 | + $invoice->discount = wpinv_format_amount($discount, NULL, true); |
|
139 | + $invoice->total = wpinv_format_amount($total, NULL, true); |
|
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_format_amount( $initial ); |
|
418 | - $recurring_total = wpinv_format_amount( $recurring ); |
|
416 | +function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') { |
|
417 | + $initial_total = wpinv_format_amount($initial); |
|
418 | + $recurring_total = wpinv_format_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( $initial_total, $currency ); |
|
431 | - $recurring_amount = wpinv_price( $recurring_total, $currency ); |
|
430 | + $initial_amount = wpinv_price($initial_total, $currency); |
|
431 | + $recurring_amount = wpinv_price($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 |