@@ -13,646 +13,646 @@ discard block |
||
13 | 13 | class GetPaid_Post_Types_Admin { |
14 | 14 | |
15 | 15 | /** |
16 | - * Hook in methods. |
|
17 | - */ |
|
18 | - public static function init() { |
|
19 | - |
|
20 | - // Init metaboxes. |
|
21 | - GetPaid_Metaboxes::init(); |
|
22 | - |
|
23 | - // Filter the post updated messages. |
|
24 | - add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | - |
|
26 | - // Filter post actions. |
|
27 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | - add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | - |
|
30 | - // Invoice table columns. |
|
31 | - add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | - add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | - |
|
34 | - // Items table columns. |
|
35 | - add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
36 | - add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
37 | - add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
38 | - add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
39 | - add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
40 | - add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
41 | - |
|
42 | - // Payment forms columns. |
|
43 | - add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
44 | - add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
45 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
46 | - |
|
47 | - // Discount table columns. |
|
48 | - add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
49 | - add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
50 | - |
|
51 | - // Deleting posts. |
|
52 | - add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
53 | - add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Post updated messages. |
|
58 | - */ |
|
59 | - public static function post_updated_messages( $messages ) { |
|
60 | - global $post; |
|
61 | - |
|
62 | - $messages['wpi_discount'] = array( |
|
63 | - 0 => '', |
|
64 | - 1 => __( 'Discount updated.', 'invoicing' ), |
|
65 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
66 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
67 | - 4 => __( 'Discount updated.', 'invoicing' ), |
|
68 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
69 | - 6 => __( 'Discount updated.', 'invoicing' ), |
|
70 | - 7 => __( 'Discount saved.', 'invoicing' ), |
|
71 | - 8 => __( 'Discount submitted.', 'invoicing' ), |
|
72 | - 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
73 | - 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
74 | - ); |
|
75 | - |
|
76 | - $messages['wpi_payment_form'] = array( |
|
77 | - 0 => '', |
|
78 | - 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
79 | - 2 => __( 'Custom field updated.', 'invoicing' ), |
|
80 | - 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
81 | - 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
82 | - 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
83 | - 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
84 | - 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
85 | - 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
86 | - 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
87 | - 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
88 | - ); |
|
89 | - |
|
90 | - return $messages; |
|
91 | - |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Post row actions. |
|
96 | - */ |
|
97 | - public static function post_row_actions( $actions, $post ) { |
|
98 | - |
|
99 | - $post = get_post( $post ); |
|
100 | - |
|
101 | - // We do not want to edit the default payment form. |
|
102 | - if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
103 | - unset( $actions['trash'] ); |
|
104 | - unset( $actions['inline hide-if-no-js'] ); |
|
105 | - } |
|
106 | - |
|
107 | - return $actions; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
16 | + * Hook in methods. |
|
17 | + */ |
|
18 | + public static function init() { |
|
19 | + |
|
20 | + // Init metaboxes. |
|
21 | + GetPaid_Metaboxes::init(); |
|
22 | + |
|
23 | + // Filter the post updated messages. |
|
24 | + add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' ); |
|
25 | + |
|
26 | + // Filter post actions. |
|
27 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 ); |
|
28 | + add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::filter_invoice_row_actions', 90, 2 ); |
|
29 | + |
|
30 | + // Invoice table columns. |
|
31 | + add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 ); |
|
32 | + add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 ); |
|
33 | + |
|
34 | + // Items table columns. |
|
35 | + add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 ); |
|
36 | + add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 ); |
|
37 | + add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 ); |
|
38 | + add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 ); |
|
39 | + add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 ); |
|
40 | + add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 ); |
|
41 | + |
|
42 | + // Payment forms columns. |
|
43 | + add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 ); |
|
44 | + add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 ); |
|
45 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 ); |
|
46 | + |
|
47 | + // Discount table columns. |
|
48 | + add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 ); |
|
49 | + add_filter( 'bulk_actions-edit-wpi_discount', '__return_empty_array', 100 ); |
|
50 | + |
|
51 | + // Deleting posts. |
|
52 | + add_action( 'delete_post', array( __CLASS__, 'delete_post' ) ); |
|
53 | + add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 ); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Post updated messages. |
|
58 | + */ |
|
59 | + public static function post_updated_messages( $messages ) { |
|
60 | + global $post; |
|
61 | + |
|
62 | + $messages['wpi_discount'] = array( |
|
63 | + 0 => '', |
|
64 | + 1 => __( 'Discount updated.', 'invoicing' ), |
|
65 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
66 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
67 | + 4 => __( 'Discount updated.', 'invoicing' ), |
|
68 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
69 | + 6 => __( 'Discount updated.', 'invoicing' ), |
|
70 | + 7 => __( 'Discount saved.', 'invoicing' ), |
|
71 | + 8 => __( 'Discount submitted.', 'invoicing' ), |
|
72 | + 9 => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
73 | + 10 => __( 'Discount draft updated.', 'invoicing' ), |
|
74 | + ); |
|
75 | + |
|
76 | + $messages['wpi_payment_form'] = array( |
|
77 | + 0 => '', |
|
78 | + 1 => __( 'Payment Form updated.', 'invoicing' ), |
|
79 | + 2 => __( 'Custom field updated.', 'invoicing' ), |
|
80 | + 3 => __( 'Custom field deleted.', 'invoicing' ), |
|
81 | + 4 => __( 'Payment Form updated.', 'invoicing' ), |
|
82 | + 5 => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, |
|
83 | + 6 => __( 'Payment Form updated.', 'invoicing' ), |
|
84 | + 7 => __( 'Payment Form saved.', 'invoicing' ), |
|
85 | + 8 => __( 'Payment Form submitted.', 'invoicing' ), |
|
86 | + 9 => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ), |
|
87 | + 10 => __( 'Payment Form draft updated.', 'invoicing' ), |
|
88 | + ); |
|
89 | + |
|
90 | + return $messages; |
|
91 | + |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Post row actions. |
|
96 | + */ |
|
97 | + public static function post_row_actions( $actions, $post ) { |
|
98 | + |
|
99 | + $post = get_post( $post ); |
|
100 | + |
|
101 | + // We do not want to edit the default payment form. |
|
102 | + if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) { |
|
103 | + unset( $actions['trash'] ); |
|
104 | + unset( $actions['inline hide-if-no-js'] ); |
|
105 | + } |
|
106 | + |
|
107 | + return $actions; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | 111 | * Remove bulk edit option from admin side quote listing |
112 | 112 | * |
113 | 113 | * @since 1.0.0 |
114 | 114 | * @param array $actions post actions |
115 | - * @param WP_Post $post |
|
115 | + * @param WP_Post $post |
|
116 | 116 | * @return array $actions actions without edit option |
117 | 117 | */ |
118 | 118 | public static function filter_invoice_row_actions( $actions, $post ) { |
119 | 119 | |
120 | 120 | if ( getpaid_is_invoice_post_type( $post->post_type ) ) { |
121 | 121 | |
122 | - $actions = array(); |
|
123 | - $invoice = new WPInv_Invoice( $post ); |
|
124 | - |
|
125 | - $actions['edit'] = sprintf( |
|
126 | - '<a href="%1$s">%2$s</a>', |
|
127 | - esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
128 | - esc_html( __( 'Edit', 'invoicing' ) ) |
|
129 | - ); |
|
130 | - |
|
131 | - if ( ! $invoice->is_draft() ) { |
|
132 | - |
|
133 | - $actions['view'] = sprintf( |
|
134 | - '<a href="%1$s">%2$s</a>', |
|
135 | - esc_url( $invoice->get_view_url() ), |
|
136 | - sprintf( |
|
137 | - esc_html( __( 'View %s', 'invoicing' ) ), |
|
138 | - getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
139 | - ) |
|
140 | - ); |
|
141 | - |
|
142 | - $actions['send'] = sprintf( |
|
143 | - '<a href="%1$s">%2$s</a>', |
|
144 | - esc_url( |
|
145 | - wp_nonce_url( |
|
146 | - add_query_arg( |
|
147 | - array( |
|
148 | - 'getpaid-admin-action' => 'send_invoice', |
|
149 | - 'invoice_id' => $invoice->get_id() |
|
150 | - ) |
|
151 | - ), |
|
152 | - 'getpaid-nonce', |
|
153 | - 'getpaid-nonce' |
|
154 | - ) |
|
155 | - ), |
|
156 | - esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
157 | - ); |
|
158 | - |
|
159 | - } |
|
122 | + $actions = array(); |
|
123 | + $invoice = new WPInv_Invoice( $post ); |
|
124 | + |
|
125 | + $actions['edit'] = sprintf( |
|
126 | + '<a href="%1$s">%2$s</a>', |
|
127 | + esc_url( get_edit_post_link( $invoice->get_id() ) ), |
|
128 | + esc_html( __( 'Edit', 'invoicing' ) ) |
|
129 | + ); |
|
130 | + |
|
131 | + if ( ! $invoice->is_draft() ) { |
|
132 | + |
|
133 | + $actions['view'] = sprintf( |
|
134 | + '<a href="%1$s">%2$s</a>', |
|
135 | + esc_url( $invoice->get_view_url() ), |
|
136 | + sprintf( |
|
137 | + esc_html( __( 'View %s', 'invoicing' ) ), |
|
138 | + getpaid_get_post_type_label( $invoice->get_post_type(), false ) |
|
139 | + ) |
|
140 | + ); |
|
141 | + |
|
142 | + $actions['send'] = sprintf( |
|
143 | + '<a href="%1$s">%2$s</a>', |
|
144 | + esc_url( |
|
145 | + wp_nonce_url( |
|
146 | + add_query_arg( |
|
147 | + array( |
|
148 | + 'getpaid-admin-action' => 'send_invoice', |
|
149 | + 'invoice_id' => $invoice->get_id() |
|
150 | + ) |
|
151 | + ), |
|
152 | + 'getpaid-nonce', |
|
153 | + 'getpaid-nonce' |
|
154 | + ) |
|
155 | + ), |
|
156 | + esc_html( __( 'Send to Customer', 'invoicing' ) ) |
|
157 | + ); |
|
158 | + |
|
159 | + } |
|
160 | 160 | |
161 | 161 | } |
162 | 162 | |
163 | 163 | return $actions; |
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Returns an array of invoice table columns. |
|
168 | - */ |
|
169 | - public static function invoice_columns( $columns ) { |
|
170 | - |
|
171 | - $columns = array( |
|
172 | - 'cb' => $columns['cb'], |
|
173 | - 'number' => __( 'Invoice', 'invoicing' ), |
|
174 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
175 | - 'invoice_date' => __( 'Created', 'invoicing' ), |
|
176 | - 'payment_date' => __( 'Completed', 'invoicing' ), |
|
177 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
178 | - 'recurring' => __( 'Recurring', 'invoicing' ), |
|
179 | - 'status' => __( 'Status', 'invoicing' ), |
|
180 | - ); |
|
181 | - |
|
182 | - return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Displays invoice table columns. |
|
187 | - */ |
|
188 | - public static function display_invoice_columns( $column_name, $post_id ) { |
|
189 | - |
|
190 | - $invoice = new WPInv_Invoice( $post_id ); |
|
191 | - |
|
192 | - switch ( $column_name ) { |
|
193 | - |
|
194 | - case 'invoice_date' : |
|
195 | - $date_time = esc_attr( $invoice->get_created_date() ); |
|
196 | - $date = getpaid_format_date_value( $date_time, "—", true ); |
|
197 | - echo "<span title='$date_time'>$date</span>"; |
|
198 | - break; |
|
199 | - |
|
200 | - case 'payment_date' : |
|
201 | - |
|
202 | - if ( $invoice->is_paid() ) { |
|
203 | - $date_time = esc_attr( $invoice->get_completed_date() ); |
|
204 | - $date = getpaid_format_date_value( $date_time, "—", true ); |
|
205 | - echo "<span title='$date_time'>$date</span>"; |
|
206 | - } else { |
|
207 | - echo "—"; |
|
208 | - } |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Returns an array of invoice table columns. |
|
168 | + */ |
|
169 | + public static function invoice_columns( $columns ) { |
|
170 | + |
|
171 | + $columns = array( |
|
172 | + 'cb' => $columns['cb'], |
|
173 | + 'number' => __( 'Invoice', 'invoicing' ), |
|
174 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
175 | + 'invoice_date' => __( 'Created', 'invoicing' ), |
|
176 | + 'payment_date' => __( 'Completed', 'invoicing' ), |
|
177 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
178 | + 'recurring' => __( 'Recurring', 'invoicing' ), |
|
179 | + 'status' => __( 'Status', 'invoicing' ), |
|
180 | + ); |
|
181 | + |
|
182 | + return apply_filters( 'wpi_invoice_table_columns', $columns ); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Displays invoice table columns. |
|
187 | + */ |
|
188 | + public static function display_invoice_columns( $column_name, $post_id ) { |
|
189 | + |
|
190 | + $invoice = new WPInv_Invoice( $post_id ); |
|
191 | + |
|
192 | + switch ( $column_name ) { |
|
193 | + |
|
194 | + case 'invoice_date' : |
|
195 | + $date_time = esc_attr( $invoice->get_created_date() ); |
|
196 | + $date = getpaid_format_date_value( $date_time, "—", true ); |
|
197 | + echo "<span title='$date_time'>$date</span>"; |
|
198 | + break; |
|
199 | + |
|
200 | + case 'payment_date' : |
|
201 | + |
|
202 | + if ( $invoice->is_paid() ) { |
|
203 | + $date_time = esc_attr( $invoice->get_completed_date() ); |
|
204 | + $date = getpaid_format_date_value( $date_time, "—", true ); |
|
205 | + echo "<span title='$date_time'>$date</span>"; |
|
206 | + } else { |
|
207 | + echo "—"; |
|
208 | + } |
|
209 | 209 | |
210 | - break; |
|
210 | + break; |
|
211 | 211 | |
212 | - case 'amount' : |
|
212 | + case 'amount' : |
|
213 | 213 | |
214 | - $amount = $invoice->get_total(); |
|
215 | - $formated_amount = wpinv_price( $amount, $invoice->get_currency() ); |
|
214 | + $amount = $invoice->get_total(); |
|
215 | + $formated_amount = wpinv_price( $amount, $invoice->get_currency() ); |
|
216 | 216 | |
217 | - if ( $invoice->is_refunded() ) { |
|
218 | - $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
219 | - echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
220 | - } else { |
|
217 | + if ( $invoice->is_refunded() ) { |
|
218 | + $refunded_amount = wpinv_price( 0, $invoice->get_currency() ); |
|
219 | + echo "<del>$formated_amount</del> <ins>$refunded_amount</ins>"; |
|
220 | + } else { |
|
221 | 221 | |
222 | - $discount = $invoice->get_total_discount(); |
|
222 | + $discount = $invoice->get_total_discount(); |
|
223 | 223 | |
224 | - if ( ! empty( $discount ) ) { |
|
225 | - $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
226 | - echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
227 | - } else { |
|
228 | - echo $formated_amount; |
|
229 | - } |
|
224 | + if ( ! empty( $discount ) ) { |
|
225 | + $new_amount = wpinv_price( $amount + $discount, $invoice->get_currency() ); |
|
226 | + echo "<del>$new_amount</del> <ins>$formated_amount</ins>"; |
|
227 | + } else { |
|
228 | + echo $formated_amount; |
|
229 | + } |
|
230 | 230 | |
231 | - } |
|
231 | + } |
|
232 | 232 | |
233 | - break; |
|
233 | + break; |
|
234 | 234 | |
235 | - case 'status' : |
|
236 | - $status = sanitize_text_field( $invoice->get_status() ); |
|
237 | - $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
235 | + case 'status' : |
|
236 | + $status = sanitize_text_field( $invoice->get_status() ); |
|
237 | + $status_label = sanitize_text_field( $invoice->get_status_nicename() ); |
|
238 | 238 | |
239 | - // If it is paid, show the gateway title. |
|
240 | - if ( $invoice->is_paid() ) { |
|
241 | - $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
242 | - $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
239 | + // If it is paid, show the gateway title. |
|
240 | + if ( $invoice->is_paid() ) { |
|
241 | + $gateway = sanitize_text_field( $invoice->get_gateway_title() ); |
|
242 | + $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway ); |
|
243 | 243 | |
244 | - echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
245 | - } else { |
|
246 | - echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
247 | - } |
|
244 | + echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>"; |
|
245 | + } else { |
|
246 | + echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>"; |
|
247 | + } |
|
248 | 248 | |
249 | - // If it is not paid, display the overdue and view status. |
|
250 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
249 | + // If it is not paid, display the overdue and view status. |
|
250 | + if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
251 | 251 | |
252 | - // Invoice view status. |
|
253 | - if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
254 | - echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
255 | - } else { |
|
256 | - echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
257 | - } |
|
252 | + // Invoice view status. |
|
253 | + if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) { |
|
254 | + echo ' <i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>'; |
|
255 | + } else { |
|
256 | + echo ' <i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>'; |
|
257 | + } |
|
258 | 258 | |
259 | - // Display the overview status. |
|
260 | - if ( wpinv_get_option( 'overdue_active' ) ) { |
|
261 | - $due_date = $invoice->get_due_date(); |
|
262 | - $fomatted = getpaid_format_date( $due_date ); |
|
259 | + // Display the overview status. |
|
260 | + if ( wpinv_get_option( 'overdue_active' ) ) { |
|
261 | + $due_date = $invoice->get_due_date(); |
|
262 | + $fomatted = getpaid_format_date( $due_date ); |
|
263 | 263 | |
264 | - if ( ! empty( $fomatted ) ) { |
|
265 | - $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
266 | - echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
267 | - } |
|
268 | - } |
|
264 | + if ( ! empty( $fomatted ) ) { |
|
265 | + $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted ); |
|
266 | + echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>"; |
|
267 | + } |
|
268 | + } |
|
269 | 269 | |
270 | - } |
|
270 | + } |
|
271 | 271 | |
272 | - break; |
|
272 | + break; |
|
273 | 273 | |
274 | - case 'recurring': |
|
274 | + case 'recurring': |
|
275 | 275 | |
276 | - if ( $invoice->is_recurring() ) { |
|
277 | - echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
278 | - } else { |
|
279 | - echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
280 | - } |
|
281 | - break; |
|
276 | + if ( $invoice->is_recurring() ) { |
|
277 | + echo '<i class="fa fa-check" style="color:#43850a;"></i>'; |
|
278 | + } else { |
|
279 | + echo '<i class="fa fa-times" style="color:#616161;"></i>'; |
|
280 | + } |
|
281 | + break; |
|
282 | 282 | |
283 | - case 'number' : |
|
283 | + case 'number' : |
|
284 | 284 | |
285 | - $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
286 | - $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
287 | - $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
285 | + $edit_link = esc_url( get_edit_post_link( $invoice->get_id() ) ); |
|
286 | + $invoice_number = sanitize_text_field( $invoice->get_number() ); |
|
287 | + $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' ); |
|
288 | 288 | |
289 | - echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
289 | + echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>"; |
|
290 | 290 | |
291 | - break; |
|
291 | + break; |
|
292 | 292 | |
293 | - case 'customer' : |
|
293 | + case 'customer' : |
|
294 | 294 | |
295 | - $customer_name = $invoice->get_user_full_name(); |
|
295 | + $customer_name = $invoice->get_user_full_name(); |
|
296 | 296 | |
297 | - if ( empty( $customer_name ) ) { |
|
298 | - $customer_name = $invoice->get_email(); |
|
299 | - } |
|
297 | + if ( empty( $customer_name ) ) { |
|
298 | + $customer_name = $invoice->get_email(); |
|
299 | + } |
|
300 | 300 | |
301 | - if ( ! empty( $customer_name ) ) { |
|
302 | - $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
303 | - $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
304 | - echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
305 | - } else { |
|
306 | - echo '<div>—</div>'; |
|
307 | - } |
|
301 | + if ( ! empty( $customer_name ) ) { |
|
302 | + $customer_details = esc_attr__( 'View Customer Details', 'invoicing' ); |
|
303 | + $view_link = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) ); |
|
304 | + echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>"; |
|
305 | + } else { |
|
306 | + echo '<div>—</div>'; |
|
307 | + } |
|
308 | 308 | |
309 | - break; |
|
309 | + break; |
|
310 | 310 | |
311 | - } |
|
311 | + } |
|
312 | 312 | |
313 | - } |
|
313 | + } |
|
314 | 314 | |
315 | - /** |
|
316 | - * Returns an array of payment forms table columns. |
|
317 | - */ |
|
318 | - public static function payment_form_columns( $columns ) { |
|
315 | + /** |
|
316 | + * Returns an array of payment forms table columns. |
|
317 | + */ |
|
318 | + public static function payment_form_columns( $columns ) { |
|
319 | 319 | |
320 | - $columns = array( |
|
321 | - 'cb' => $columns['cb'], |
|
322 | - 'title' => __( 'Name', 'invoicing' ), |
|
323 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
324 | - 'earnings' => __( 'Revenue', 'invoicing' ), |
|
325 | - 'refunds' => __( 'Refunded', 'invoicing' ), |
|
326 | - 'items' => __( 'Items', 'invoicing' ), |
|
327 | - 'date' => __( 'Date', 'invoicing' ), |
|
328 | - ); |
|
320 | + $columns = array( |
|
321 | + 'cb' => $columns['cb'], |
|
322 | + 'title' => __( 'Name', 'invoicing' ), |
|
323 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
324 | + 'earnings' => __( 'Revenue', 'invoicing' ), |
|
325 | + 'refunds' => __( 'Refunded', 'invoicing' ), |
|
326 | + 'items' => __( 'Items', 'invoicing' ), |
|
327 | + 'date' => __( 'Date', 'invoicing' ), |
|
328 | + ); |
|
329 | 329 | |
330 | - return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
330 | + return apply_filters( 'wpi_payment_form_table_columns', $columns ); |
|
331 | 331 | |
332 | - } |
|
332 | + } |
|
333 | 333 | |
334 | - /** |
|
335 | - * Displays payment form table columns. |
|
336 | - */ |
|
337 | - public static function display_payment_form_columns( $column_name, $post_id ) { |
|
334 | + /** |
|
335 | + * Displays payment form table columns. |
|
336 | + */ |
|
337 | + public static function display_payment_form_columns( $column_name, $post_id ) { |
|
338 | 338 | |
339 | - // Retrieve the payment form. |
|
340 | - $form = new GetPaid_Payment_Form( $post_id ); |
|
339 | + // Retrieve the payment form. |
|
340 | + $form = new GetPaid_Payment_Form( $post_id ); |
|
341 | 341 | |
342 | - switch ( $column_name ) { |
|
342 | + switch ( $column_name ) { |
|
343 | 343 | |
344 | - case 'earnings' : |
|
345 | - echo wpinv_price( $form->get_earned() ); |
|
346 | - break; |
|
344 | + case 'earnings' : |
|
345 | + echo wpinv_price( $form->get_earned() ); |
|
346 | + break; |
|
347 | 347 | |
348 | - case 'refunds' : |
|
349 | - echo wpinv_price( $form->get_refunded() ); |
|
350 | - break; |
|
348 | + case 'refunds' : |
|
349 | + echo wpinv_price( $form->get_refunded() ); |
|
350 | + break; |
|
351 | 351 | |
352 | - case 'refunds' : |
|
353 | - echo wpinv_price( $form->get_refunded() ); |
|
354 | - break; |
|
352 | + case 'refunds' : |
|
353 | + echo wpinv_price( $form->get_refunded() ); |
|
354 | + break; |
|
355 | 355 | |
356 | - case 'shortcode' : |
|
356 | + case 'shortcode' : |
|
357 | 357 | |
358 | - if ( $form->is_default() ) { |
|
359 | - echo '—'; |
|
360 | - } else { |
|
361 | - echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
362 | - } |
|
358 | + if ( $form->is_default() ) { |
|
359 | + echo '—'; |
|
360 | + } else { |
|
361 | + echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>'; |
|
362 | + } |
|
363 | 363 | |
364 | - break; |
|
364 | + break; |
|
365 | 365 | |
366 | - case 'items' : |
|
366 | + case 'items' : |
|
367 | 367 | |
368 | - $items = $form->get_items(); |
|
368 | + $items = $form->get_items(); |
|
369 | 369 | |
370 | - if ( $form->is_default() || empty( $items ) ) { |
|
371 | - echo '—'; |
|
372 | - return; |
|
373 | - } |
|
370 | + if ( $form->is_default() || empty( $items ) ) { |
|
371 | + echo '—'; |
|
372 | + return; |
|
373 | + } |
|
374 | 374 | |
375 | - $_items = array(); |
|
375 | + $_items = array(); |
|
376 | 376 | |
377 | - foreach ( $items as $item ) { |
|
378 | - $url = $item->get_edit_url(); |
|
377 | + foreach ( $items as $item ) { |
|
378 | + $url = $item->get_edit_url(); |
|
379 | 379 | |
380 | - if ( empty( $url ) ) { |
|
381 | - $_items[] = sanitize_text_field( $item->get_name() ); |
|
382 | - } else { |
|
383 | - $_items[] = sprintf( |
|
384 | - '<a href="%s">%s</a>', |
|
385 | - esc_url( $url ), |
|
386 | - sanitize_text_field( $item->get_name() ) |
|
387 | - ); |
|
388 | - } |
|
380 | + if ( empty( $url ) ) { |
|
381 | + $_items[] = sanitize_text_field( $item->get_name() ); |
|
382 | + } else { |
|
383 | + $_items[] = sprintf( |
|
384 | + '<a href="%s">%s</a>', |
|
385 | + esc_url( $url ), |
|
386 | + sanitize_text_field( $item->get_name() ) |
|
387 | + ); |
|
388 | + } |
|
389 | 389 | |
390 | - } |
|
390 | + } |
|
391 | 391 | |
392 | - echo implode( '<br>', $_items ); |
|
392 | + echo implode( '<br>', $_items ); |
|
393 | 393 | |
394 | - break; |
|
394 | + break; |
|
395 | 395 | |
396 | - } |
|
396 | + } |
|
397 | 397 | |
398 | - } |
|
398 | + } |
|
399 | 399 | |
400 | - /** |
|
401 | - * Filters post states. |
|
402 | - */ |
|
403 | - public static function filter_payment_form_state( $post_states, $post ) { |
|
400 | + /** |
|
401 | + * Filters post states. |
|
402 | + */ |
|
403 | + public static function filter_payment_form_state( $post_states, $post ) { |
|
404 | 404 | |
405 | - if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
406 | - $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
407 | - } |
|
405 | + if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) { |
|
406 | + $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' ); |
|
407 | + } |
|
408 | 408 | |
409 | - return $post_states; |
|
410 | - |
|
411 | - } |
|
412 | - |
|
413 | - /** |
|
414 | - * Returns an array of coupon table columns. |
|
415 | - */ |
|
416 | - public static function discount_columns( $columns ) { |
|
417 | - |
|
418 | - $columns = array( |
|
419 | - 'cb' => $columns['cb'], |
|
420 | - 'title' => __( 'Name', 'invoicing' ), |
|
421 | - 'code' => __( 'Code', 'invoicing' ), |
|
422 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
423 | - 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
424 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
425 | - 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
426 | - ); |
|
427 | - |
|
428 | - return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
429 | - } |
|
430 | - |
|
431 | - /** |
|
432 | - * Filters post states. |
|
433 | - */ |
|
434 | - public static function filter_discount_state( $post_states, $post ) { |
|
435 | - |
|
436 | - if ( 'wpi_discount' == $post->post_type ) { |
|
437 | - |
|
438 | - $discount = new WPInv_Discount( $post ); |
|
439 | - |
|
440 | - $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
441 | - |
|
442 | - if ( $status != 'publish' ) { |
|
443 | - return array( |
|
444 | - 'discount_status' => wpinv_discount_status( $status ), |
|
445 | - ); |
|
446 | - } |
|
447 | - |
|
448 | - return array(); |
|
449 | - |
|
450 | - } |
|
451 | - |
|
452 | - return $post_states; |
|
453 | - |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Returns an array of items table columns. |
|
458 | - */ |
|
459 | - public static function item_columns( $columns ) { |
|
460 | - |
|
461 | - $columns = array( |
|
462 | - 'cb' => $columns['cb'], |
|
463 | - 'title' => __( 'Name', 'invoicing' ), |
|
464 | - 'price' => __( 'Price', 'invoicing' ), |
|
465 | - 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
466 | - 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
467 | - 'type' => __( 'Type', 'invoicing' ), |
|
468 | - 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
469 | - ); |
|
470 | - |
|
471 | - if ( ! wpinv_use_taxes() ) { |
|
472 | - unset( $columns['vat_rule'] ); |
|
473 | - unset( $columns['vat_class'] ); |
|
474 | - } |
|
475 | - |
|
476 | - return apply_filters( 'wpi_item_table_columns', $columns ); |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * Returns an array of sortable items table columns. |
|
481 | - */ |
|
482 | - public static function sortable_item_columns( $columns ) { |
|
483 | - |
|
484 | - return array_merge( |
|
485 | - $columns, |
|
486 | - array( |
|
487 | - 'price' => 'price', |
|
488 | - 'vat_rule' => 'vat_rule', |
|
489 | - 'vat_class' => 'vat_class', |
|
490 | - 'type' => 'type', |
|
491 | - ) |
|
492 | - ); |
|
493 | - |
|
494 | - } |
|
495 | - |
|
496 | - /** |
|
497 | - * Displays items table columns. |
|
498 | - */ |
|
499 | - public static function display_item_columns( $column_name, $post_id ) { |
|
409 | + return $post_states; |
|
410 | + |
|
411 | + } |
|
412 | + |
|
413 | + /** |
|
414 | + * Returns an array of coupon table columns. |
|
415 | + */ |
|
416 | + public static function discount_columns( $columns ) { |
|
417 | + |
|
418 | + $columns = array( |
|
419 | + 'cb' => $columns['cb'], |
|
420 | + 'title' => __( 'Name', 'invoicing' ), |
|
421 | + 'code' => __( 'Code', 'invoicing' ), |
|
422 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
423 | + 'usage' => __( 'Usage / Limit', 'invoicing' ), |
|
424 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
425 | + 'expiry_date' => __( 'Expiry Date', 'invoicing' ), |
|
426 | + ); |
|
427 | + |
|
428 | + return apply_filters( 'wpi_discount_table_columns', $columns ); |
|
429 | + } |
|
430 | + |
|
431 | + /** |
|
432 | + * Filters post states. |
|
433 | + */ |
|
434 | + public static function filter_discount_state( $post_states, $post ) { |
|
435 | + |
|
436 | + if ( 'wpi_discount' == $post->post_type ) { |
|
437 | + |
|
438 | + $discount = new WPInv_Discount( $post ); |
|
439 | + |
|
440 | + $status = $discount->is_expired() ? 'expired' : $discount->get_status(); |
|
441 | + |
|
442 | + if ( $status != 'publish' ) { |
|
443 | + return array( |
|
444 | + 'discount_status' => wpinv_discount_status( $status ), |
|
445 | + ); |
|
446 | + } |
|
447 | + |
|
448 | + return array(); |
|
449 | + |
|
450 | + } |
|
451 | + |
|
452 | + return $post_states; |
|
453 | + |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Returns an array of items table columns. |
|
458 | + */ |
|
459 | + public static function item_columns( $columns ) { |
|
460 | + |
|
461 | + $columns = array( |
|
462 | + 'cb' => $columns['cb'], |
|
463 | + 'title' => __( 'Name', 'invoicing' ), |
|
464 | + 'price' => __( 'Price', 'invoicing' ), |
|
465 | + 'vat_rule' => __( 'VAT rule', 'invoicing' ), |
|
466 | + 'vat_class' => __( 'VAT class', 'invoicing' ), |
|
467 | + 'type' => __( 'Type', 'invoicing' ), |
|
468 | + 'shortcode' => __( 'Shortcode', 'invoicing' ), |
|
469 | + ); |
|
470 | + |
|
471 | + if ( ! wpinv_use_taxes() ) { |
|
472 | + unset( $columns['vat_rule'] ); |
|
473 | + unset( $columns['vat_class'] ); |
|
474 | + } |
|
475 | + |
|
476 | + return apply_filters( 'wpi_item_table_columns', $columns ); |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * Returns an array of sortable items table columns. |
|
481 | + */ |
|
482 | + public static function sortable_item_columns( $columns ) { |
|
483 | + |
|
484 | + return array_merge( |
|
485 | + $columns, |
|
486 | + array( |
|
487 | + 'price' => 'price', |
|
488 | + 'vat_rule' => 'vat_rule', |
|
489 | + 'vat_class' => 'vat_class', |
|
490 | + 'type' => 'type', |
|
491 | + ) |
|
492 | + ); |
|
493 | + |
|
494 | + } |
|
495 | + |
|
496 | + /** |
|
497 | + * Displays items table columns. |
|
498 | + */ |
|
499 | + public static function display_item_columns( $column_name, $post_id ) { |
|
500 | 500 | |
501 | - $item = new WPInv_Item( $post_id ); |
|
501 | + $item = new WPInv_Item( $post_id ); |
|
502 | 502 | |
503 | - switch ( $column_name ) { |
|
503 | + switch ( $column_name ) { |
|
504 | 504 | |
505 | - case 'price' : |
|
505 | + case 'price' : |
|
506 | 506 | |
507 | - if ( ! $item->is_recurring() ) { |
|
508 | - echo $item->get_the_price(); |
|
509 | - break; |
|
510 | - } |
|
507 | + if ( ! $item->is_recurring() ) { |
|
508 | + echo $item->get_the_price(); |
|
509 | + break; |
|
510 | + } |
|
511 | 511 | |
512 | - $price = wp_sprintf( |
|
513 | - __( '%s / %s', 'invoicing' ), |
|
514 | - $item->get_the_price(), |
|
515 | - getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
516 | - ); |
|
512 | + $price = wp_sprintf( |
|
513 | + __( '%s / %s', 'invoicing' ), |
|
514 | + $item->get_the_price(), |
|
515 | + getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ) |
|
516 | + ); |
|
517 | 517 | |
518 | - if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
519 | - echo $price; |
|
520 | - break; |
|
521 | - } |
|
518 | + if ( $item->get_the_price() == $item->get_the_initial_price() ) { |
|
519 | + echo $price; |
|
520 | + break; |
|
521 | + } |
|
522 | 522 | |
523 | - echo $item->get_the_initial_price(); |
|
523 | + echo $item->get_the_initial_price(); |
|
524 | 524 | |
525 | - echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
526 | - break; |
|
525 | + echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price ) .'</span>'; |
|
526 | + break; |
|
527 | 527 | |
528 | - case 'vat_rule' : |
|
529 | - echo getpaid_get_tax_rule_label( $item->get_vat_rule() ); |
|
530 | - break; |
|
528 | + case 'vat_rule' : |
|
529 | + echo getpaid_get_tax_rule_label( $item->get_vat_rule() ); |
|
530 | + break; |
|
531 | 531 | |
532 | - case 'vat_class' : |
|
533 | - echo getpaid_get_tax_class_label( $item->get_vat_class() ); |
|
534 | - break; |
|
532 | + case 'vat_class' : |
|
533 | + echo getpaid_get_tax_class_label( $item->get_vat_class() ); |
|
534 | + break; |
|
535 | 535 | |
536 | - case 'shortcode' : |
|
537 | - echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
538 | - break; |
|
536 | + case 'shortcode' : |
|
537 | + echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>'; |
|
538 | + break; |
|
539 | 539 | |
540 | - case 'type' : |
|
541 | - echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
542 | - break; |
|
540 | + case 'type' : |
|
541 | + echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>'; |
|
542 | + break; |
|
543 | 543 | |
544 | - } |
|
544 | + } |
|
545 | 545 | |
546 | - } |
|
546 | + } |
|
547 | 547 | |
548 | - /** |
|
549 | - * Lets users filter items using taxes. |
|
550 | - */ |
|
551 | - public static function add_item_filters( $post_type ) { |
|
548 | + /** |
|
549 | + * Lets users filter items using taxes. |
|
550 | + */ |
|
551 | + public static function add_item_filters( $post_type ) { |
|
552 | 552 | |
553 | - // Abort if we're not dealing with items. |
|
554 | - if ( $post_type != 'wpi_item' ) { |
|
555 | - return; |
|
556 | - } |
|
553 | + // Abort if we're not dealing with items. |
|
554 | + if ( $post_type != 'wpi_item' ) { |
|
555 | + return; |
|
556 | + } |
|
557 | 557 | |
558 | - // Filter by vat rules. |
|
559 | - if ( wpinv_use_taxes() ) { |
|
558 | + // Filter by vat rules. |
|
559 | + if ( wpinv_use_taxes() ) { |
|
560 | 560 | |
561 | - // Sanitize selected vat rule. |
|
562 | - $vat_rule = ''; |
|
563 | - $vat_rules = getpaid_get_tax_rules(); |
|
564 | - if ( isset( $_GET['vat_rule'] ) ) { |
|
565 | - $vat_rule = $_GET['vat_rule']; |
|
566 | - } |
|
567 | - |
|
568 | - // Filter by VAT rule. |
|
569 | - echo wpinv_html_select( |
|
570 | - array( |
|
571 | - 'options' => array_merge( |
|
572 | - array( |
|
573 | - '' => __( 'All VAT rules', 'invoicing' ) |
|
574 | - ), |
|
575 | - $vat_rules |
|
576 | - ), |
|
577 | - 'name' => 'vat_rule', |
|
578 | - 'id' => 'vat_rule', |
|
579 | - 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
580 | - 'show_option_all' => false, |
|
581 | - 'show_option_none' => false, |
|
582 | - ) |
|
583 | - ); |
|
584 | - |
|
585 | - // Filter by VAT class. |
|
561 | + // Sanitize selected vat rule. |
|
562 | + $vat_rule = ''; |
|
563 | + $vat_rules = getpaid_get_tax_rules(); |
|
564 | + if ( isset( $_GET['vat_rule'] ) ) { |
|
565 | + $vat_rule = $_GET['vat_rule']; |
|
566 | + } |
|
567 | + |
|
568 | + // Filter by VAT rule. |
|
569 | + echo wpinv_html_select( |
|
570 | + array( |
|
571 | + 'options' => array_merge( |
|
572 | + array( |
|
573 | + '' => __( 'All VAT rules', 'invoicing' ) |
|
574 | + ), |
|
575 | + $vat_rules |
|
576 | + ), |
|
577 | + 'name' => 'vat_rule', |
|
578 | + 'id' => 'vat_rule', |
|
579 | + 'selected' => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '', |
|
580 | + 'show_option_all' => false, |
|
581 | + 'show_option_none' => false, |
|
582 | + ) |
|
583 | + ); |
|
584 | + |
|
585 | + // Filter by VAT class. |
|
586 | 586 | |
587 | - // Sanitize selected vat rule. |
|
588 | - $vat_class = ''; |
|
589 | - $vat_classes = getpaid_get_tax_classes(); |
|
590 | - if ( isset( $_GET['vat_class'] ) ) { |
|
591 | - $vat_class = $_GET['vat_class']; |
|
592 | - } |
|
593 | - |
|
594 | - echo wpinv_html_select( |
|
595 | - array( |
|
596 | - 'options' => array_merge( |
|
597 | - array( |
|
598 | - '' => __( 'All VAT classes', 'invoicing' ) |
|
599 | - ), |
|
600 | - $vat_classes |
|
601 | - ), |
|
602 | - 'name' => 'vat_class', |
|
603 | - 'id' => 'vat_class', |
|
604 | - 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
605 | - 'show_option_all' => false, |
|
606 | - 'show_option_none' => false, |
|
607 | - ) |
|
608 | - ); |
|
609 | - |
|
610 | - } |
|
611 | - |
|
612 | - // Filter by item type. |
|
613 | - $type = ''; |
|
614 | - if ( isset( $_GET['type'] ) ) { |
|
615 | - $type = $_GET['type']; |
|
616 | - } |
|
617 | - |
|
618 | - echo wpinv_html_select( |
|
619 | - array( |
|
620 | - 'options' => array_merge( |
|
621 | - array( |
|
622 | - '' => __( 'All item types', 'invoicing' ) |
|
623 | - ), |
|
624 | - wpinv_get_item_types() |
|
625 | - ), |
|
626 | - 'name' => 'type', |
|
627 | - 'id' => 'type', |
|
628 | - 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
629 | - 'show_option_all' => false, |
|
630 | - 'show_option_none' => false, |
|
631 | - ) |
|
632 | - ); |
|
633 | - |
|
634 | - } |
|
635 | - |
|
636 | - /** |
|
637 | - * Filters the item query. |
|
638 | - */ |
|
639 | - public static function filter_item_query( $query ) { |
|
640 | - |
|
641 | - // modify the query only if it admin and main query. |
|
642 | - if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
643 | - return $query; |
|
644 | - } |
|
645 | - |
|
646 | - // we want to modify the query for our items. |
|
647 | - if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){ |
|
648 | - return $query; |
|
649 | - } |
|
650 | - |
|
651 | - if ( empty( $query->query_vars['meta_query'] ) ) { |
|
652 | - $query->query_vars['meta_query'] = array(); |
|
653 | - } |
|
654 | - |
|
655 | - // Filter vat rule type |
|
587 | + // Sanitize selected vat rule. |
|
588 | + $vat_class = ''; |
|
589 | + $vat_classes = getpaid_get_tax_classes(); |
|
590 | + if ( isset( $_GET['vat_class'] ) ) { |
|
591 | + $vat_class = $_GET['vat_class']; |
|
592 | + } |
|
593 | + |
|
594 | + echo wpinv_html_select( |
|
595 | + array( |
|
596 | + 'options' => array_merge( |
|
597 | + array( |
|
598 | + '' => __( 'All VAT classes', 'invoicing' ) |
|
599 | + ), |
|
600 | + $vat_classes |
|
601 | + ), |
|
602 | + 'name' => 'vat_class', |
|
603 | + 'id' => 'vat_class', |
|
604 | + 'selected' => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '', |
|
605 | + 'show_option_all' => false, |
|
606 | + 'show_option_none' => false, |
|
607 | + ) |
|
608 | + ); |
|
609 | + |
|
610 | + } |
|
611 | + |
|
612 | + // Filter by item type. |
|
613 | + $type = ''; |
|
614 | + if ( isset( $_GET['type'] ) ) { |
|
615 | + $type = $_GET['type']; |
|
616 | + } |
|
617 | + |
|
618 | + echo wpinv_html_select( |
|
619 | + array( |
|
620 | + 'options' => array_merge( |
|
621 | + array( |
|
622 | + '' => __( 'All item types', 'invoicing' ) |
|
623 | + ), |
|
624 | + wpinv_get_item_types() |
|
625 | + ), |
|
626 | + 'name' => 'type', |
|
627 | + 'id' => 'type', |
|
628 | + 'selected' => in_array( $type, wpinv_item_types() ) ? $type : '', |
|
629 | + 'show_option_all' => false, |
|
630 | + 'show_option_none' => false, |
|
631 | + ) |
|
632 | + ); |
|
633 | + |
|
634 | + } |
|
635 | + |
|
636 | + /** |
|
637 | + * Filters the item query. |
|
638 | + */ |
|
639 | + public static function filter_item_query( $query ) { |
|
640 | + |
|
641 | + // modify the query only if it admin and main query. |
|
642 | + if ( ! ( is_admin() && $query->is_main_query() ) ){ |
|
643 | + return $query; |
|
644 | + } |
|
645 | + |
|
646 | + // we want to modify the query for our items. |
|
647 | + if ( empty( $query->query['post_type'] ) || 'wpi_item' != $query->query['post_type'] ){ |
|
648 | + return $query; |
|
649 | + } |
|
650 | + |
|
651 | + if ( empty( $query->query_vars['meta_query'] ) ) { |
|
652 | + $query->query_vars['meta_query'] = array(); |
|
653 | + } |
|
654 | + |
|
655 | + // Filter vat rule type |
|
656 | 656 | if ( ! empty( $_GET['vat_rule'] ) ) { |
657 | 657 | $query->query_vars['meta_query'][] = array( |
658 | 658 | 'key' => '_wpinv_vat_rule', |
@@ -677,94 +677,94 @@ discard block |
||
677 | 677 | 'value' => sanitize_text_field( $_GET['type'] ), |
678 | 678 | 'compare' => '=' |
679 | 679 | ); |
680 | - } |
|
681 | - |
|
682 | - } |
|
683 | - |
|
684 | - /** |
|
685 | - * Reorders items. |
|
686 | - */ |
|
687 | - public static function reorder_items( $vars ) { |
|
688 | - global $typenow; |
|
689 | - |
|
690 | - if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
691 | - return $vars; |
|
692 | - } |
|
693 | - |
|
694 | - // By item type. |
|
695 | - if ( 'type' == $vars['orderby'] ) { |
|
696 | - return array_merge( |
|
697 | - $vars, |
|
698 | - array( |
|
699 | - 'meta_key' => '_wpinv_type', |
|
700 | - 'orderby' => 'meta_value' |
|
701 | - ) |
|
702 | - ); |
|
703 | - } |
|
704 | - |
|
705 | - // By vat class. |
|
706 | - if ( 'vat_class' == $vars['orderby'] ) { |
|
707 | - return array_merge( |
|
708 | - $vars, |
|
709 | - array( |
|
710 | - 'meta_key' => '_wpinv_vat_class', |
|
711 | - 'orderby' => 'meta_value' |
|
712 | - ) |
|
713 | - ); |
|
714 | - } |
|
715 | - |
|
716 | - // By vat rule. |
|
717 | - if ( 'vat_rule' == $vars['orderby'] ) { |
|
718 | - return array_merge( |
|
719 | - $vars, |
|
720 | - array( |
|
721 | - 'meta_key' => '_wpinv_vat_rule', |
|
722 | - 'orderby' => 'meta_value' |
|
723 | - ) |
|
724 | - ); |
|
725 | - } |
|
726 | - |
|
727 | - // By price. |
|
728 | - if ( 'price' == $vars['orderby'] ) { |
|
729 | - return array_merge( |
|
730 | - $vars, |
|
731 | - array( |
|
732 | - 'meta_key' => '_wpinv_price', |
|
733 | - 'orderby' => 'meta_value_num' |
|
734 | - ) |
|
735 | - ); |
|
736 | - } |
|
737 | - |
|
738 | - return $vars; |
|
739 | - |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * Fired when deleting a post. |
|
744 | - */ |
|
745 | - public static function delete_post( $post_id ) { |
|
746 | - |
|
747 | - switch ( get_post_type( $post_id ) ) { |
|
748 | - |
|
749 | - case 'wpi_item' : |
|
750 | - do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
751 | - break; |
|
752 | - |
|
753 | - case 'wpi_payment_form' : |
|
754 | - do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
755 | - break; |
|
756 | - |
|
757 | - case 'wpi_discount' : |
|
758 | - do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
759 | - break; |
|
760 | - |
|
761 | - case 'wpi_invoice' : |
|
762 | - $invoice = new WPInv_Invoice( $post_id ); |
|
763 | - do_action( "getpaid_before_delete_invoice", $invoice ); |
|
764 | - $invoice->get_data_store()->delete_items( $invoice ); |
|
765 | - $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
766 | - break; |
|
767 | - } |
|
768 | - } |
|
680 | + } |
|
681 | + |
|
682 | + } |
|
683 | + |
|
684 | + /** |
|
685 | + * Reorders items. |
|
686 | + */ |
|
687 | + public static function reorder_items( $vars ) { |
|
688 | + global $typenow; |
|
689 | + |
|
690 | + if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) { |
|
691 | + return $vars; |
|
692 | + } |
|
693 | + |
|
694 | + // By item type. |
|
695 | + if ( 'type' == $vars['orderby'] ) { |
|
696 | + return array_merge( |
|
697 | + $vars, |
|
698 | + array( |
|
699 | + 'meta_key' => '_wpinv_type', |
|
700 | + 'orderby' => 'meta_value' |
|
701 | + ) |
|
702 | + ); |
|
703 | + } |
|
704 | + |
|
705 | + // By vat class. |
|
706 | + if ( 'vat_class' == $vars['orderby'] ) { |
|
707 | + return array_merge( |
|
708 | + $vars, |
|
709 | + array( |
|
710 | + 'meta_key' => '_wpinv_vat_class', |
|
711 | + 'orderby' => 'meta_value' |
|
712 | + ) |
|
713 | + ); |
|
714 | + } |
|
715 | + |
|
716 | + // By vat rule. |
|
717 | + if ( 'vat_rule' == $vars['orderby'] ) { |
|
718 | + return array_merge( |
|
719 | + $vars, |
|
720 | + array( |
|
721 | + 'meta_key' => '_wpinv_vat_rule', |
|
722 | + 'orderby' => 'meta_value' |
|
723 | + ) |
|
724 | + ); |
|
725 | + } |
|
726 | + |
|
727 | + // By price. |
|
728 | + if ( 'price' == $vars['orderby'] ) { |
|
729 | + return array_merge( |
|
730 | + $vars, |
|
731 | + array( |
|
732 | + 'meta_key' => '_wpinv_price', |
|
733 | + 'orderby' => 'meta_value_num' |
|
734 | + ) |
|
735 | + ); |
|
736 | + } |
|
737 | + |
|
738 | + return $vars; |
|
739 | + |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * Fired when deleting a post. |
|
744 | + */ |
|
745 | + public static function delete_post( $post_id ) { |
|
746 | + |
|
747 | + switch ( get_post_type( $post_id ) ) { |
|
748 | + |
|
749 | + case 'wpi_item' : |
|
750 | + do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) ); |
|
751 | + break; |
|
752 | + |
|
753 | + case 'wpi_payment_form' : |
|
754 | + do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) ); |
|
755 | + break; |
|
756 | + |
|
757 | + case 'wpi_discount' : |
|
758 | + do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) ); |
|
759 | + break; |
|
760 | + |
|
761 | + case 'wpi_invoice' : |
|
762 | + $invoice = new WPInv_Invoice( $post_id ); |
|
763 | + do_action( "getpaid_before_delete_invoice", $invoice ); |
|
764 | + $invoice->get_data_store()->delete_items( $invoice ); |
|
765 | + $invoice->get_data_store()->delete_special_fields( $invoice ); |
|
766 | + break; |
|
767 | + } |
|
768 | + } |
|
769 | 769 | |
770 | 770 | } |