@@ -36,7 +36,7 @@ |
||
36 | 36 | add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' ); |
37 | 37 | } |
38 | 38 | |
39 | - remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
39 | + remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
40 | 40 | } |
41 | 41 | add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
42 | 42 |
@@ -1,74 +1,74 @@ 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-payment-form-design', __( 'Payment Form', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
29 | - add_meta_box( 'wpinv-payment-form-shortcode', __( 'Shortcode', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_shortcode', 'wpi_payment_form', 'side' ); |
|
28 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
29 | + add_meta_box('wpinv-payment-form-shortcode', __('Shortcode', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_shortcode', 'wpi_payment_form', 'side'); |
|
30 | 30 | |
31 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' ); |
|
32 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
33 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' ); |
|
31 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high'); |
|
32 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
33 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high'); |
|
34 | 34 | |
35 | - if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
|
36 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' ); |
|
35 | + if (!empty($post->ID) && get_post_meta($post->ID, 'payment_form_data', true)) { |
|
36 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
40 | 40 | } |
41 | -add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 ); |
|
41 | +add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2); |
|
42 | 42 | |
43 | -function wpinv_save_meta_boxes( $post_id, $post, $update = false ) { |
|
44 | - remove_action( 'save_post', __FUNCTION__ ); |
|
43 | +function wpinv_save_meta_boxes($post_id, $post, $update = false) { |
|
44 | + remove_action('save_post', __FUNCTION__); |
|
45 | 45 | |
46 | 46 | // $post_id and $post are required |
47 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
47 | + if (empty($post_id) || empty($post)) { |
|
48 | 48 | return; |
49 | 49 | } |
50 | 50 | |
51 | - if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) { |
|
51 | + if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
55 | 55 | // Dont' save meta boxes for revisions or autosaves |
56 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
56 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | - if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) { |
|
61 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
60 | + if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') { |
|
61 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
65 | - if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) { |
|
66 | - WPInv_Meta_Box_Items::save( $post_id, $_POST, $post ); |
|
65 | + if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) { |
|
66 | + WPInv_Meta_Box_Items::save($post_id, $_POST, $post); |
|
67 | 67 | } |
68 | - } else if ( $post->post_type == 'wpi_item' ) { |
|
68 | + } else if ($post->post_type == 'wpi_item') { |
|
69 | 69 | // verify nonce |
70 | - if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) { |
|
71 | - $fields = array(); |
|
70 | + if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) { |
|
71 | + $fields = array(); |
|
72 | 72 | $fields['_wpinv_price'] = 'wpinv_item_price'; |
73 | 73 | $fields['_wpinv_vat_class'] = 'wpinv_vat_class'; |
74 | 74 | $fields['_wpinv_vat_rule'] = 'wpinv_vat_rules'; |
@@ -83,96 +83,96 @@ discard block |
||
83 | 83 | $fields['_wpinv_dynamic_pricing'] = 'wpinv_name_your_price'; |
84 | 84 | $fields['_minimum_price'] = 'wpinv_minimum_price'; |
85 | 85 | |
86 | - if ( !isset( $_POST['wpinv_is_recurring'] ) ) { |
|
86 | + if (!isset($_POST['wpinv_is_recurring'])) { |
|
87 | 87 | $_POST['wpinv_is_recurring'] = 0; |
88 | 88 | } |
89 | 89 | |
90 | - if ( !isset( $_POST['wpinv_name_your_price'] ) ) { |
|
90 | + if (!isset($_POST['wpinv_name_your_price'])) { |
|
91 | 91 | $_POST['wpinv_name_your_price'] = 0; |
92 | 92 | } |
93 | 93 | |
94 | - if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) { |
|
94 | + if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) { |
|
95 | 95 | $_POST['wpinv_free_trial'] = 0; |
96 | 96 | } |
97 | 97 | |
98 | - foreach ( $fields as $field => $name ) { |
|
99 | - if ( isset( $_POST[ $name ] ) ) { |
|
100 | - $allowed = apply_filters( 'wpinv_item_allowed_save_meta_value', true, $field, $post_id ); |
|
98 | + foreach ($fields as $field => $name) { |
|
99 | + if (isset($_POST[$name])) { |
|
100 | + $allowed = apply_filters('wpinv_item_allowed_save_meta_value', true, $field, $post_id); |
|
101 | 101 | |
102 | - if ( !$allowed ) { |
|
102 | + if (!$allowed) { |
|
103 | 103 | continue; |
104 | 104 | } |
105 | 105 | |
106 | - if ( $field == '_wpinv_price' ) { |
|
107 | - $value = wpinv_sanitize_amount( $_POST[ $name ] ); |
|
106 | + if ($field == '_wpinv_price') { |
|
107 | + $value = wpinv_sanitize_amount($_POST[$name]); |
|
108 | 108 | } else { |
109 | - $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ]; |
|
109 | + $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name]; |
|
110 | 110 | } |
111 | 111 | |
112 | - $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name ); |
|
113 | - update_post_meta( $post_id, $field, $value ); |
|
112 | + $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name); |
|
113 | + update_post_meta($post_id, $field, $value); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | - if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) { |
|
118 | - update_post_meta( $post_id, '_wpinv_custom_id', $post_id ); |
|
117 | + if (!get_post_meta($post_id, '_wpinv_custom_id', true)) { |
|
118 | + update_post_meta($post_id, '_wpinv_custom_id', $post_id); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
123 | -add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 ); |
|
123 | +add_action('save_post', 'wpinv_save_meta_boxes', 10, 3); |
|
124 | 124 | |
125 | 125 | function wpinv_register_item_meta_boxes() { |
126 | 126 | global $wpinv_euvat; |
127 | 127 | |
128 | - add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' ); |
|
128 | + add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high'); |
|
129 | 129 | |
130 | - if ( $wpinv_euvat->allow_vat_rules() ) { |
|
131 | - add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' ); |
|
130 | + if ($wpinv_euvat->allow_vat_rules()) { |
|
131 | + add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high'); |
|
132 | 132 | } |
133 | 133 | |
134 | - if ( $wpinv_euvat->allow_vat_classes() ) { |
|
135 | - add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' ); |
|
134 | + if ($wpinv_euvat->allow_vat_classes()) { |
|
135 | + add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high'); |
|
136 | 136 | } |
137 | 137 | |
138 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' ); |
|
139 | - add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' ); |
|
138 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core'); |
|
139 | + add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core'); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | function wpinv_register_discount_meta_boxes() { |
143 | - add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' ); |
|
143 | + add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high'); |
|
144 | 144 | } |
145 | 145 | |
146 | -function wpinv_discount_metabox_details( $post ) { |
|
146 | +function wpinv_discount_metabox_details($post) { |
|
147 | 147 | $discount_id = $post->ID; |
148 | - $discount = wpinv_get_discount( $discount_id ); |
|
148 | + $discount = wpinv_get_discount($discount_id); |
|
149 | 149 | |
150 | - $type = wpinv_get_discount_type( $discount_id ); |
|
151 | - $item_reqs = wpinv_get_discount_item_reqs( $discount_id ); |
|
152 | - $excluded_items = wpinv_get_discount_excluded_items( $discount_id ); |
|
153 | - $min_total = wpinv_get_discount_min_total( $discount_id ); |
|
154 | - $max_total = wpinv_get_discount_max_total( $discount_id ); |
|
155 | - $max_uses = wpinv_get_discount_max_uses( $discount_id ); |
|
156 | - $single_use = wpinv_discount_is_single_use( $discount_id ); |
|
157 | - $recurring = (bool)wpinv_discount_is_recurring( $discount_id ); |
|
158 | - $start_date = wpinv_get_discount_start_date( $discount_id ); |
|
159 | - $expiration_date = wpinv_get_discount_expiration( $discount_id ); |
|
150 | + $type = wpinv_get_discount_type($discount_id); |
|
151 | + $item_reqs = wpinv_get_discount_item_reqs($discount_id); |
|
152 | + $excluded_items = wpinv_get_discount_excluded_items($discount_id); |
|
153 | + $min_total = wpinv_get_discount_min_total($discount_id); |
|
154 | + $max_total = wpinv_get_discount_max_total($discount_id); |
|
155 | + $max_uses = wpinv_get_discount_max_uses($discount_id); |
|
156 | + $single_use = wpinv_discount_is_single_use($discount_id); |
|
157 | + $recurring = (bool) wpinv_discount_is_recurring($discount_id); |
|
158 | + $start_date = wpinv_get_discount_start_date($discount_id); |
|
159 | + $expiration_date = wpinv_get_discount_expiration($discount_id); |
|
160 | 160 | |
161 | - if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) { |
|
162 | - $start_time = strtotime( $start_date ); |
|
163 | - $start_h = date_i18n( 'H', $start_time ); |
|
164 | - $start_m = date_i18n( 'i', $start_time ); |
|
165 | - $start_date = date_i18n( 'Y-m-d', $start_time ); |
|
161 | + if (!empty($start_date) && strpos($start_date, '0000') === false) { |
|
162 | + $start_time = strtotime($start_date); |
|
163 | + $start_h = date_i18n('H', $start_time); |
|
164 | + $start_m = date_i18n('i', $start_time); |
|
165 | + $start_date = date_i18n('Y-m-d', $start_time); |
|
166 | 166 | } else { |
167 | 167 | $start_h = '00'; |
168 | 168 | $start_m = '00'; |
169 | 169 | } |
170 | 170 | |
171 | - if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) { |
|
172 | - $expiration_time = strtotime( $expiration_date ); |
|
173 | - $expiration_h = date_i18n( 'H', $expiration_time ); |
|
174 | - $expiration_m = date_i18n( 'i', $expiration_time ); |
|
175 | - $expiration_date = date_i18n( 'Y-m-d', $expiration_time ); |
|
171 | + if (!empty($expiration_date) && strpos($expiration_date, '0000') === false) { |
|
172 | + $expiration_time = strtotime($expiration_date); |
|
173 | + $expiration_h = date_i18n('H', $expiration_time); |
|
174 | + $expiration_m = date_i18n('i', $expiration_time); |
|
175 | + $expiration_date = date_i18n('Y-m-d', $expiration_time); |
|
176 | 176 | } else { |
177 | 177 | $expiration_h = '23'; |
178 | 178 | $expiration_m = '59'; |
@@ -182,207 +182,207 @@ discard block |
||
182 | 182 | $max_total = $max_total > 0 ? $max_total : ''; |
183 | 183 | $max_uses = $max_uses > 0 ? $max_uses : ''; |
184 | 184 | ?> |
185 | -<?php do_action( 'wpinv_discount_form_top', $post ); ?> |
|
186 | -<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?> |
|
185 | +<?php do_action('wpinv_discount_form_top', $post); ?> |
|
186 | +<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?> |
|
187 | 187 | <table class="form-table wpi-form-table"> |
188 | 188 | <tbody> |
189 | - <?php do_action( 'wpinv_discount_form_first', $post ); ?> |
|
190 | - <?php do_action( 'wpinv_discount_form_before_code', $post ); ?> |
|
189 | + <?php do_action('wpinv_discount_form_first', $post); ?> |
|
190 | + <?php do_action('wpinv_discount_form_before_code', $post); ?> |
|
191 | 191 | <tr> |
192 | 192 | <th valign="top" scope="row"> |
193 | - <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label> |
|
193 | + <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label> |
|
194 | 194 | </th> |
195 | 195 | <td> |
196 | - <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required> |
|
197 | - <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p> |
|
196 | + <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required> |
|
197 | + <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p> |
|
198 | 198 | </td> |
199 | 199 | </tr> |
200 | - <?php do_action( 'wpinv_discount_form_before_type', $post ); ?> |
|
200 | + <?php do_action('wpinv_discount_form_before_type', $post); ?> |
|
201 | 201 | <tr> |
202 | 202 | <th valign="top" scope="row"> |
203 | - <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label> |
|
203 | + <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label> |
|
204 | 204 | </th> |
205 | 205 | <td> |
206 | 206 | <select id="wpinv_discount_type" name="type" class="medium-text wpi_select2"> |
207 | - <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?> |
|
208 | - <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option> |
|
207 | + <?php foreach (wpinv_get_discount_types() as $value => $label) { ?> |
|
208 | + <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option> |
|
209 | 209 | <?php } ?> |
210 | 210 | </select> |
211 | - <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p> |
|
211 | + <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p> |
|
212 | 212 | </td> |
213 | 213 | </tr> |
214 | - <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?> |
|
214 | + <?php do_action('wpinv_discount_form_before_amount', $post); ?> |
|
215 | 215 | <tr> |
216 | 216 | <th valign="top" scope="row"> |
217 | - <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label> |
|
217 | + <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label> |
|
218 | 218 | </th> |
219 | 219 | <td> |
220 | - <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> |
|
221 | - <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p> |
|
222 | - <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p> |
|
220 | + <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> |
|
221 | + <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p> |
|
222 | + <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p> |
|
223 | 223 | </td> |
224 | 224 | </tr> |
225 | - <?php do_action( 'wpinv_discount_form_before_items', $post ); ?> |
|
225 | + <?php do_action('wpinv_discount_form_before_items', $post); ?> |
|
226 | 226 | <tr> |
227 | 227 | <th valign="top" scope="row"> |
228 | - <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label> |
|
228 | + <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label> |
|
229 | 229 | </th> |
230 | 230 | <td> |
231 | - <p><?php echo wpinv_item_dropdown( array( |
|
231 | + <p><?php echo wpinv_item_dropdown(array( |
|
232 | 232 | 'name' => 'items[]', |
233 | 233 | 'id' => 'items', |
234 | 234 | 'selected' => $item_reqs, |
235 | 235 | 'multiple' => true, |
236 | 236 | 'class' => 'medium-text wpi_select2', |
237 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
237 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
238 | 238 | 'show_recurring' => true, |
239 | - ) ); ?> |
|
239 | + )); ?> |
|
240 | 240 | </p> |
241 | - <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> |
|
241 | + <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> |
|
242 | 242 | </td> |
243 | 243 | </tr> |
244 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?> |
|
244 | + <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?> |
|
245 | 245 | <tr> |
246 | 246 | <th valign="top" scope="row"> |
247 | - <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label> |
|
247 | + <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label> |
|
248 | 248 | </th> |
249 | 249 | <td> |
250 | - <p><?php echo wpinv_item_dropdown( array( |
|
250 | + <p><?php echo wpinv_item_dropdown(array( |
|
251 | 251 | 'name' => 'excluded_items[]', |
252 | 252 | 'id' => 'excluded_items', |
253 | 253 | 'selected' => $excluded_items, |
254 | 254 | 'multiple' => true, |
255 | 255 | 'class' => 'medium-text wpi_select2', |
256 | - 'placeholder' => __( 'Select one or more Items', 'invoicing' ), |
|
256 | + 'placeholder' => __('Select one or more Items', 'invoicing'), |
|
257 | 257 | 'show_recurring' => true, |
258 | - ) ); ?> |
|
258 | + )); ?> |
|
259 | 259 | </p> |
260 | - <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p> |
|
260 | + <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p> |
|
261 | 261 | </td> |
262 | 262 | </tr> |
263 | - <?php do_action( 'wpinv_discount_form_before_start', $post ); ?> |
|
263 | + <?php do_action('wpinv_discount_form_before_start', $post); ?> |
|
264 | 264 | <tr> |
265 | 265 | <th valign="top" scope="row"> |
266 | - <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label> |
|
266 | + <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label> |
|
267 | 267 | </th> |
268 | 268 | <td> |
269 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( $start_date ); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
270 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
271 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option> |
|
269 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr($start_date); ?>"> @ <select id="wpinv_discount_start_h" name="start_h"> |
|
270 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
271 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_h); ?>><?php echo $value; ?></option> |
|
272 | 272 | <?php } ?> |
273 | 273 | </select> : <select id="wpinv_discount_start_m" name="start_m"> |
274 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
275 | - <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option> |
|
274 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
275 | + <option value="<?php echo $value; ?>" <?php selected($value, $start_m); ?>><?php echo $value; ?></option> |
|
276 | 276 | <?php } ?> |
277 | 277 | </select> |
278 | - <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> |
|
278 | + <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> |
|
279 | 279 | </td> |
280 | 280 | </tr> |
281 | - <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?> |
|
281 | + <?php do_action('wpinv_discount_form_before_expiration', $post); ?> |
|
282 | 282 | <tr> |
283 | 283 | <th valign="top" scope="row"> |
284 | - <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label> |
|
284 | + <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label> |
|
285 | 285 | </th> |
286 | 286 | <td> |
287 | - <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( $expiration_date ); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
288 | - <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
289 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option> |
|
287 | + <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr($expiration_date); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h"> |
|
288 | + <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
289 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_h); ?>><?php echo $value; ?></option> |
|
290 | 290 | <?php } ?> |
291 | 291 | </select> : <select id="wpinv_discount_expiration_m" name="expiration_m"> |
292 | - <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?> |
|
293 | - <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option> |
|
292 | + <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?> |
|
293 | + <option value="<?php echo $value; ?>" <?php selected($value, $expiration_m); ?>><?php echo $value; ?></option> |
|
294 | 294 | <?php } ?> |
295 | 295 | </select> |
296 | - <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> |
|
296 | + <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> |
|
297 | 297 | </td> |
298 | 298 | </tr> |
299 | - <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?> |
|
299 | + <?php do_action('wpinv_discount_form_before_min_total', $post); ?> |
|
300 | 300 | <tr> |
301 | 301 | <th valign="top" scope="row"> |
302 | - <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label> |
|
302 | + <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label> |
|
303 | 303 | </th> |
304 | 304 | <td> |
305 | 305 | <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>"> |
306 | - <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
306 | + <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
307 | 307 | </td> |
308 | 308 | </tr> |
309 | - <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?> |
|
309 | + <?php do_action('wpinv_discount_form_before_max_total', $post); ?> |
|
310 | 310 | <tr> |
311 | 311 | <th valign="top" scope="row"> |
312 | - <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label> |
|
312 | + <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label> |
|
313 | 313 | </th> |
314 | 314 | <td> |
315 | 315 | <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>"> |
316 | - <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p> |
|
316 | + <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p> |
|
317 | 317 | </td> |
318 | 318 | </tr> |
319 | - <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?> |
|
319 | + <?php do_action('wpinv_discount_form_before_recurring', $post); ?> |
|
320 | 320 | <tr> |
321 | 321 | <th valign="top" scope="row"> |
322 | - <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label> |
|
322 | + <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label> |
|
323 | 323 | </th> |
324 | 324 | <td> |
325 | 325 | <select id="wpinv_discount_recurring" name="recurring" class="medium-text wpi_select2"> |
326 | - <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option> |
|
327 | - <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option> |
|
326 | + <option value="0" <?php selected(false, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option> |
|
327 | + <option value="1" <?php selected(true, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option> |
|
328 | 328 | </select> |
329 | - <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> |
|
329 | + <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> |
|
330 | 330 | </td> |
331 | 331 | </tr> |
332 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?> |
|
332 | + <?php do_action('wpinv_discount_form_before_max_uses', $post); ?> |
|
333 | 333 | <tr> |
334 | 334 | <th valign="top" scope="row"> |
335 | - <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label> |
|
335 | + <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label> |
|
336 | 336 | </th> |
337 | 337 | <td> |
338 | 338 | <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>"> |
339 | - <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p> |
|
339 | + <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p> |
|
340 | 340 | </td> |
341 | 341 | </tr> |
342 | - <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?> |
|
342 | + <?php do_action('wpinv_discount_form_before_single_use', $post); ?> |
|
343 | 343 | <tr> |
344 | 344 | <th valign="top" scope="row"> |
345 | - <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label> |
|
345 | + <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label> |
|
346 | 346 | </th> |
347 | 347 | <td> |
348 | - <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>> |
|
349 | - <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span> |
|
348 | + <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>> |
|
349 | + <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span> |
|
350 | 350 | </td> |
351 | 351 | </tr> |
352 | - <?php do_action( 'wpinv_discount_form_last', $post ); ?> |
|
352 | + <?php do_action('wpinv_discount_form_last', $post); ?> |
|
353 | 353 | </tbody> |
354 | 354 | </table> |
355 | -<?php do_action( 'wpinv_discount_form_bottom', $post ); ?> |
|
355 | +<?php do_action('wpinv_discount_form_bottom', $post); ?> |
|
356 | 356 | <?php |
357 | 357 | } |
358 | 358 | |
359 | -function wpinv_discount_metabox_save( $post_id, $post, $update = false ) { |
|
360 | - $post_type = !empty( $post ) ? $post->post_type : ''; |
|
359 | +function wpinv_discount_metabox_save($post_id, $post, $update = false) { |
|
360 | + $post_type = !empty($post) ? $post->post_type : ''; |
|
361 | 361 | |
362 | - if ( $post_type != 'wpi_discount' ) { |
|
362 | + if ($post_type != 'wpi_discount') { |
|
363 | 363 | return; |
364 | 364 | } |
365 | 365 | |
366 | - 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' ) ) ) { |
|
366 | + 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'))) { |
|
367 | 367 | return; |
368 | 368 | } |
369 | 369 | |
370 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
370 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
371 | 371 | return; |
372 | 372 | } |
373 | 373 | |
374 | - if ( !current_user_can( wpinv_get_capability(), $post_id ) ) { |
|
374 | + if (!current_user_can(wpinv_get_capability(), $post_id)) { |
|
375 | 375 | return; |
376 | 376 | } |
377 | 377 | |
378 | - if ( !empty( $_POST['start'] ) && isset( $_POST['start_h'] ) && isset( $_POST['start_m'] ) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '' ) { |
|
378 | + if (!empty($_POST['start']) && isset($_POST['start_h']) && isset($_POST['start_m']) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '') { |
|
379 | 379 | $_POST['start'] = $_POST['start'] . ' ' . $_POST['start_h'] . ':' . $_POST['start_m']; |
380 | 380 | } |
381 | 381 | |
382 | - if ( !empty( $_POST['expiration'] ) && isset( $_POST['expiration_h'] ) && isset( $_POST['expiration_m'] ) ) { |
|
382 | + if (!empty($_POST['expiration']) && isset($_POST['expiration_h']) && isset($_POST['expiration_m'])) { |
|
383 | 383 | $_POST['expiration'] = $_POST['expiration'] . ' ' . $_POST['expiration_h'] . ':' . $_POST['expiration_m']; |
384 | 384 | } |
385 | 385 | |
386 | - return /** @scrutinizer ignore-call */ wpinv_store_discount( $post_id, $_POST, $post, $update ); |
|
386 | + return /** @scrutinizer ignore-call */ wpinv_store_discount($post_id, $_POST, $post, $update); |
|
387 | 387 | } |
388 | -add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 ); |
|
389 | 388 | \ No newline at end of file |
389 | +add_action('save_post', 'wpinv_discount_metabox_save', 10, 3); |
|
390 | 390 | \ No newline at end of file |
@@ -1,7 +1,7 @@ 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_Payment_Form { |
@@ -11,23 +11,23 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @param WP_Post $post |
13 | 13 | */ |
14 | - public static function output_details( $post ) { |
|
15 | - $details = get_post_meta( $post->ID, 'payment_form_data', true ); |
|
14 | + public static function output_details($post) { |
|
15 | + $details = get_post_meta($post->ID, 'payment_form_data', true); |
|
16 | 16 | |
17 | - if ( ! is_array( $details ) ) { |
|
17 | + if (!is_array($details)) { |
|
18 | 18 | return; |
19 | 19 | } |
20 | 20 | |
21 | 21 | echo '<div class="gdmbx2-wrap form-table"> <div class="gdmbx2-metabox gdmbx-field-list">'; |
22 | 22 | |
23 | - foreach ( $details as $key => $value ) { |
|
24 | - $key = sanitize_text_field( $key ); |
|
23 | + foreach ($details as $key => $value) { |
|
24 | + $key = sanitize_text_field($key); |
|
25 | 25 | |
26 | - if ( is_array( $value ) ) { |
|
27 | - $value = implode( ',', $value ); |
|
26 | + if (is_array($value)) { |
|
27 | + $value = implode(',', $value); |
|
28 | 28 | } |
29 | 29 | |
30 | - $value = esc_html( $value ); |
|
30 | + $value = esc_html($value); |
|
31 | 31 | |
32 | 32 | echo "<div class='gdmbx-row gdmbx-type-select'>"; |
33 | 33 | echo "<div class='gdmbx-th'><label>$key:</label></div>"; |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @param WP_Post $post |
45 | 45 | */ |
46 | - public static function output_shortcode( $post ) { |
|
46 | + public static function output_shortcode($post) { |
|
47 | 47 | |
48 | - if ( ! is_numeric( $post ) ) { |
|
48 | + if (!is_numeric($post)) { |
|
49 | 49 | $post = $post->ID; |
50 | 50 | } |
51 | 51 | |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @param WP_Post $post |
59 | 59 | */ |
60 | - public static function output ( $post ) { |
|
61 | - $success_page = get_post_meta( $post->ID, 'wpinv_success_page', true ); |
|
62 | - $success_page = empty( $success_page ) ? wpinv_get_success_page_uri() : $success_page |
|
60 | + public static function output($post) { |
|
61 | + $success_page = get_post_meta($post->ID, 'wpinv_success_page', true); |
|
62 | + $success_page = empty($success_page) ? wpinv_get_success_page_uri() : $success_page |
|
63 | 63 | ?> |
64 | 64 | |
65 | 65 | <div id="wpinv-form-builder" style="display: flex; flex-flow: wrap;"> |
@@ -67,20 +67,20 @@ discard block |
||
67 | 67 | <div class="wpinv-form-builder-left bsui" style="flex: 0 0 320px;"> |
68 | 68 | <ul class="wpinv-form-builder-tabs nav nav-tabs"> |
69 | 69 | <li class='nav-item' v-if="active_tab!='new_item'"> |
70 | - <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e( 'Add new element', 'invoicing' ); ?></a> |
|
70 | + <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e('Add new element', 'invoicing'); ?></a> |
|
71 | 71 | </li> |
72 | 72 | <li class='nav-item' v-if='false'> |
73 | - <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e( 'Edit element', 'invoicing' ); ?></a> |
|
73 | + <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e('Edit element', 'invoicing'); ?></a> |
|
74 | 74 | </li> |
75 | 75 | <li class='nav-item' v-if='false'> |
76 | - <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e( 'Settings', 'invoicing' ); ?></a> |
|
76 | + <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e('Settings', 'invoicing'); ?></a> |
|
77 | 77 | </li> |
78 | 78 | </ul> |
79 | 79 | |
80 | 80 | <div class="wpinv-form-builder-tab-content bsui" style="margin-top: 16px;"> |
81 | 81 | <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'"> |
82 | 82 | <div class="wpinv-form-builder-add-field-types"> |
83 | - <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small> |
|
83 | + <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small> |
|
84 | 84 | <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable"> |
85 | 85 | <li v-for="element in elements" style="width: 49%; background-color: #fafafa; margin-bottom: 9px; cursor: move; border: 1px solid #eeeeee;" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }"> |
86 | 86 | <button class="button btn" style="width: 100%; cursor: move;"> |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | |
96 | 96 | <div class="wpinv-form-builder-tab-pane bsui" v-if="active_tab=='edit_item'" style="font-size: 16px;"> |
97 | 97 | <div class="wpinv-form-builder-edit-field-wrapper"> |
98 | - <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?> |
|
98 | + <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?> |
|
99 | 99 | <div> |
100 | - <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Field', 'invoicing' ); ?></button> |
|
100 | + <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Field', 'invoicing'); ?></button> |
|
101 | 101 | </div> |
102 | 102 | </div> |
103 | 103 | </div> |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | <div class="wpinv-form-builder-settings-wrapper"> |
107 | 107 | |
108 | 108 | <div class='form-group'> |
109 | - <label for="wpi-success-page"><?php _e( 'Success Page', 'invoicing' ); ?></label> |
|
110 | - <input placeholder="https://" id='wpi-success-page' value="<?php echo esc_url( $success_page ); ?>" class='form-control' type='text'> |
|
111 | - <small class='form-text text-muted'><?php _e( 'Where should we redirect users after successfuly completing their payment?', 'invoicing' ); ?></small> |
|
109 | + <label for="wpi-success-page"><?php _e('Success Page', 'invoicing'); ?></label> |
|
110 | + <input placeholder="https://" id='wpi-success-page' value="<?php echo esc_url($success_page); ?>" class='form-control' type='text'> |
|
111 | + <small class='form-text text-muted'><?php _e('Where should we redirect users after successfuly completing their payment?', 'invoicing'); ?></small> |
|
112 | 112 | </div> |
113 | 113 | |
114 | 114 | </div> |
@@ -119,12 +119,12 @@ discard block |
||
119 | 119 | |
120 | 120 | <div class="wpinv-form-builder-right" style="flex: 1; padding-top: 40px;border-left: 1px solid #ddd;padding-left: 20px;min-height: 520px;margin-left: 10px;"> |
121 | 121 | |
122 | - <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small> |
|
123 | - <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p> |
|
122 | + <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small> |
|
123 | + <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p> |
|
124 | 124 | |
125 | 125 | <draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 16px;"> |
126 | 126 | <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="{ active: active_form_element==form_element && active_tab=='edit_item' }" @click="active_tab = 'edit_item'; active_form_element = form_element"> |
127 | - <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?> |
|
127 | + <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?> |
|
128 | 128 | </div> |
129 | 129 | </draggable> |
130 | 130 | </div> |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | <textarea style="display:none;" name="wpinv_form_items" v-model="itemString"></textarea> |
134 | 134 | </div> |
135 | 135 | |
136 | - <?php wp_nonce_field( 'wpinv_save_payment_form', 'wpinv_save_payment_form' ) ;?> |
|
136 | + <?php wp_nonce_field('wpinv_save_payment_form', 'wpinv_save_payment_form'); ?> |
|
137 | 137 | |
138 | 138 | <?php |
139 | 139 | } |
@@ -141,83 +141,83 @@ discard block |
||
141 | 141 | /** |
142 | 142 | * Saves our payment forms. |
143 | 143 | */ |
144 | - public static function save( $post_id, $post ) { |
|
144 | + public static function save($post_id, $post) { |
|
145 | 145 | |
146 | - remove_action( 'save_post', 'WPInv_Meta_Box_Payment_Form::save' ); |
|
146 | + remove_action('save_post', 'WPInv_Meta_Box_Payment_Form::save'); |
|
147 | 147 | |
148 | 148 | // $post_id and $post are required. |
149 | - if ( empty( $post_id ) || empty( $post ) ) { |
|
149 | + if (empty($post_id) || empty($post)) { |
|
150 | 150 | return; |
151 | 151 | } |
152 | 152 | |
153 | 153 | // Ensure that this user can edit the post. |
154 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
154 | + if (!current_user_can('edit_post', $post_id)) { |
|
155 | 155 | return; |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Dont' save meta boxes for revisions or autosaves |
159 | - if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
159 | + if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
160 | 160 | return; |
161 | 161 | } |
162 | 162 | |
163 | 163 | // Do not save for ajax requests. |
164 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
164 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
165 | 165 | return; |
166 | 166 | } |
167 | 167 | |
168 | 168 | // Confirm the security nonce. |
169 | - if ( empty( $_POST['wpinv_save_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form' ) ) { |
|
169 | + if (empty($_POST['wpinv_save_payment_form']) || !wp_verify_nonce($_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form')) { |
|
170 | 170 | return; |
171 | 171 | } |
172 | 172 | |
173 | 173 | // Save form items. |
174 | - $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true ); |
|
174 | + $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true); |
|
175 | 175 | |
176 | - if ( empty( $form_items ) ) { |
|
176 | + if (empty($form_items)) { |
|
177 | 177 | $form_items = array(); |
178 | 178 | } |
179 | 179 | |
180 | - update_post_meta( $post_id, 'wpinv_form_items', self::maybe_save_items( $form_items ) ); |
|
180 | + update_post_meta($post_id, 'wpinv_form_items', self::maybe_save_items($form_items)); |
|
181 | 181 | |
182 | 182 | // Save form elements. |
183 | - $wpinv_form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true ); |
|
184 | - if ( empty( $wpinv_form_elements ) ) { |
|
183 | + $wpinv_form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true); |
|
184 | + if (empty($wpinv_form_elements)) { |
|
185 | 185 | $wpinv_form_elements = array(); |
186 | 186 | } |
187 | 187 | |
188 | - update_post_meta( $post_id, 'wpinv_form_elements', $wpinv_form_elements ); |
|
188 | + update_post_meta($post_id, 'wpinv_form_elements', $wpinv_form_elements); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | 192 | * Saves unsaved form items. |
193 | 193 | */ |
194 | - public static function maybe_save_items( $items ) { |
|
194 | + public static function maybe_save_items($items) { |
|
195 | 195 | |
196 | 196 | $saved = array(); |
197 | 197 | |
198 | - foreach( $items as $item ) { |
|
198 | + foreach ($items as $item) { |
|
199 | 199 | |
200 | - if ( is_numeric( $item['id'] ) ) { |
|
200 | + if (is_numeric($item['id'])) { |
|
201 | 201 | $saved[] = $item; |
202 | 202 | continue; |
203 | 203 | } |
204 | 204 | |
205 | 205 | $data = array( |
206 | - 'post_title' => sanitize_text_field( $item['title'] ), |
|
207 | - 'post_excerpt' => wp_kses_post( $item['description'] ), |
|
206 | + 'post_title' => sanitize_text_field($item['title']), |
|
207 | + 'post_excerpt' => wp_kses_post($item['description']), |
|
208 | 208 | 'post_status' => 'publish', |
209 | 209 | 'meta' => array( |
210 | 210 | 'type' => 'custom', |
211 | - 'price' => wpinv_sanitize_amount( $item['price'] ), |
|
211 | + 'price' => wpinv_sanitize_amount($item['price']), |
|
212 | 212 | 'vat_rule' => 'digital', |
213 | 213 | 'vat_class' => '_standard', |
214 | 214 | ) |
215 | 215 | ); |
216 | 216 | |
217 | - $new_item = new WPInv_Item(); |
|
218 | - $new_item->create( $data ); |
|
217 | + $new_item = new WPInv_Item(); |
|
218 | + $new_item->create($data); |
|
219 | 219 | |
220 | - if ( ! empty( $new_item ) ) { |
|
220 | + if (!empty($new_item)) { |
|
221 | 221 | $item['id'] = $new_item->ID; |
222 | 222 | $saved[] = $item; |
223 | 223 | } |
@@ -230,5 +230,5 @@ discard block |
||
230 | 230 | |
231 | 231 | } |
232 | 232 | |
233 | -add_action( 'save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2 ); |
|
233 | +add_action('save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2); |
|
234 | 234 |
@@ -1,29 +1,29 @@ 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 | - $statuses = wpinv_get_invoice_statuses( true ); |
|
10 | + $statuses = wpinv_get_invoice_statuses(true); |
|
11 | 11 | |
12 | - $post_id = !empty( $post->ID ) ? $post->ID : 0; |
|
13 | - $invoice = new WPInv_Invoice( $post_id ); |
|
14 | - $status = $invoice->get_status( false ); // Current status |
|
12 | + $post_id = !empty($post->ID) ? $post->ID : 0; |
|
13 | + $invoice = new WPInv_Invoice($post_id); |
|
14 | + $status = $invoice->get_status(false); // Current status |
|
15 | 15 | $discount = $invoice->get_discount(); |
16 | 16 | $discount_code = $discount > 0 ? $invoice->get_discount_code() : ''; |
17 | 17 | $invoice_number = $invoice->get_number(); |
18 | 18 | |
19 | 19 | $date_created = $invoice->get_created_date(); |
20 | - $datetime_created = strtotime( $date_created ); |
|
21 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : ''; |
|
20 | + $datetime_created = strtotime($date_created); |
|
21 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : ''; |
|
22 | 22 | $date_completed = $invoice->get_completed_date(); |
23 | - $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'; |
|
24 | - $title['status'] = __( 'Invoice Status:', 'invoicing' ); |
|
25 | - $title['number'] = __( 'Invoice Number:', 'invoicing' ); |
|
26 | - $mail_notice = esc_attr__( 'After saving invoice, this will send a copy of the invoice to the user’s email address.', 'invoicing' ); |
|
23 | + $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'; |
|
24 | + $title['status'] = __('Invoice Status:', 'invoicing'); |
|
25 | + $title['number'] = __('Invoice Number:', 'invoicing'); |
|
26 | + $mail_notice = esc_attr__('After saving invoice, this will send a copy of the invoice to the user’s email address.', 'invoicing'); |
|
27 | 27 | |
28 | 28 | $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice); |
29 | 29 | $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice); |
@@ -33,36 +33,36 @@ discard block |
||
33 | 33 | <div class="gdmbx2-wrap form-table"> |
34 | 34 | <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details"> |
35 | 35 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created"> |
36 | - <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div> |
|
37 | - <div class="gdmbx-td"><?php echo $date_created;?></div> |
|
36 | + <div class="gdmbx-th"><label><?php _e('Date Created:', 'invoicing'); ?></label></div> |
|
37 | + <div class="gdmbx-td"><?php echo $date_created; ?></div> |
|
38 | 38 | </div> |
39 | - <?php if ( $invoice->post_type == 'wpi_invoice' && wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft', 'draft' ) ) ) ) { ?> |
|
39 | + <?php if ($invoice->post_type == 'wpi_invoice' && wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft', 'draft')))) { ?> |
|
40 | 40 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue"> |
41 | - <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div> |
|
41 | + <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div> |
|
42 | 42 | <div class="gdmbx-td"> |
43 | - <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 | - <p class="wpi-meta-row wpi-meta-desc"><?php _e( 'Leave blank to disable sending auto reminder for this invoice.', 'invoicing' );?></p> |
|
43 | + <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 | + <p class="wpi-meta-row wpi-meta-desc"><?php _e('Leave blank to disable sending auto reminder for this invoice.', 'invoicing'); ?></p> |
|
45 | 45 | </div> |
46 | 46 | </div> |
47 | 47 | <?php } ?> |
48 | - <?php do_action( 'wpinv_meta_box_details_after_due_date', $post_id ); ?> |
|
49 | - <?php if ( $date_completed && $date_completed != 'n/a' ) { ?> |
|
48 | + <?php do_action('wpinv_meta_box_details_after_due_date', $post_id); ?> |
|
49 | + <?php if ($date_completed && $date_completed != 'n/a') { ?> |
|
50 | 50 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed"> |
51 | - <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div> |
|
52 | - <div class="gdmbx-td"><?php echo $date_completed;?></div> |
|
51 | + <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div> |
|
52 | + <div class="gdmbx-td"><?php echo $date_completed; ?></div> |
|
53 | 53 | </div> |
54 | 54 | <?php } ?> |
55 | - <?php $is_viewed = wpinv_is_invoice_viewed( $post_id ); ?> |
|
55 | + <?php $is_viewed = wpinv_is_invoice_viewed($post_id); ?> |
|
56 | 56 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-customer-viewed"> |
57 | - <div class="gdmbx-th"><label><?php _e( 'Viewed by Customer:', 'invoicing' );?></label></div> |
|
58 | - <div class="gdmbx-td"><?php ( 1 == $is_viewed ) ? _e( 'Yes', 'invoicing' ) : _e( 'No', 'invoicing' ); ?></div> |
|
57 | + <div class="gdmbx-th"><label><?php _e('Viewed by Customer:', 'invoicing'); ?></label></div> |
|
58 | + <div class="gdmbx-td"><?php (1 == $is_viewed) ? _e('Yes', 'invoicing') : _e('No', 'invoicing'); ?></div> |
|
59 | 59 | </div> |
60 | 60 | <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status"> |
61 | 61 | <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div> |
62 | 62 | <div class="gdmbx-td"> |
63 | 63 | <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select wpi_select2"> |
64 | - <?php foreach ( $statuses as $value => $label ) { ?> |
|
65 | - <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option> |
|
64 | + <?php foreach ($statuses as $value => $label) { ?> |
|
65 | + <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option> |
|
66 | 66 | <?php } ?> |
67 | 67 | </select> |
68 | 68 | </div> |
@@ -70,117 +70,117 @@ discard block |
||
70 | 70 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout"> |
71 | 71 | <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div> |
72 | 72 | <div class="gdmbx-td"> |
73 | - <input type="text" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly> |
|
73 | + <input type="text" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly> |
|
74 | 74 | </div> |
75 | 75 | </div> |
76 | - <?php do_action( 'wpinv_meta_box_details_inner', $post_id ); |
|
76 | + <?php do_action('wpinv_meta_box_details_inner', $post_id); |
|
77 | 77 | $disable_discount = apply_filters('wpinv_disable_apply_discount', false, $invoice, $post_id); |
78 | 78 | ?> |
79 | - <?php if ( !( $is_paid = ( $invoice->is_paid() || $invoice->is_refunded() ) ) && !$disable_discount || $discount_code ) { ?> |
|
79 | + <?php if (!($is_paid = ($invoice->is_paid() || $invoice->is_refunded())) && !$disable_discount || $discount_code) { ?> |
|
80 | 80 | <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout"> |
81 | - <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div> |
|
81 | + <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div> |
|
82 | 82 | <div class="gdmbx-td"> |
83 | - <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 && !$disable_discount ) { ?><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 } ?> |
|
83 | + <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 && !$disable_discount) { ?><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 } ?> |
|
84 | 84 | </div> |
85 | 85 | </div> |
86 | 86 | <?php } ?> |
87 | 87 | </div> |
88 | 88 | </div> |
89 | 89 | <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout"> |
90 | - <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> |
|
90 | + <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> |
|
91 | 91 | <select id="wpi_save_send" name="wpi_save_send" class="wpi_select2"> |
92 | - <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option> |
|
93 | - <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option> |
|
92 | + <option value="1"><?php _e('Yes', 'invoicing'); ?></option> |
|
93 | + <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option> |
|
94 | 94 | </select> |
95 | 95 | </p> |
96 | 96 | <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p> |
97 | 97 | </div> |
98 | -<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?> |
|
98 | +<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?> |
|
99 | 99 | <?php |
100 | 100 | } |
101 | 101 | |
102 | - public static function resend_invoice( $post ) { |
|
102 | + public static function resend_invoice($post) { |
|
103 | 103 | global $wpi_mb_invoice; |
104 | 104 | |
105 | - if ( empty( $wpi_mb_invoice ) ) { |
|
105 | + if (empty($wpi_mb_invoice)) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | 109 | $text = array( |
110 | - 'message' => esc_attr__( 'This will send a copy of the invoice to the customer’s email address.', 'invoicing' ), |
|
111 | - 'button_text' => __( 'Resend Invoice', 'invoicing' ), |
|
110 | + 'message' => esc_attr__('This will send a copy of the invoice to the customer’s email address.', 'invoicing'), |
|
111 | + 'button_text' => __('Resend Invoice', 'invoicing'), |
|
112 | 112 | ); |
113 | 113 | |
114 | 114 | $text = apply_filters('wpinv_resend_invoice_metabox_text', $text); |
115 | - do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice ); |
|
115 | + do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice); |
|
116 | 116 | |
117 | - if ( $email = $wpi_mb_invoice->get_email() ) { |
|
117 | + if ($email = $wpi_mb_invoice->get_email()) { |
|
118 | 118 | $email_actions = array(); |
119 | - $email_actions['email_url'] = remove_query_arg( 'wpinv-message', add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ); |
|
120 | - $email_actions['reminder_url'] = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) ); |
|
119 | + $email_actions['email_url'] = remove_query_arg('wpinv-message', add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))); |
|
120 | + $email_actions['reminder_url'] = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID)); |
|
121 | 121 | |
122 | - $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions ); |
|
122 | + $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions); |
|
123 | 123 | ?> |
124 | 124 | <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p> |
125 | - <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url( $email_actions['email_url'] ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
126 | - <?php if ( wpinv_get_option( 'overdue_active' ) && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?> |
|
127 | - <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( $email_actions['reminder_url'] ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p> |
|
125 | + <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url($email_actions['email_url']); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p> |
|
126 | + <?php if (wpinv_get_option('overdue_active') && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?> |
|
127 | + <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($email_actions['reminder_url']); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p> |
|
128 | 128 | <?php } ?> |
129 | 129 | <?php |
130 | 130 | } |
131 | 131 | |
132 | - do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice ); |
|
132 | + do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice); |
|
133 | 133 | } |
134 | 134 | |
135 | - public static function subscriptions( $post ) { |
|
136 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
135 | + public static function subscriptions($post) { |
|
136 | + $invoice = wpinv_get_invoice($post->ID); |
|
137 | 137 | |
138 | - if ( ! empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) { |
|
139 | - $subscription = wpinv_get_subscription( $invoice ); |
|
138 | + if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) { |
|
139 | + $subscription = wpinv_get_subscription($invoice); |
|
140 | 140 | |
141 | - if ( empty( $subscription ) ) { |
|
141 | + if (empty($subscription)) { |
|
142 | 142 | ?> |
143 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( 'New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing' ), '<a href="' . admin_url( 'admin.php?page=wpinv-subscriptions' ).'">', '</a>' ); ?></p> |
|
143 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing'), '<a href="' . admin_url('admin.php?page=wpinv-subscriptions') . '">', '</a>'); ?></p> |
|
144 | 144 | <?php |
145 | 145 | return; |
146 | 146 | } |
147 | - $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, $subscription->frequency ); |
|
148 | - $billing = wpinv_price(wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency; |
|
149 | - $initial = wpinv_price(wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ); |
|
147 | + $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency); |
|
148 | + $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)) . ' / ' . $frequency; |
|
149 | + $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)); |
|
150 | 150 | $payments = $subscription->get_child_payments(); |
151 | 151 | ?> |
152 | 152 | <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . $subscription->status; ?>"><?php _e('Recurring Payment', 'invoicing'); ?></p> |
153 | - <?php if ( ! empty( $subscription ) && ! empty( $subscription->id ) ) { ?> |
|
153 | + <?php if (!empty($subscription) && !empty($subscription->id)) { ?> |
|
154 | 154 | <p class="wpi-meta-row wpi-sub-id"> |
155 | - <label><?php _e( 'Subscription ID:', 'invoicing' ); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p> |
|
155 | + <label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p> |
|
156 | 156 | <?php } ?> |
157 | 157 | <p class="wpi-meta-row wpi-bill-cycle"> |
158 | - <label><?php _e( 'Billing Cycle:', 'invoicing'); ?> </label><?php printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); ?> |
|
158 | + <label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); ?> |
|
159 | 159 | </p> |
160 | 160 | <p class="wpi-meta-row wpi-billed-times"> |
161 | - <label><?php _e( 'Times Billed:', 'invoicing' ); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? 'Until Cancelled' : $subscription->bill_times ); ?> |
|
161 | + <label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? 'Until Cancelled' : $subscription->bill_times); ?> |
|
162 | 162 | </p> |
163 | 163 | <p class="wpi-meta-row wpi-start-date"> |
164 | - <label><?php _e( 'Start Date:', 'invoicing' ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?> |
|
164 | + <label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->created, current_time('timestamp'))); ?> |
|
165 | 165 | </p> |
166 | 166 | <p class="wpi-meta-row wpi-end-date"> |
167 | - <label><?php echo ( 'trialling' == $subscription->status ? __( 'Trialling Until:', 'invoicing' ) : __( 'Expiration Date:', 'invoicing' ) ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration, current_time( 'timestamp' ) ) ); ?> |
|
167 | + <label><?php echo ('trialling' == $subscription->status ? __('Trialling Until:', 'invoicing') : __('Expiration Date:', 'invoicing')); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->expiration, current_time('timestamp'))); ?> |
|
168 | 168 | </p> |
169 | - <?php if ( $subscription->status ) { ?> |
|
169 | + <?php if ($subscription->status) { ?> |
|
170 | 170 | <p class="wpi-meta-row wpi-sub-status"> |
171 | - <label><?php _e( 'Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?> |
|
171 | + <label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?> |
|
172 | 172 | </p> |
173 | 173 | <?php } ?> |
174 | - <?php if ( !empty( $payments ) ) { ?> |
|
175 | - <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p> |
|
174 | + <?php if (!empty($payments)) { ?> |
|
175 | + <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p> |
|
176 | 176 | <ul id="wpi-sub-payments"> |
177 | - <?php foreach ( $payments as $payment ) { |
|
177 | + <?php foreach ($payments as $payment) { |
|
178 | 178 | $invoice_id = $payment->ID; |
179 | 179 | ?> |
180 | 180 | <li> |
181 | - <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a> – |
|
182 | - <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?> – </span> |
|
183 | - <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span> |
|
181 | + <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a> – |
|
182 | + <span><?php echo wpinv_get_invoice_date($invoice_id); ?> – </span> |
|
183 | + <span><?php echo wpinv_payment_total($invoice_id, true); ?></span> |
|
184 | 184 | </li> |
185 | 185 | <?php } ?> |
186 | 186 | </ul> |
@@ -188,16 +188,16 @@ discard block |
||
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | - public static function renewals( $post ) { |
|
192 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
191 | + public static function renewals($post) { |
|
192 | + $invoice = wpinv_get_invoice($post->ID); |
|
193 | 193 | |
194 | - if ( wpinv_is_subscription_payment( $invoice ) ) { |
|
195 | - $parent_url = get_edit_post_link( $invoice->parent_invoice ); |
|
196 | - $parent_id = wpinv_get_invoice_number( $invoice->parent_invoice ); |
|
197 | - $subscription = wpinv_get_subscription( $invoice ); |
|
194 | + if (wpinv_is_subscription_payment($invoice)) { |
|
195 | + $parent_url = get_edit_post_link($invoice->parent_invoice); |
|
196 | + $parent_id = wpinv_get_invoice_number($invoice->parent_invoice); |
|
197 | + $subscription = wpinv_get_subscription($invoice); |
|
198 | 198 | ?> |
199 | - <?php if ( ! empty( $subscription ) ) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?> |
|
200 | - <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> |
|
199 | + <?php if (!empty($subscription)) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?> |
|
200 | + <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> |
|
201 | 201 | <?php |
202 | 202 | } |
203 | 203 | } |
@@ -205,47 +205,47 @@ discard block |
||
205 | 205 | /** |
206 | 206 | * Renders a metabox to edit a payment form. |
207 | 207 | */ |
208 | - public static function payment_form( $post ) { |
|
209 | - WPInv_Meta_Box_Form_Items::output_options( $post ); |
|
208 | + public static function payment_form($post) { |
|
209 | + WPInv_Meta_Box_Form_Items::output_options($post); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
213 | 213 | * Renders a metabox to select items. |
214 | 214 | */ |
215 | - public static function payment_form_items( $post ) { |
|
216 | - WPInv_Meta_Box_Form_Items::output( $post ); |
|
215 | + public static function payment_form_items($post) { |
|
216 | + WPInv_Meta_Box_Form_Items::output($post); |
|
217 | 217 | } |
218 | 218 | |
219 | - public static function payment_meta( $post ) { |
|
219 | + public static function payment_meta($post) { |
|
220 | 220 | global $wpi_mb_invoice; |
221 | 221 | |
222 | - $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false; |
|
223 | - if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded() ) { |
|
222 | + $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false; |
|
223 | + if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded()) { |
|
224 | 224 | $set_dateway = true; |
225 | 225 | } |
226 | 226 | |
227 | 227 | ?> |
228 | 228 | <p class="wpi-meta-row"> |
229 | - <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?> |
|
230 | - <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label> |
|
229 | + <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?> |
|
230 | + <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label> |
|
231 | 231 | <select required="required" id="wpinv_gateway" class="wpi_select2" name="wpinv_gateway"> |
232 | - <?php foreach ( $gateways as $name => $gateway ) { |
|
233 | - if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) { |
|
232 | + <?php foreach ($gateways as $name => $gateway) { |
|
233 | + if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) { |
|
234 | 234 | continue; |
235 | 235 | } |
236 | 236 | ?> |
237 | - <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> |
|
237 | + <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> |
|
238 | 238 | <?php } ?> |
239 | 239 | </select> |
240 | 240 | <?php } else { |
241 | - echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_admin_label( $wpi_mb_invoice->gateway ) ); |
|
241 | + echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_admin_label($wpi_mb_invoice->gateway)); |
|
242 | 242 | } ?> |
243 | 243 | </p> |
244 | - <?php if ( $key = $wpi_mb_invoice->get_key() ) { ?> |
|
245 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $key ); ?></p> |
|
244 | + <?php if ($key = $wpi_mb_invoice->get_key()) { ?> |
|
245 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $key); ?></p> |
|
246 | 246 | <?php } ?> |
247 | - <?php if ( $wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded() ) { ?> |
|
248 | - <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p> |
|
247 | + <?php if ($wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded()) { ?> |
|
248 | + <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p> |
|
249 | 249 | <?php } ?> |
250 | 250 | <?php |
251 | 251 | } |
@@ -7,28 +7,28 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Ajax { |
15 | 15 | public static function init() { |
16 | - add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 ); |
|
17 | - add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 ); |
|
16 | + add_action('init', array(__CLASS__, 'define_ajax'), 0); |
|
17 | + add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0); |
|
18 | 18 | self::add_ajax_events(); |
19 | 19 | } |
20 | 20 | |
21 | 21 | public static function define_ajax() { |
22 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
23 | - if ( ! defined( 'DOING_AJAX' ) ) { |
|
24 | - define( 'DOING_AJAX', true ); |
|
22 | + if (!empty($_GET['wpinv-ajax'])) { |
|
23 | + if (!defined('DOING_AJAX')) { |
|
24 | + define('DOING_AJAX', true); |
|
25 | 25 | } |
26 | - if ( ! defined( 'WC_DOING_AJAX' ) ) { |
|
27 | - define( 'WC_DOING_AJAX', true ); |
|
26 | + if (!defined('WC_DOING_AJAX')) { |
|
27 | + define('WC_DOING_AJAX', true); |
|
28 | 28 | } |
29 | 29 | // Turn off display_errors during AJAX events to prevent malformed JSON |
30 | - if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) { |
|
31 | - /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 ); |
|
30 | + if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) { |
|
31 | + /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0); |
|
32 | 32 | } |
33 | 33 | $GLOBALS['wpdb']->hide_errors(); |
34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | public static function do_wpinv_ajax() { |
38 | 38 | global $wp_query; |
39 | 39 | |
40 | - if ( !empty( $_GET['wpinv-ajax'] ) ) { |
|
41 | - $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) ); |
|
40 | + if (!empty($_GET['wpinv-ajax'])) { |
|
41 | + $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax'])); |
|
42 | 42 | } |
43 | 43 | |
44 | - if ( $action = $wp_query->get( 'wpinv-ajax' ) ) { |
|
44 | + if ($action = $wp_query->get('wpinv-ajax')) { |
|
45 | 45 | self::wpinv_ajax_headers(); |
46 | - do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) ); |
|
46 | + do_action('wpinv_ajax_' . sanitize_text_field($action)); |
|
47 | 47 | die(); |
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | 51 | private static function wpinv_ajax_headers() { |
52 | 52 | send_origin_headers(); |
53 | - /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) ); |
|
54 | - /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' ); |
|
53 | + /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset')); |
|
54 | + /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex'); |
|
55 | 55 | send_nosniff_header(); |
56 | 56 | nocache_headers(); |
57 | - status_header( 200 ); |
|
57 | + status_header(200); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | public static function add_ajax_events() { |
@@ -78,39 +78,39 @@ discard block |
||
78 | 78 | 'buy_items' => true, |
79 | 79 | ); |
80 | 80 | |
81 | - foreach ( $ajax_events as $ajax_event => $nopriv ) { |
|
82 | - add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
81 | + foreach ($ajax_events as $ajax_event => $nopriv) { |
|
82 | + add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
83 | 83 | |
84 | - if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) { |
|
85 | - define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 ); |
|
84 | + if (!defined('WPI_AJAX_' . strtoupper($nopriv))) { |
|
85 | + define('WPI_AJAX_' . strtoupper($nopriv), 1); |
|
86 | 86 | } |
87 | 87 | |
88 | - if ( $nopriv ) { |
|
89 | - add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
88 | + if ($nopriv) { |
|
89 | + add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
90 | 90 | |
91 | - add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) ); |
|
91 | + add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event)); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | } |
95 | 95 | |
96 | 96 | public static function add_note() { |
97 | - check_ajax_referer( 'add-invoice-note', '_nonce' ); |
|
97 | + check_ajax_referer('add-invoice-note', '_nonce'); |
|
98 | 98 | |
99 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
99 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
100 | 100 | die(-1); |
101 | 101 | } |
102 | 102 | |
103 | - $post_id = absint( $_POST['post_id'] ); |
|
104 | - $note = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) ); |
|
105 | - $note_type = sanitize_text_field( $_POST['note_type'] ); |
|
103 | + $post_id = absint($_POST['post_id']); |
|
104 | + $note = wp_kses_post(trim(stripslashes($_POST['note']))); |
|
105 | + $note_type = sanitize_text_field($_POST['note_type']); |
|
106 | 106 | |
107 | 107 | $is_customer_note = $note_type == 'customer' ? 1 : 0; |
108 | 108 | |
109 | - if ( $post_id > 0 ) { |
|
110 | - $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note ); |
|
109 | + if ($post_id > 0) { |
|
110 | + $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note); |
|
111 | 111 | |
112 | - if ( $note_id > 0 && !is_wp_error( $note_id ) ) { |
|
113 | - wpinv_get_invoice_note_line_item( $note_id ); |
|
112 | + if ($note_id > 0 && !is_wp_error($note_id)) { |
|
113 | + wpinv_get_invoice_note_line_item($note_id); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
@@ -118,16 +118,16 @@ discard block |
||
118 | 118 | } |
119 | 119 | |
120 | 120 | public static function delete_note() { |
121 | - check_ajax_referer( 'delete-invoice-note', '_nonce' ); |
|
121 | + check_ajax_referer('delete-invoice-note', '_nonce'); |
|
122 | 122 | |
123 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
123 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
124 | 124 | die(-1); |
125 | 125 | } |
126 | 126 | |
127 | - $note_id = (int)$_POST['note_id']; |
|
127 | + $note_id = (int) $_POST['note_id']; |
|
128 | 128 | |
129 | - if ( $note_id > 0 ) { |
|
130 | - wp_delete_comment( $note_id, true ); |
|
129 | + if ($note_id > 0) { |
|
130 | + wp_delete_comment($note_id, true); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | die(); |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | } |
141 | 141 | |
142 | 142 | public static function checkout() { |
143 | - if ( ! defined( 'WPINV_CHECKOUT' ) ) { |
|
144 | - define( 'WPINV_CHECKOUT', true ); |
|
143 | + if (!defined('WPINV_CHECKOUT')) { |
|
144 | + define('WPINV_CHECKOUT', true); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | wpinv_process_checkout(); |
@@ -150,53 +150,53 @@ discard block |
||
150 | 150 | |
151 | 151 | public static function add_invoice_item() { |
152 | 152 | global $wpi_userID, $wpinv_ip_address_country; |
153 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
154 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
153 | + check_ajax_referer('invoice-item', '_nonce'); |
|
154 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
155 | 155 | die(-1); |
156 | 156 | } |
157 | 157 | |
158 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
159 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
158 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
159 | + $invoice_id = absint($_POST['invoice_id']); |
|
160 | 160 | |
161 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
161 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
162 | 162 | die(); |
163 | 163 | } |
164 | 164 | |
165 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
166 | - if ( empty( $invoice ) ) { |
|
165 | + $invoice = wpinv_get_invoice($invoice_id); |
|
166 | + if (empty($invoice)) { |
|
167 | 167 | die(); |
168 | 168 | } |
169 | 169 | |
170 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
170 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
171 | 171 | die(); // Don't allow modify items for paid invoice. |
172 | 172 | } |
173 | 173 | |
174 | - if ( !empty( $_POST['user_id'] ) ) { |
|
175 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
174 | + if (!empty($_POST['user_id'])) { |
|
175 | + $wpi_userID = absint($_POST['user_id']); |
|
176 | 176 | } |
177 | 177 | |
178 | - $item = new WPInv_Item( $item_id ); |
|
179 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
178 | + $item = new WPInv_Item($item_id); |
|
179 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
180 | 180 | die(); |
181 | 181 | } |
182 | 182 | |
183 | 183 | // Validate item before adding to invoice because recurring item must be paid individually. |
184 | - if ( !empty( $invoice->cart_details ) ) { |
|
184 | + if (!empty($invoice->cart_details)) { |
|
185 | 185 | $valid = true; |
186 | 186 | |
187 | - if ( $recurring_item = $invoice->get_recurring() ) { |
|
188 | - if ( $recurring_item != $item_id ) { |
|
187 | + if ($recurring_item = $invoice->get_recurring()) { |
|
188 | + if ($recurring_item != $item_id) { |
|
189 | 189 | $valid = false; |
190 | 190 | } |
191 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
191 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
192 | 192 | $valid = false; |
193 | 193 | } |
194 | 194 | |
195 | - if ( !$valid ) { |
|
195 | + if (!$valid) { |
|
196 | 196 | $response = array(); |
197 | 197 | $response['success'] = false; |
198 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
199 | - wp_send_json( $response ); |
|
198 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
199 | + wp_send_json($response); |
|
200 | 200 | } |
201 | 201 | } |
202 | 202 | |
@@ -204,11 +204,11 @@ discard block |
||
204 | 204 | |
205 | 205 | $data = array(); |
206 | 206 | $data['invoice_id'] = $invoice_id; |
207 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
207 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
208 | 208 | |
209 | - wpinv_set_checkout_session( $data ); |
|
209 | + wpinv_set_checkout_session($data); |
|
210 | 210 | |
211 | - $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1; |
|
211 | + $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1; |
|
212 | 212 | |
213 | 213 | $args = array( |
214 | 214 | 'id' => $item_id, |
@@ -221,21 +221,21 @@ discard block |
||
221 | 221 | 'fees' => array() |
222 | 222 | ); |
223 | 223 | |
224 | - $invoice->add_item( $item_id, $args ); |
|
224 | + $invoice->add_item($item_id, $args); |
|
225 | 225 | $invoice->save(); |
226 | 226 | |
227 | - if ( empty( $_POST['country'] ) ) { |
|
227 | + if (empty($_POST['country'])) { |
|
228 | 228 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
229 | 229 | } |
230 | - if ( empty( $_POST['state'] ) ) { |
|
230 | + if (empty($_POST['state'])) { |
|
231 | 231 | $_POST['state'] = $invoice->state; |
232 | 232 | } |
233 | 233 | |
234 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
235 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
234 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
235 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
236 | 236 | |
237 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
238 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
237 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
238 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
239 | 239 | |
240 | 240 | $wpinv_ip_address_country = $invoice->country; |
241 | 241 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | |
244 | 244 | $response = array(); |
245 | 245 | $response['success'] = true; |
246 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
246 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
247 | 247 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
248 | 248 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
249 | 249 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -255,41 +255,41 @@ discard block |
||
255 | 255 | |
256 | 256 | wpinv_set_checkout_session($checkout_session); |
257 | 257 | |
258 | - wp_send_json( $response ); |
|
258 | + wp_send_json($response); |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | |
262 | 262 | public static function remove_invoice_item() { |
263 | 263 | global $wpi_userID, $wpinv_ip_address_country; |
264 | 264 | |
265 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
266 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
265 | + check_ajax_referer('invoice-item', '_nonce'); |
|
266 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
267 | 267 | die(-1); |
268 | 268 | } |
269 | 269 | |
270 | - $item_id = sanitize_text_field( $_POST['item_id'] ); |
|
271 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
272 | - $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
270 | + $item_id = sanitize_text_field($_POST['item_id']); |
|
271 | + $invoice_id = absint($_POST['invoice_id']); |
|
272 | + $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false; |
|
273 | 273 | |
274 | - if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) { |
|
274 | + if (!is_numeric($invoice_id) || !is_numeric($item_id)) { |
|
275 | 275 | die(); |
276 | 276 | } |
277 | 277 | |
278 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
279 | - if ( empty( $invoice ) ) { |
|
278 | + $invoice = wpinv_get_invoice($invoice_id); |
|
279 | + if (empty($invoice)) { |
|
280 | 280 | die(); |
281 | 281 | } |
282 | 282 | |
283 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
283 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
284 | 284 | die(); // Don't allow modify items for paid invoice. |
285 | 285 | } |
286 | 286 | |
287 | - if ( !empty( $_POST['user_id'] ) ) { |
|
288 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
287 | + if (!empty($_POST['user_id'])) { |
|
288 | + $wpi_userID = absint($_POST['user_id']); |
|
289 | 289 | } |
290 | 290 | |
291 | - $item = new WPInv_Item( $item_id ); |
|
292 | - if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) { |
|
291 | + $item = new WPInv_Item($item_id); |
|
292 | + if (!(!empty($item) && $item->post_type == 'wpi_item')) { |
|
293 | 293 | die(); |
294 | 294 | } |
295 | 295 | |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | |
298 | 298 | $data = array(); |
299 | 299 | $data['invoice_id'] = $invoice_id; |
300 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
300 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
301 | 301 | |
302 | - wpinv_set_checkout_session( $data ); |
|
302 | + wpinv_set_checkout_session($data); |
|
303 | 303 | |
304 | 304 | $args = array( |
305 | 305 | 'id' => $item_id, |
@@ -307,21 +307,21 @@ discard block |
||
307 | 307 | 'cart_index' => $cart_index |
308 | 308 | ); |
309 | 309 | |
310 | - $invoice->remove_item( $item_id, $args ); |
|
310 | + $invoice->remove_item($item_id, $args); |
|
311 | 311 | $invoice->save(); |
312 | 312 | |
313 | - if ( empty( $_POST['country'] ) ) { |
|
313 | + if (empty($_POST['country'])) { |
|
314 | 314 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
315 | 315 | } |
316 | - if ( empty( $_POST['state'] ) ) { |
|
316 | + if (empty($_POST['state'])) { |
|
317 | 317 | $_POST['state'] = $invoice->state; |
318 | 318 | } |
319 | 319 | |
320 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
321 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
320 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
321 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
322 | 322 | |
323 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
324 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
323 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
324 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
325 | 325 | |
326 | 326 | $wpinv_ip_address_country = $invoice->country; |
327 | 327 | |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | |
330 | 330 | $response = array(); |
331 | 331 | $response['success'] = true; |
332 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
332 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
333 | 333 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
334 | 334 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
335 | 335 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -341,55 +341,55 @@ discard block |
||
341 | 341 | |
342 | 342 | wpinv_set_checkout_session($checkout_session); |
343 | 343 | |
344 | - wp_send_json( $response ); |
|
344 | + wp_send_json($response); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | public static function create_invoice_item() { |
348 | - check_ajax_referer( 'invoice-item', '_nonce' ); |
|
349 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
348 | + check_ajax_referer('invoice-item', '_nonce'); |
|
349 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
350 | 350 | die(-1); |
351 | 351 | } |
352 | 352 | |
353 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
353 | + $invoice_id = absint($_POST['invoice_id']); |
|
354 | 354 | |
355 | 355 | // Find the item |
356 | - if ( !is_numeric( $invoice_id ) ) { |
|
356 | + if (!is_numeric($invoice_id)) { |
|
357 | 357 | die(); |
358 | 358 | } |
359 | 359 | |
360 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
361 | - if ( empty( $invoice ) ) { |
|
360 | + $invoice = wpinv_get_invoice($invoice_id); |
|
361 | + if (empty($invoice)) { |
|
362 | 362 | die(); |
363 | 363 | } |
364 | 364 | |
365 | 365 | // Validate item before adding to invoice because recurring item must be paid individually. |
366 | - if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) { |
|
366 | + if (!empty($invoice->cart_details) && $invoice->get_recurring()) { |
|
367 | 367 | $response = array(); |
368 | 368 | $response['success'] = false; |
369 | - $response['msg'] = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ); |
|
370 | - wp_send_json( $response ); |
|
369 | + $response['msg'] = __('You can not add item because recurring item must be paid individually!', 'invoicing'); |
|
370 | + wp_send_json($response); |
|
371 | 371 | } |
372 | 372 | |
373 | - $save_item = wp_unslash( $_POST['_wpinv_quick'] ); |
|
373 | + $save_item = wp_unslash($_POST['_wpinv_quick']); |
|
374 | 374 | |
375 | 375 | $meta = array(); |
376 | 376 | $meta['type'] = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom'; |
377 | - $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0; |
|
377 | + $meta['price'] = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0; |
|
378 | 378 | $meta['vat_rule'] = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital'; |
379 | 379 | $meta['vat_class'] = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard'; |
380 | 380 | |
381 | 381 | $data = array(); |
382 | 382 | $data['post_title'] = sanitize_text_field($save_item['name']); |
383 | 383 | $data['post_status'] = 'publish'; |
384 | - $data['post_excerpt'] = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : ''; |
|
384 | + $data['post_excerpt'] = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : ''; |
|
385 | 385 | $data['meta'] = $meta; |
386 | 386 | |
387 | 387 | $item = new WPInv_Item(); |
388 | - $item->create( $data ); |
|
388 | + $item->create($data); |
|
389 | 389 | |
390 | - if ( !empty( $item ) ) { |
|
390 | + if (!empty($item)) { |
|
391 | 391 | $_POST['item_id'] = $item->ID; |
392 | - $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1; |
|
392 | + $_POST['qty'] = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1; |
|
393 | 393 | |
394 | 394 | self::add_invoice_item(); |
395 | 395 | } |
@@ -397,15 +397,15 @@ discard block |
||
397 | 397 | } |
398 | 398 | |
399 | 399 | public static function get_billing_details() { |
400 | - check_ajax_referer( 'get-billing-details', '_nonce' ); |
|
400 | + check_ajax_referer('get-billing-details', '_nonce'); |
|
401 | 401 | |
402 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
402 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
403 | 403 | die(-1); |
404 | 404 | } |
405 | 405 | |
406 | - $user_id = (int)$_POST['user_id']; |
|
406 | + $user_id = (int) $_POST['user_id']; |
|
407 | 407 | $billing_details = wpinv_get_user_address($user_id); |
408 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
408 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
409 | 409 | |
410 | 410 | if (isset($billing_details['user_id'])) { |
411 | 411 | unset($billing_details['user_id']); |
@@ -419,20 +419,20 @@ discard block |
||
419 | 419 | $response['success'] = true; |
420 | 420 | $response['data']['billing_details'] = $billing_details; |
421 | 421 | |
422 | - wp_send_json( $response ); |
|
422 | + wp_send_json($response); |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | public static function admin_recalculate_totals() { |
426 | 426 | global $wpi_userID, $wpinv_ip_address_country; |
427 | 427 | |
428 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
429 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
428 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
429 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
430 | 430 | die(-1); |
431 | 431 | } |
432 | 432 | |
433 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
434 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
435 | - if ( empty( $invoice ) ) { |
|
433 | + $invoice_id = absint($_POST['invoice_id']); |
|
434 | + $invoice = wpinv_get_invoice($invoice_id); |
|
435 | + if (empty($invoice)) { |
|
436 | 436 | die(); |
437 | 437 | } |
438 | 438 | |
@@ -440,23 +440,23 @@ discard block |
||
440 | 440 | |
441 | 441 | $data = array(); |
442 | 442 | $data['invoice_id'] = $invoice_id; |
443 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
443 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
444 | 444 | |
445 | - wpinv_set_checkout_session( $data ); |
|
445 | + wpinv_set_checkout_session($data); |
|
446 | 446 | |
447 | - if ( !empty( $_POST['user_id'] ) ) { |
|
448 | - $wpi_userID = absint( $_POST['user_id'] ); |
|
447 | + if (!empty($_POST['user_id'])) { |
|
448 | + $wpi_userID = absint($_POST['user_id']); |
|
449 | 449 | } |
450 | 450 | |
451 | - if ( empty( $_POST['country'] ) ) { |
|
451 | + if (empty($_POST['country'])) { |
|
452 | 452 | $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
453 | 453 | } |
454 | 454 | |
455 | - $invoice->country = sanitize_text_field( $_POST['country'] ); |
|
456 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
457 | - if ( isset( $_POST['state'] ) ) { |
|
458 | - $invoice->state = sanitize_text_field( $_POST['state'] ); |
|
459 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
455 | + $invoice->country = sanitize_text_field($_POST['country']); |
|
456 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
457 | + if (isset($_POST['state'])) { |
|
458 | + $invoice->state = sanitize_text_field($_POST['state']); |
|
459 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | $wpinv_ip_address_country = $invoice->country; |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | |
466 | 466 | $response = array(); |
467 | 467 | $response['success'] = true; |
468 | - $response['data']['items'] = wpinv_admin_get_line_items( $invoice ); |
|
468 | + $response['data']['items'] = wpinv_admin_get_line_items($invoice); |
|
469 | 469 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
470 | 470 | $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
471 | 471 | $response['data']['tax'] = $invoice->get_tax(); |
@@ -477,25 +477,25 @@ discard block |
||
477 | 477 | |
478 | 478 | wpinv_set_checkout_session($checkout_session); |
479 | 479 | |
480 | - wp_send_json( $response ); |
|
480 | + wp_send_json($response); |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | public static function admin_apply_discount() { |
484 | 484 | global $wpi_userID; |
485 | 485 | |
486 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
487 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
486 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
487 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
488 | 488 | die(-1); |
489 | 489 | } |
490 | 490 | |
491 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
492 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
493 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
491 | + $invoice_id = absint($_POST['invoice_id']); |
|
492 | + $discount_code = sanitize_text_field($_POST['code']); |
|
493 | + if (empty($invoice_id) || empty($discount_code)) { |
|
494 | 494 | die(); |
495 | 495 | } |
496 | 496 | |
497 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
498 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
497 | + $invoice = wpinv_get_invoice($invoice_id); |
|
498 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
499 | 499 | die(); |
500 | 500 | } |
501 | 501 | |
@@ -503,49 +503,49 @@ discard block |
||
503 | 503 | |
504 | 504 | $data = array(); |
505 | 505 | $data['invoice_id'] = $invoice_id; |
506 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
506 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
507 | 507 | |
508 | - wpinv_set_checkout_session( $data ); |
|
508 | + wpinv_set_checkout_session($data); |
|
509 | 509 | |
510 | 510 | $response = array(); |
511 | 511 | $response['success'] = false; |
512 | - $response['msg'] = __( 'This discount is invalid.', 'invoicing' ); |
|
512 | + $response['msg'] = __('This discount is invalid.', 'invoicing'); |
|
513 | 513 | $response['data']['code'] = $discount_code; |
514 | 514 | |
515 | - if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) { |
|
516 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
515 | + if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) { |
|
516 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
517 | 517 | |
518 | 518 | $response['success'] = true; |
519 | - $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' ); |
|
520 | - } else { |
|
519 | + $response['msg'] = __('Discount has been applied successfully.', 'invoicing'); |
|
520 | + } else { |
|
521 | 521 | $errors = wpinv_get_errors(); |
522 | - if ( !empty( $errors['wpinv-discount-error'] ) ) { |
|
522 | + if (!empty($errors['wpinv-discount-error'])) { |
|
523 | 523 | $response['msg'] = $errors['wpinv-discount-error']; |
524 | 524 | } |
525 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
525 | + wpinv_unset_error('wpinv-discount-error'); |
|
526 | 526 | } |
527 | 527 | |
528 | 528 | wpinv_set_checkout_session($checkout_session); |
529 | 529 | |
530 | - wp_send_json( $response ); |
|
530 | + wp_send_json($response); |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | public static function admin_remove_discount() { |
534 | 534 | global $wpi_userID; |
535 | 535 | |
536 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
537 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
536 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
537 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
538 | 538 | die(-1); |
539 | 539 | } |
540 | 540 | |
541 | - $invoice_id = absint( $_POST['invoice_id'] ); |
|
542 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
543 | - if ( empty( $invoice_id ) || empty( $discount_code ) ) { |
|
541 | + $invoice_id = absint($_POST['invoice_id']); |
|
542 | + $discount_code = sanitize_text_field($_POST['code']); |
|
543 | + if (empty($invoice_id) || empty($discount_code)) { |
|
544 | 544 | die(); |
545 | 545 | } |
546 | 546 | |
547 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
548 | - if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) { |
|
547 | + $invoice = wpinv_get_invoice($invoice_id); |
|
548 | + if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) { |
|
549 | 549 | die(); |
550 | 550 | } |
551 | 551 | |
@@ -553,38 +553,38 @@ discard block |
||
553 | 553 | |
554 | 554 | $data = array(); |
555 | 555 | $data['invoice_id'] = $invoice_id; |
556 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
556 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
557 | 557 | |
558 | - wpinv_set_checkout_session( $data ); |
|
558 | + wpinv_set_checkout_session($data); |
|
559 | 559 | |
560 | 560 | $response = array(); |
561 | 561 | $response['success'] = false; |
562 | 562 | $response['msg'] = NULL; |
563 | 563 | |
564 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
564 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
565 | 565 | $response['success'] = true; |
566 | - $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' ); |
|
566 | + $response['msg'] = __('Discount has been removed successfully.', 'invoicing'); |
|
567 | 567 | |
568 | 568 | wpinv_set_checkout_session($checkout_session); |
569 | 569 | |
570 | - wp_send_json( $response ); |
|
570 | + wp_send_json($response); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | public static function check_email() { |
574 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
575 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
574 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
575 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
576 | 576 | die(-1); |
577 | 577 | } |
578 | 578 | |
579 | - $email = sanitize_text_field( $_POST['email'] ); |
|
579 | + $email = sanitize_text_field($_POST['email']); |
|
580 | 580 | |
581 | 581 | $response = array(); |
582 | - if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) { |
|
582 | + if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) { |
|
583 | 583 | $user_id = $user_data->ID; |
584 | 584 | $user_login = $user_data->user_login; |
585 | 585 | $display_name = $user_data->display_name ? $user_data->display_name : $user_login; |
586 | 586 | $billing_details = wpinv_get_user_address($user_id); |
587 | - $billing_details = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id ); |
|
587 | + $billing_details = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id); |
|
588 | 588 | |
589 | 589 | if (isset($billing_details['user_id'])) { |
590 | 590 | unset($billing_details['user_id']); |
@@ -600,54 +600,54 @@ discard block |
||
600 | 600 | $response['data']['billing_details'] = $billing_details; |
601 | 601 | } |
602 | 602 | |
603 | - wp_send_json( $response ); |
|
603 | + wp_send_json($response); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | public static function run_tool() { |
607 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
608 | - if ( !wpinv_current_user_can_manage_invoicing() ) { |
|
607 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
608 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
609 | 609 | die(-1); |
610 | 610 | } |
611 | 611 | |
612 | - $tool = sanitize_text_field( $_POST['tool'] ); |
|
612 | + $tool = sanitize_text_field($_POST['tool']); |
|
613 | 613 | |
614 | - do_action( 'wpinv_run_tool' ); |
|
614 | + do_action('wpinv_run_tool'); |
|
615 | 615 | |
616 | - if ( !empty( $tool ) ) { |
|
617 | - do_action( 'wpinv_tool_' . $tool ); |
|
616 | + if (!empty($tool)) { |
|
617 | + do_action('wpinv_tool_' . $tool); |
|
618 | 618 | } |
619 | 619 | } |
620 | 620 | |
621 | 621 | public static function apply_discount() { |
622 | 622 | global $wpi_userID; |
623 | 623 | |
624 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
624 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
625 | 625 | |
626 | 626 | $response = array(); |
627 | 627 | |
628 | - if ( isset( $_POST['code'] ) ) { |
|
629 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
628 | + if (isset($_POST['code'])) { |
|
629 | + $discount_code = sanitize_text_field($_POST['code']); |
|
630 | 630 | |
631 | 631 | $response['success'] = false; |
632 | 632 | $response['msg'] = ''; |
633 | 633 | $response['data']['code'] = $discount_code; |
634 | 634 | |
635 | 635 | $invoice = wpinv_get_invoice_cart(); |
636 | - if ( empty( $invoice->ID ) ) { |
|
637 | - $response['msg'] = __( 'Invalid checkout request.', 'invoicing' ); |
|
638 | - wp_send_json( $response ); |
|
636 | + if (empty($invoice->ID)) { |
|
637 | + $response['msg'] = __('Invalid checkout request.', 'invoicing'); |
|
638 | + wp_send_json($response); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | $wpi_userID = $invoice->get_user_id(); |
642 | 642 | |
643 | - if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) { |
|
644 | - $discount = wpinv_get_discount_by_code( $discount_code ); |
|
645 | - $discounts = wpinv_set_cart_discount( $discount_code ); |
|
646 | - $amount = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) ); |
|
647 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
648 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
643 | + if (wpinv_is_discount_valid($discount_code, $wpi_userID)) { |
|
644 | + $discount = wpinv_get_discount_by_code($discount_code); |
|
645 | + $discounts = wpinv_set_cart_discount($discount_code); |
|
646 | + $amount = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID)); |
|
647 | + $total = wpinv_get_cart_total(null, $discounts); |
|
648 | + $cart_totals = wpinv_recalculate_tax(true); |
|
649 | 649 | |
650 | - if ( !empty( $cart_totals ) ) { |
|
650 | + if (!empty($cart_totals)) { |
|
651 | 651 | $response['success'] = true; |
652 | 652 | $response['data'] = $cart_totals; |
653 | 653 | $response['data']['code'] = $discount_code; |
@@ -656,29 +656,29 @@ discard block |
||
656 | 656 | } |
657 | 657 | } else { |
658 | 658 | $errors = wpinv_get_errors(); |
659 | - $response['msg'] = $errors['wpinv-discount-error']; |
|
660 | - wpinv_unset_error( 'wpinv-discount-error' ); |
|
659 | + $response['msg'] = $errors['wpinv-discount-error']; |
|
660 | + wpinv_unset_error('wpinv-discount-error'); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | // Allow for custom discount code handling |
664 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
664 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
665 | 665 | } |
666 | 666 | |
667 | - wp_send_json( $response ); |
|
667 | + wp_send_json($response); |
|
668 | 668 | } |
669 | 669 | |
670 | 670 | public static function remove_discount() { |
671 | - check_ajax_referer( 'wpinv-nonce', '_nonce' ); |
|
671 | + check_ajax_referer('wpinv-nonce', '_nonce'); |
|
672 | 672 | |
673 | 673 | $response = array(); |
674 | 674 | |
675 | - if ( isset( $_POST['code'] ) ) { |
|
676 | - $discount_code = sanitize_text_field( $_POST['code'] ); |
|
677 | - $discounts = wpinv_unset_cart_discount( $discount_code ); |
|
678 | - $total = wpinv_get_cart_total( null, $discounts ); |
|
679 | - $cart_totals = wpinv_recalculate_tax( true ); |
|
675 | + if (isset($_POST['code'])) { |
|
676 | + $discount_code = sanitize_text_field($_POST['code']); |
|
677 | + $discounts = wpinv_unset_cart_discount($discount_code); |
|
678 | + $total = wpinv_get_cart_total(null, $discounts); |
|
679 | + $cart_totals = wpinv_recalculate_tax(true); |
|
680 | 680 | |
681 | - if ( !empty( $cart_totals ) ) { |
|
681 | + if (!empty($cart_totals)) { |
|
682 | 682 | $response['success'] = true; |
683 | 683 | $response['data'] = $cart_totals; |
684 | 684 | $response['data']['code'] = $discount_code; |
@@ -687,10 +687,10 @@ discard block |
||
687 | 687 | } |
688 | 688 | |
689 | 689 | // Allow for custom discount code handling |
690 | - $response = apply_filters( 'wpinv_ajax_discount_response', $response ); |
|
690 | + $response = apply_filters('wpinv_ajax_discount_response', $response); |
|
691 | 691 | } |
692 | 692 | |
693 | - wp_send_json( $response ); |
|
693 | + wp_send_json($response); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |
@@ -702,50 +702,50 @@ discard block |
||
702 | 702 | global $invoicing; |
703 | 703 | |
704 | 704 | // Check nonce. |
705 | - if ( ! isset( $_POST['wpinv_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_payment_form'], 'wpinv_payment_form' ) ) { |
|
706 | - wp_send_json_error( __( 'Security checks failed.', 'invoicing' ) ); |
|
705 | + if (!isset($_POST['wpinv_payment_form']) || !wp_verify_nonce($_POST['wpinv_payment_form'], 'wpinv_payment_form')) { |
|
706 | + wp_send_json_error(__('Security checks failed.', 'invoicing')); |
|
707 | 707 | } |
708 | 708 | |
709 | 709 | // Prepare submitted data... |
710 | - $data = wp_unslash( $_POST ); |
|
710 | + $data = wp_unslash($_POST); |
|
711 | 711 | |
712 | 712 | // ... form fields... |
713 | - if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) { |
|
714 | - wp_send_json_error( __( 'This payment form is no longer active.', 'invoicing' ) ); |
|
713 | + if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) { |
|
714 | + wp_send_json_error(__('This payment form is no longer active.', 'invoicing')); |
|
715 | 715 | } |
716 | 716 | |
717 | - if ( empty( $data['billing_email'] ) || ! is_email( $data['billing_email'] ) ) { |
|
718 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
717 | + if (empty($data['billing_email']) || !is_email($data['billing_email'])) { |
|
718 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | $prepared = array( |
722 | - 'billing_email' => sanitize_email( $data['billing_email'] ), |
|
723 | - __( 'Billing Email', 'invoicing' ) => sanitize_email( $data['billing_email'] ), |
|
724 | - __( 'Form Id', 'invoicing' ) => absint( $data['form_id'] ), |
|
722 | + 'billing_email' => sanitize_email($data['billing_email']), |
|
723 | + __('Billing Email', 'invoicing') => sanitize_email($data['billing_email']), |
|
724 | + __('Form Id', 'invoicing') => absint($data['form_id']), |
|
725 | 725 | ); |
726 | 726 | |
727 | - $prepared['billing_email'] = sanitize_email( $data['billing_email'] ); |
|
727 | + $prepared['billing_email'] = sanitize_email($data['billing_email']); |
|
728 | 728 | |
729 | - $fields = $invoicing->form_elements->get_form_elements( $data['form_id'] ); |
|
729 | + $fields = $invoicing->form_elements->get_form_elements($data['form_id']); |
|
730 | 730 | |
731 | 731 | // ... and form items. |
732 | - $items = $invoicing->form_elements->get_form_items( $data['form_id'] ); |
|
732 | + $items = $invoicing->form_elements->get_form_items($data['form_id']); |
|
733 | 733 | $prepared_items = array(); |
734 | 734 | |
735 | - if ( ! empty( $data['payment-form-items'] ) ) { |
|
735 | + if (!empty($data['payment-form-items'])) { |
|
736 | 736 | |
737 | - $selected_items = wpinv_parse_list( $data['payment-form-items'] ); |
|
737 | + $selected_items = wpinv_parse_list($data['payment-form-items']); |
|
738 | 738 | |
739 | - foreach( $items as $item ) { |
|
739 | + foreach ($items as $item) { |
|
740 | 740 | |
741 | - if ( ! in_array( $item['id'], $selected_items ) ) { |
|
741 | + if (!in_array($item['id'], $selected_items)) { |
|
742 | 742 | continue; |
743 | 743 | } |
744 | 744 | |
745 | 745 | $prepared_items[] = array( |
746 | 746 | 'id' => $item['id'], |
747 | - 'item_price' => wpinv_sanitize_amount( $item['price'] ), |
|
748 | - 'custom_price' => wpinv_sanitize_amount( $item['price'] ), |
|
747 | + 'item_price' => wpinv_sanitize_amount($item['price']), |
|
748 | + 'custom_price' => wpinv_sanitize_amount($item['price']), |
|
749 | 749 | 'name' => $item['title'], |
750 | 750 | ); |
751 | 751 | |
@@ -753,11 +753,11 @@ discard block |
||
753 | 753 | |
754 | 754 | } else { |
755 | 755 | |
756 | - foreach( $items as $item ) { |
|
756 | + foreach ($items as $item) { |
|
757 | 757 | $prepared_items[] = array( |
758 | 758 | 'id' => $item['id'], |
759 | - 'item_price' => wpinv_sanitize_amount( $item['price'] ), |
|
760 | - 'custom_price' => wpinv_sanitize_amount( $item['price'] ), |
|
759 | + 'item_price' => wpinv_sanitize_amount($item['price']), |
|
760 | + 'custom_price' => wpinv_sanitize_amount($item['price']), |
|
761 | 761 | 'name' => $item['title'], |
762 | 762 | ); |
763 | 763 | } |
@@ -765,40 +765,40 @@ discard block |
||
765 | 765 | } |
766 | 766 | |
767 | 767 | // Are all required fields provided? |
768 | - foreach ( $fields as $field ) { |
|
768 | + foreach ($fields as $field) { |
|
769 | 769 | |
770 | - if ( ! empty( $field['premade'] ) ) { |
|
770 | + if (!empty($field['premade'])) { |
|
771 | 771 | continue; |
772 | 772 | } |
773 | 773 | |
774 | - if ( ! empty( $field['required'] ) && empty( $data[ $field['id'] ] ) ) { |
|
775 | - wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) ); |
|
774 | + if (!empty($field['required']) && empty($data[$field['id']])) { |
|
775 | + wp_send_json_error(__('Some required fields have not been filled.', 'invoicing')); |
|
776 | 776 | } |
777 | 777 | |
778 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
778 | + if (isset($data[$field['id']])) { |
|
779 | 779 | $label = $field['id']; |
780 | 780 | |
781 | - if ( isset( $field['label'] ) ) { |
|
781 | + if (isset($field['label'])) { |
|
782 | 782 | $label = $field['label']; |
783 | 783 | } |
784 | 784 | |
785 | - $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] ); |
|
785 | + $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | } |
789 | 789 | |
790 | - $user = get_user_by( 'email', $prepared['billing_email'] ); |
|
790 | + $user = get_user_by('email', $prepared['billing_email']); |
|
791 | 791 | |
792 | - if ( empty( $user ) ) { |
|
793 | - $user = wpinv_create_user( $prepared['billing_email'] ); |
|
792 | + if (empty($user)) { |
|
793 | + $user = wpinv_create_user($prepared['billing_email']); |
|
794 | 794 | } |
795 | 795 | |
796 | - if ( is_wp_error( $user ) ) { |
|
797 | - wp_send_json_error( $user->get_error_message() ); |
|
796 | + if (is_wp_error($user)) { |
|
797 | + wp_send_json_error($user->get_error_message()); |
|
798 | 798 | } |
799 | 799 | |
800 | - if ( is_numeric( $user ) ) { |
|
801 | - $user = get_user_by( 'id', $user ); |
|
800 | + if (is_numeric($user)) { |
|
801 | + $user = get_user_by('id', $user); |
|
802 | 802 | } |
803 | 803 | |
804 | 804 | // Create the invoice. |
@@ -812,18 +812,18 @@ discard block |
||
812 | 812 | true |
813 | 813 | ); |
814 | 814 | |
815 | - if ( is_wp_error( $created ) ) { |
|
816 | - wp_send_json_error( $created->get_error_message() ); |
|
815 | + if (is_wp_error($created)) { |
|
816 | + wp_send_json_error($created->get_error_message()); |
|
817 | 817 | } |
818 | 818 | |
819 | - if ( empty( $created ) ) { |
|
820 | - wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) ); |
|
819 | + if (empty($created)) { |
|
820 | + wp_send_json_error(__('Could not create your invoice.', 'invoicing')); |
|
821 | 821 | } |
822 | 822 | |
823 | - unset( $prepared['billing_email'] ); |
|
824 | - update_post_meta( $created->ID, 'payment_form_data', $prepared ); |
|
823 | + unset($prepared['billing_email']); |
|
824 | + update_post_meta($created->ID, 'payment_form_data', $prepared); |
|
825 | 825 | |
826 | - wp_send_json_success( $created->get_view_url( true ) ); |
|
826 | + wp_send_json_success($created->get_view_url(true)); |
|
827 | 827 | |
828 | 828 | } |
829 | 829 | |
@@ -835,53 +835,53 @@ discard block |
||
835 | 835 | public static function buy_items() { |
836 | 836 | $user_id = get_current_user_id(); |
837 | 837 | |
838 | - if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page |
|
839 | - wp_send_json( array( |
|
840 | - 'success' => wp_login_url( wp_get_referer() ) |
|
841 | - ) ); |
|
838 | + if (empty($user_id)) { // If not logged in then lets redirect to the login page |
|
839 | + wp_send_json(array( |
|
840 | + 'success' => wp_login_url(wp_get_referer()) |
|
841 | + )); |
|
842 | 842 | } else { |
843 | 843 | // Only check nonce if logged in as it could be cached when logged out. |
844 | - if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) { |
|
845 | - wp_send_json( array( |
|
846 | - 'error' => __( 'Security checks failed.', 'invoicing' ) |
|
847 | - ) ); |
|
844 | + if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) { |
|
845 | + wp_send_json(array( |
|
846 | + 'error' => __('Security checks failed.', 'invoicing') |
|
847 | + )); |
|
848 | 848 | wp_die(); |
849 | 849 | } |
850 | 850 | |
851 | 851 | // allow to set a custom price through post_id |
852 | 852 | $items = $_POST['items']; |
853 | - $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0; |
|
854 | - $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0; |
|
853 | + $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0; |
|
854 | + $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0; |
|
855 | 855 | |
856 | 856 | $cart_items = array(); |
857 | - if ( $items ) { |
|
858 | - $items = explode( ',', $items ); |
|
857 | + if ($items) { |
|
858 | + $items = explode(',', $items); |
|
859 | 859 | |
860 | - foreach( $items as $item ) { |
|
860 | + foreach ($items as $item) { |
|
861 | 861 | $item_id = $item; |
862 | 862 | $quantity = 1; |
863 | 863 | |
864 | - if ( strpos( $item, '|' ) !== false ) { |
|
865 | - $item_parts = explode( '|', $item ); |
|
864 | + if (strpos($item, '|') !== false) { |
|
865 | + $item_parts = explode('|', $item); |
|
866 | 866 | $item_id = $item_parts[0]; |
867 | 867 | $quantity = $item_parts[1]; |
868 | 868 | } |
869 | 869 | |
870 | - if ( $item_id && $quantity ) { |
|
870 | + if ($item_id && $quantity) { |
|
871 | 871 | $cart_items_arr = array( |
872 | - 'id' => (int)$item_id, |
|
873 | - 'quantity' => (int)$quantity |
|
872 | + 'id' => (int) $item_id, |
|
873 | + 'quantity' => (int) $quantity |
|
874 | 874 | ); |
875 | 875 | |
876 | 876 | // If there is a related post id then add it to meta |
877 | - if ( $related_post_id ) { |
|
877 | + if ($related_post_id) { |
|
878 | 878 | $cart_items_arr['meta'] = array( |
879 | 879 | 'post_id' => $related_post_id |
880 | 880 | ); |
881 | 881 | } |
882 | 882 | |
883 | 883 | // If there is a custom price then set it. |
884 | - if ( $custom_item_price ) { |
|
884 | + if ($custom_item_price) { |
|
885 | 885 | $cart_items_arr['custom_price'] = $custom_item_price; |
886 | 886 | } |
887 | 887 | |
@@ -897,37 +897,37 @@ discard block |
||
897 | 897 | * @param int $related_post_id The related post id if any. |
898 | 898 | * @since 1.0.0 |
899 | 899 | */ |
900 | - $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id ); |
|
900 | + $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id); |
|
901 | 901 | |
902 | 902 | // Make sure its not in the cart already, if it is then redirect to checkout. |
903 | 903 | $cart_invoice = wpinv_get_invoice_cart(); |
904 | 904 | |
905 | - if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) { |
|
906 | - wp_send_json( array( |
|
905 | + if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) { |
|
906 | + wp_send_json(array( |
|
907 | 907 | 'success' => $cart_invoice->get_checkout_payment_url() |
908 | - ) ); |
|
908 | + )); |
|
909 | 909 | wp_die(); |
910 | 910 | } |
911 | 911 | |
912 | 912 | // Check if user has invoice with same items waiting to be paid. |
913 | - $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' ); |
|
914 | - if ( !empty( $user_invoices ) ) { |
|
915 | - foreach( $user_invoices as $user_invoice ) { |
|
913 | + $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending'); |
|
914 | + if (!empty($user_invoices)) { |
|
915 | + foreach ($user_invoices as $user_invoice) { |
|
916 | 916 | $user_cart_details = array(); |
917 | - $invoice = wpinv_get_invoice( $user_invoice->ID ); |
|
917 | + $invoice = wpinv_get_invoice($user_invoice->ID); |
|
918 | 918 | $cart_details = $invoice->get_cart_details(); |
919 | 919 | |
920 | - if ( !empty( $cart_details ) ) { |
|
921 | - foreach ( $cart_details as $invoice_item ) { |
|
920 | + if (!empty($cart_details)) { |
|
921 | + foreach ($cart_details as $invoice_item) { |
|
922 | 922 | $ii_arr = array(); |
923 | - $ii_arr['id'] = (int)$invoice_item['id']; |
|
924 | - $ii_arr['quantity'] = (int)$invoice_item['quantity']; |
|
923 | + $ii_arr['id'] = (int) $invoice_item['id']; |
|
924 | + $ii_arr['quantity'] = (int) $invoice_item['quantity']; |
|
925 | 925 | |
926 | - if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) { |
|
926 | + if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) { |
|
927 | 927 | $ii_arr['meta'] = $invoice_item['meta']; |
928 | 928 | } |
929 | 929 | |
930 | - if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) { |
|
930 | + if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) { |
|
931 | 931 | $ii_arr['custom_price'] = $invoice_item['custom_price']; |
932 | 932 | } |
933 | 933 | |
@@ -935,17 +935,17 @@ discard block |
||
935 | 935 | } |
936 | 936 | } |
937 | 937 | |
938 | - if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) { |
|
939 | - wp_send_json( array( |
|
938 | + if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) { |
|
939 | + wp_send_json(array( |
|
940 | 940 | 'success' => $invoice->get_checkout_payment_url() |
941 | - ) ); |
|
941 | + )); |
|
942 | 942 | wp_die(); |
943 | 943 | } |
944 | 944 | } |
945 | 945 | } |
946 | 946 | |
947 | 947 | // Create invoice and send user to checkout |
948 | - if ( !empty( $cart_items ) ) { |
|
948 | + if (!empty($cart_items)) { |
|
949 | 949 | $invoice_data = array( |
950 | 950 | 'status' => 'wpi-pending', |
951 | 951 | 'created_via' => 'wpi', |
@@ -953,21 +953,21 @@ discard block |
||
953 | 953 | 'cart_details' => $cart_items, |
954 | 954 | ); |
955 | 955 | |
956 | - $invoice = wpinv_insert_invoice( $invoice_data, true ); |
|
956 | + $invoice = wpinv_insert_invoice($invoice_data, true); |
|
957 | 957 | |
958 | - if ( !empty( $invoice ) && isset( $invoice->ID ) ) { |
|
959 | - wp_send_json( array( |
|
958 | + if (!empty($invoice) && isset($invoice->ID)) { |
|
959 | + wp_send_json(array( |
|
960 | 960 | 'success' => $invoice->get_checkout_payment_url() |
961 | - ) ); |
|
961 | + )); |
|
962 | 962 | } else { |
963 | - wp_send_json( array( |
|
964 | - 'error' => __( 'Invoice failed to create', 'invoicing' ) |
|
965 | - ) ); |
|
963 | + wp_send_json(array( |
|
964 | + 'error' => __('Invoice failed to create', 'invoicing') |
|
965 | + )); |
|
966 | 966 | } |
967 | 967 | } else { |
968 | - wp_send_json( array( |
|
969 | - 'error' => __( 'Items not valid.', 'invoicing' ) |
|
970 | - ) ); |
|
968 | + wp_send_json(array( |
|
969 | + 'error' => __('Items not valid.', 'invoicing') |
|
970 | + )); |
|
971 | 971 | } |
972 | 972 | } |
973 | 973 |