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