Passed
Pull Request — master (#834)
by Kiran
06:01
created
includes/admin/class-getpaid-post-types-admin.php 1 patch
Indentation   +813 added lines, -813 removed lines patch added patch discarded remove patch
@@ -13,756 +13,756 @@  discard block
 block discarded – undo
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, '&mdash;', 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, '&mdash;', 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 '&mdash;';
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>&nbsp;<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>&nbsp;<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
-				$status_label = esc_html( $invoice->get_status_nicename() );
323
-
324
-				// If it is paid, show the gateway title.
325
-				if ( $invoice->is_paid() ) {
326
-					$gateway = esc_html( $invoice->get_gateway_title() );
327
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) );
328
-
329
-					echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" );
330
-				} else {
331
-					echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" );
332
-				}
333
-
334
-				// If it is not paid, display the overdue and view status.
335
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
336
-
337
-					// Invoice view status.
338
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
339
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>';
340
-					} else {
341
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>';
342
-					}
343
-
344
-					// Display the overview status.
345
-					if ( wpinv_get_option( 'overdue_active' ) ) {
346
-						$due_date = $invoice->get_due_date();
347
-						$fomatted = getpaid_format_date( $due_date );
348
-
349
-						if ( ! empty( $fomatted ) ) {
350
-							$date = wp_sprintf(
351
-								// translators: %s is the due date.
352
-								__( 'Due %s', 'invoicing' ),
353
-								$fomatted
354
-							);
355
-							echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" );
356
-						}
357
-					}
358
-				}
359
-
360
-				break;
361
-
362
-			case 'recurring':
363
-				if ( $invoice->is_recurring() ) {
364
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
365
-				} else {
366
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
367
-				}
368
-				break;
369
-
370
-			case 'number':
371
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
372
-				$invoice_number  = esc_html( $invoice->get_number() );
373
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
374
-
375
-				echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" );
376
-
377
-				do_action( 'getpaid_admin_table_invoice_number_column', $invoice );
378
-				break;
379
-
380
-			case 'customer':
381
-				$customer_name = $invoice->get_user_full_name();
382
-
383
-				if ( empty( $customer_name ) ) {
384
-					$customer_name = $invoice->get_email();
385
-				}
386
-
387
-				if ( ! empty( $customer_name ) ) {
388
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
389
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
390
-					echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" );
391
-				} else {
392
-					echo '<div>&mdash;</div>';
393
-				}
394
-
395
-				break;
396
-
397
-		}
398
-
399
-	}
400
-
401
-	/**
402
-	 * Displays invoice bulk actions.
403
-	 */
404
-	public static function invoice_bulk_actions( $actions ) {
405
-		$actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
406
-		return $actions;
407
-	}
408
-
409
-	/**
410
-	 * Processes invoice bulk actions.
411
-	 */
412
-	public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
413
-
414
-		if ( 'resend-invoice' === $action ) {
415
-			foreach ( $post_ids as $post_id ) {
416
-				getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
417
-			}
418
-		}
419
-
420
-		return $redirect_url;
421
-
422
-	}
423
-
424
-	/**
425
-	 * Returns an array of payment forms table columns.
426
-	 */
427
-	public static function payment_form_columns( $columns ) {
428
-
429
-		$columns = array(
430
-			'cb'        => $columns['cb'],
431
-			'title'     => __( 'Name', 'invoicing' ),
432
-			'shortcode' => __( 'Shortcode', 'invoicing' ),
433
-			'earnings'  => __( 'Revenue', 'invoicing' ),
434
-			'refunds'   => __( 'Refunded', 'invoicing' ),
435
-			'items'     => __( 'Items', 'invoicing' ),
436
-			'date'      => __( 'Date', 'invoicing' ),
437
-		);
438
-
439
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
440
-
441
-	}
442
-
443
-	/**
444
-	 * Displays payment form table columns.
445
-	 */
446
-	public static function display_payment_form_columns( $column_name, $post_id ) {
447
-
448
-		// Retrieve the payment form.
449
-		$form = new GetPaid_Payment_Form( $post_id );
450
-
451
-		switch ( $column_name ) {
452
-
453
-			case 'earnings':
454
-				echo wp_kses_post( wpinv_price( $form->get_earned() ) );
455
-				break;
456
-
457
-			case 'refunds':
458
-				echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
459
-				break;
460
-
461
-			case 'refunds':
462
-				echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
463
-				break;
464
-
465
-			case 'shortcode':
466
-				if ( $form->is_default() ) {
467
-					echo '&mdash;';
468
-				} else {
469
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
470
-				}
471
-
472
-				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, '&mdash;', 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, '&mdash;', 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 '&mdash;';
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>&nbsp;<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>&nbsp;<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
+                $status_label = esc_html( $invoice->get_status_nicename() );
323
+
324
+                // If it is paid, show the gateway title.
325
+                if ( $invoice->is_paid() ) {
326
+                    $gateway = esc_html( $invoice->get_gateway_title() );
327
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), esc_html( $gateway ) );
328
+
329
+                    echo wp_kses_post( "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>" );
330
+                } else {
331
+                    echo wp_kses_post( "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>" );
332
+                }
333
+
334
+                // If it is not paid, display the overdue and view status.
335
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
336
+
337
+                    // Invoice view status.
338
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
339
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__( 'Viewed by Customer', 'invoicing' ) . '"></i>';
340
+                    } else {
341
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__( 'Not Viewed by Customer', 'invoicing' ) . '"></i>';
342
+                    }
343
+
344
+                    // Display the overview status.
345
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
346
+                        $due_date = $invoice->get_due_date();
347
+                        $fomatted = getpaid_format_date( $due_date );
348
+
349
+                        if ( ! empty( $fomatted ) ) {
350
+                            $date = wp_sprintf(
351
+                                // translators: %s is the due date.
352
+                                __( 'Due %s', 'invoicing' ),
353
+                                $fomatted
354
+                            );
355
+                            echo wp_kses_post( "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>" );
356
+                        }
357
+                    }
358
+                }
359
+
360
+                break;
361
+
362
+            case 'recurring':
363
+                if ( $invoice->is_recurring() ) {
364
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
365
+                } else {
366
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
367
+                }
368
+                break;
369
+
370
+            case 'number':
371
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
372
+                $invoice_number  = esc_html( $invoice->get_number() );
373
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
374
+
375
+                echo wp_kses_post( "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>" );
376
+
377
+                do_action( 'getpaid_admin_table_invoice_number_column', $invoice );
378
+                break;
379
+
380
+            case 'customer':
381
+                $customer_name = $invoice->get_user_full_name();
382
+
383
+                if ( empty( $customer_name ) ) {
384
+                    $customer_name = $invoice->get_email();
385
+                }
386
+
387
+                if ( ! empty( $customer_name ) ) {
388
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
389
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
390
+                    echo wp_kses_post( "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>" );
391
+                } else {
392
+                    echo '<div>&mdash;</div>';
393
+                }
394
+
395
+                break;
473 396
 
474
-			case 'items':
475
-				$items = $form->get_items();
476
-
477
-				if ( $form->is_default() || empty( $items ) ) {
478
-					echo '&mdash;';
479
-					return;
480
-				}
481
-
482
-				$_items = array();
483
-
484
-				foreach ( $items as $item ) {
485
-					$url = $item->get_edit_url();
486
-
487
-					if ( empty( $url ) ) {
488
-						$_items[] = esc_html( $item->get_name() );
489
-					} else {
490
-						$_items[] = sprintf(
491
-							'<a href="%s">%s</a>',
492
-							esc_url( $url ),
493
-							esc_html( $item->get_name() )
494
-						);
495
-					}
397
+        }
398
+
399
+    }
400
+
401
+    /**
402
+     * Displays invoice bulk actions.
403
+     */
404
+    public static function invoice_bulk_actions( $actions ) {
405
+        $actions['resend-invoice'] = __( 'Send to Customer', 'invoicing' );
406
+        return $actions;
407
+    }
408
+
409
+    /**
410
+     * Processes invoice bulk actions.
411
+     */
412
+    public static function handle_invoice_bulk_actions( $redirect_url, $action, $post_ids ) {
413
+
414
+        if ( 'resend-invoice' === $action ) {
415
+            foreach ( $post_ids as $post_id ) {
416
+                getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $post_id ), true );
417
+            }
418
+        }
419
+
420
+        return $redirect_url;
421
+
422
+    }
423
+
424
+    /**
425
+     * Returns an array of payment forms table columns.
426
+     */
427
+    public static function payment_form_columns( $columns ) {
428
+
429
+        $columns = array(
430
+            'cb'        => $columns['cb'],
431
+            'title'     => __( 'Name', 'invoicing' ),
432
+            'shortcode' => __( 'Shortcode', 'invoicing' ),
433
+            'earnings'  => __( 'Revenue', 'invoicing' ),
434
+            'refunds'   => __( 'Refunded', 'invoicing' ),
435
+            'items'     => __( 'Items', 'invoicing' ),
436
+            'date'      => __( 'Date', 'invoicing' ),
437
+        );
438
+
439
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
440
+
441
+    }
442
+
443
+    /**
444
+     * Displays payment form table columns.
445
+     */
446
+    public static function display_payment_form_columns( $column_name, $post_id ) {
447
+
448
+        // Retrieve the payment form.
449
+        $form = new GetPaid_Payment_Form( $post_id );
450
+
451
+        switch ( $column_name ) {
452
+
453
+            case 'earnings':
454
+                echo wp_kses_post( wpinv_price( $form->get_earned() ) );
455
+                break;
456
+
457
+            case 'refunds':
458
+                echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
459
+                break;
460
+
461
+            case 'refunds':
462
+                echo wp_kses_post( wpinv_price( $form->get_refunded() ) );
463
+                break;
464
+
465
+            case 'shortcode':
466
+                if ( $form->is_default() ) {
467
+                    echo '&mdash;';
468
+                } else {
469
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
470
+                }
471
+
472
+                break;
473
+
474
+            case 'items':
475
+                $items = $form->get_items();
476
+
477
+                if ( $form->is_default() || empty( $items ) ) {
478
+                    echo '&mdash;';
479
+                    return;
480
+                }
481
+
482
+                $_items = array();
483
+
484
+                foreach ( $items as $item ) {
485
+                    $url = $item->get_edit_url();
486
+
487
+                    if ( empty( $url ) ) {
488
+                        $_items[] = esc_html( $item->get_name() );
489
+                    } else {
490
+                        $_items[] = sprintf(
491
+                            '<a href="%s">%s</a>',
492
+                            esc_url( $url ),
493
+                            esc_html( $item->get_name() )
494
+                        );
495
+                    }
496 496
 }
497 497
 
498
-				echo wp_kses_post( implode( '<br>', $_items ) );
498
+                echo wp_kses_post( implode( '<br>', $_items ) );
499
+
500
+                break;
501
+
502
+        }
503
+
504
+    }
505
+
506
+    /**
507
+     * Filters post states.
508
+     */
509
+    public static function filter_payment_form_state( $post_states, $post ) {
510
+
511
+        if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) {
512
+            $post_states['default_form'] = __( 'Default Payment Form', 'invoicing' );
513
+        }
514
+
515
+        return $post_states;
516
+
517
+    }
518
+
519
+    /**
520
+     * Returns an array of coupon table columns.
521
+     */
522
+    public static function discount_columns( $columns ) {
523
+
524
+        $columns = array(
525
+            'cb'          => $columns['cb'],
526
+            'title'       => __( 'Name', 'invoicing' ),
527
+            'code'        => __( 'Code', 'invoicing' ),
528
+            'amount'      => __( 'Amount', 'invoicing' ),
529
+            'usage'       => __( 'Usage / Limit', 'invoicing' ),
530
+            'start_date'  => __( 'Start Date', 'invoicing' ),
531
+            'expiry_date' => __( 'Expiry Date', 'invoicing' ),
532
+        );
533
+
534
+        return apply_filters( 'wpi_discount_table_columns', $columns );
535
+    }
499 536
 
500
-				break;
537
+    /**
538
+     * Filters post states.
539
+     */
540
+    public static function filter_discount_state( $post_states, $post ) {
501 541
 
502
-		}
542
+        if ( 'wpi_discount' === $post->post_type ) {
503 543
 
504
-	}
544
+            $discount = new WPInv_Discount( $post );
505 545
 
506
-	/**
507
-	 * Filters post states.
508
-	 */
509
-	public static function filter_payment_form_state( $post_states, $post ) {
546
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
510 547
 
511
-		if ( 'wpi_payment_form' === $post->post_type && wpinv_get_default_payment_form() === $post->ID ) {
512
-			$post_states['default_form'] = __( 'Default Payment Form', 'invoicing' );
513
-		}
548
+            if ( 'publish' !== $status ) {
549
+                return array(
550
+                    'discount_status' => wpinv_discount_status( $status ),
551
+                );
552
+            }
553
+
554
+            return array();
555
+
556
+        }
557
+
558
+        return $post_states;
514 559
 
515
-		return $post_states;
560
+    }
516 561
 
517
-	}
562
+    /**
563
+     * Returns an array of items table columns.
564
+     */
565
+    public static function item_columns( $columns ) {
566
+
567
+        $columns = array(
568
+            'cb'        => $columns['cb'],
569
+            'title'     => __( 'Name', 'invoicing' ),
570
+            'price'     => __( 'Price', 'invoicing' ),
571
+            'vat_rule'  => __( 'Tax Rule', 'invoicing' ),
572
+            'vat_class' => __( 'Tax Class', 'invoicing' ),
573
+            'type'      => __( 'Type', 'invoicing' ),
574
+            'shortcode' => __( 'Shortcode', 'invoicing' ),
575
+        );
576
+
577
+        if ( ! wpinv_use_taxes() ) {
578
+            unset( $columns['vat_rule'] );
579
+            unset( $columns['vat_class'] );
580
+        }
518 581
 
519
-	/**
520
-	 * Returns an array of coupon table columns.
521
-	 */
522
-	public static function discount_columns( $columns ) {
582
+        return apply_filters( 'wpi_item_table_columns', $columns );
583
+    }
523 584
 
524
-		$columns = array(
525
-			'cb'          => $columns['cb'],
526
-			'title'       => __( 'Name', 'invoicing' ),
527
-			'code'        => __( 'Code', 'invoicing' ),
528
-			'amount'      => __( 'Amount', 'invoicing' ),
529
-			'usage'       => __( 'Usage / Limit', 'invoicing' ),
530
-			'start_date'  => __( 'Start Date', 'invoicing' ),
531
-			'expiry_date' => __( 'Expiry Date', 'invoicing' ),
532
-		);
585
+    /**
586
+     * Returns an array of sortable items table columns.
587
+     */
588
+    public static function sortable_item_columns( $columns ) {
589
+
590
+        return array_merge(
591
+            $columns,
592
+            array(
593
+                'price'     => 'price',
594
+                'vat_rule'  => 'vat_rule',
595
+                'vat_class' => 'vat_class',
596
+                'type'      => 'type',
597
+            )
598
+        );
533 599
 
534
-		return apply_filters( 'wpi_discount_table_columns', $columns );
535
-	}
600
+    }
536 601
 
537
-	/**
538
-	 * Filters post states.
539
-	 */
540
-	public static function filter_discount_state( $post_states, $post ) {
602
+    /**
603
+     * Displays items table columns.
604
+     */
605
+    public static function display_item_columns( $column_name, $post_id ) {
541 606
 
542
-		if ( 'wpi_discount' === $post->post_type ) {
607
+        $item = new WPInv_Item( $post_id );
543 608
 
544
-			$discount = new WPInv_Discount( $post );
609
+        switch ( $column_name ) {
545 610
 
546
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
611
+            case 'price':
612
+                if ( ! $item->is_recurring() ) {
613
+                    echo wp_kses_post( $item->get_the_price() );
614
+                    break;
615
+                }
547 616
 
548
-			if ( 'publish' !== $status ) {
549
-				return array(
550
-					'discount_status' => wpinv_discount_status( $status ),
551
-				);
552
-			}
617
+                $price = wp_sprintf(
618
+                    __( '%1$s / %2$s', 'invoicing' ),
619
+                    $item->get_the_price(),
620
+                    getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
621
+                );
553 622
 
554
-			return array();
623
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
624
+                    echo wp_kses_post( $price );
625
+                    break;
626
+                }
555 627
 
556
-		}
628
+                echo wp_kses_post( $item->get_the_initial_price() );
557 629
 
558
-		return $post_states;
630
+                echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>';
631
+                break;
559 632
 
560
-	}
633
+            case 'vat_rule':
634
+                echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) );
635
+                break;
561 636
 
562
-	/**
563
-	 * Returns an array of items table columns.
564
-	 */
565
-	public static function item_columns( $columns ) {
637
+            case 'vat_class':
638
+                echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) );
639
+                break;
566 640
 
567
-		$columns = array(
568
-			'cb'        => $columns['cb'],
569
-			'title'     => __( 'Name', 'invoicing' ),
570
-			'price'     => __( 'Price', 'invoicing' ),
571
-			'vat_rule'  => __( 'Tax Rule', 'invoicing' ),
572
-			'vat_class' => __( 'Tax Class', 'invoicing' ),
573
-			'type'      => __( 'Type', 'invoicing' ),
574
-			'shortcode' => __( 'Shortcode', 'invoicing' ),
575
-		);
641
+            case 'shortcode':
642
+                if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) {
643
+                    echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
644
+                } else {
645
+                    echo '&mdash;';
646
+                }
576 647
 
577
-		if ( ! wpinv_use_taxes() ) {
578
-			unset( $columns['vat_rule'] );
579
-			unset( $columns['vat_class'] );
580
-		}
648
+                break;
581 649
 
582
-		return apply_filters( 'wpi_item_table_columns', $columns );
583
-	}
650
+            case 'type':
651
+                echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' );
652
+                break;
584 653
 
585
-	/**
586
-	 * Returns an array of sortable items table columns.
587
-	 */
588
-	public static function sortable_item_columns( $columns ) {
589
-
590
-		return array_merge(
591
-			$columns,
592
-			array(
593
-				'price'     => 'price',
594
-				'vat_rule'  => 'vat_rule',
595
-				'vat_class' => 'vat_class',
596
-				'type'      => 'type',
597
-			)
598
-		);
599
-
600
-	}
601
-
602
-	/**
603
-	 * Displays items table columns.
604
-	 */
605
-	public static function display_item_columns( $column_name, $post_id ) {
606
-
607
-		$item = new WPInv_Item( $post_id );
608
-
609
-		switch ( $column_name ) {
610
-
611
-			case 'price':
612
-				if ( ! $item->is_recurring() ) {
613
-					echo wp_kses_post( $item->get_the_price() );
614
-					break;
615
-				}
616
-
617
-				$price = wp_sprintf(
618
-					__( '%1$s / %2$s', 'invoicing' ),
619
-					$item->get_the_price(),
620
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
621
-				);
622
-
623
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
624
-					echo wp_kses_post( $price );
625
-					break;
626
-				}
627
-
628
-				echo wp_kses_post( $item->get_the_initial_price() );
629
-
630
-				echo '<span class="meta">' . wp_sprintf( esc_html__( 'then %s', 'invoicing' ), wp_kses_post( $price ) ) . '</span>';
631
-				break;
632
-
633
-			case 'vat_rule':
634
-				echo wp_kses_post( getpaid_get_tax_rule_label( $item->get_vat_rule() ) );
635
-				break;
636
-
637
-			case 'vat_class':
638
-				echo wp_kses_post( getpaid_get_tax_class_label( $item->get_vat_class() ) );
639
-				break;
640
-
641
-			case 'shortcode':
642
-				if ( $item->is_type( array( '', 'fee', 'custom' ) ) ) {
643
-					echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
644
-				} else {
645
-					echo '&mdash;';
646
-				}
647
-
648
-				break;
649
-
650
-			case 'type':
651
-				echo wp_kses_post( wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>' );
652
-				break;
653
-
654
-		}
655
-
656
-	}
657
-
658
-	/**
659
-	 * Lets users filter items using taxes.
660
-	 */
661
-	public static function add_item_filters( $post_type ) {
662
-
663
-		// Abort if we're not dealing with items.
664
-		if ( 'wpi_item' !== $post_type ) {
665
-			return;
666
-		}
667
-
668
-		// Filter by vat rules.
669
-		if ( wpinv_use_taxes() ) {
670
-
671
-			// Sanitize selected vat rule.
672
-			$vat_rule   = '';
673
-			$vat_rules  = getpaid_get_tax_rules();
674
-			if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
675
-				$vat_rule   = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
676
-			}
677
-
678
-			// Filter by VAT rule.
679
-			wpinv_html_select(
680
-				array(
681
-					'options'          => array_merge(
682
-						array(
683
-							'' => __( 'All Tax Rules', 'invoicing' ),
684
-						),
685
-						$vat_rules
686
-					),
687
-					'name'             => 'vat_rule',
688
-					'id'               => 'vat_rule',
689
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '',
690
-					'show_option_all'  => false,
691
-					'show_option_none' => false,
692
-				)
693
-			);
694
-
695
-			// Filter by VAT class.
696
-
697
-			// Sanitize selected vat rule.
698
-			$vat_class   = '';
699
-			$vat_classes = getpaid_get_tax_classes();
700
-			if ( isset( $_GET['vat_class'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
701
-				$vat_class   = sanitize_text_field( $_GET['vat_class'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
702
-			}
703
-
704
-			wpinv_html_select(
705
-				array(
706
-					'options'          => array_merge(
707
-						array(
708
-							'' => __( 'All Tax Classes', 'invoicing' ),
709
-						),
710
-						$vat_classes
711
-					),
712
-					'name'             => 'vat_class',
713
-					'id'               => 'vat_class',
714
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '',
715
-					'show_option_all'  => false,
716
-					'show_option_none' => false,
717
-				)
718
-			);
719
-
720
-		}
721
-
722
-		// Filter by item type.
723
-		$type   = '';
724
-		if ( isset( $_GET['type'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
725
-			$type   = sanitize_text_field( $_GET['type'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
726
-		}
727
-
728
-		wpinv_html_select(
729
-			array(
730
-				'options'          => array_merge(
731
-					array(
732
-						'' => __( 'All item types', 'invoicing' ),
733
-					),
734
-					wpinv_get_item_types()
735
-				),
736
-				'name'             => 'type',
737
-				'id'               => 'type',
738
-				'selected'         => in_array( $type, wpinv_item_types(), true ) ? $type : '',
739
-				'show_option_all'  => false,
740
-				'show_option_none' => false,
741
-			)
742
-		);
743
-
744
-	}
745
-
746
-	/**
747
-	 * Filters the item query.
748
-	 */
749
-	public static function filter_item_query( $query ) {
750
-
751
-		// modify the query only if it admin and main query.
752
-		if ( ! ( is_admin() && $query->is_main_query() ) ) {
753
-			return $query;
754
-		}
755
-
756
-		// we want to modify the query for our items.
757
-		if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) {
758
-			return $query;
759
-		}
760
-
761
-		if ( empty( $query->query_vars['meta_query'] ) ) {
762
-			$query->query_vars['meta_query'] = array();
763
-		}
764
-
765
-		// Filter vat rule type
654
+        }
655
+
656
+    }
657
+
658
+    /**
659
+     * Lets users filter items using taxes.
660
+     */
661
+    public static function add_item_filters( $post_type ) {
662
+
663
+        // Abort if we're not dealing with items.
664
+        if ( 'wpi_item' !== $post_type ) {
665
+            return;
666
+        }
667
+
668
+        // Filter by vat rules.
669
+        if ( wpinv_use_taxes() ) {
670
+
671
+            // Sanitize selected vat rule.
672
+            $vat_rule   = '';
673
+            $vat_rules  = getpaid_get_tax_rules();
674
+            if ( isset( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
675
+                $vat_rule   = sanitize_text_field( $_GET['vat_rule'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
676
+            }
677
+
678
+            // Filter by VAT rule.
679
+            wpinv_html_select(
680
+                array(
681
+                    'options'          => array_merge(
682
+                        array(
683
+                            '' => __( 'All Tax Rules', 'invoicing' ),
684
+                        ),
685
+                        $vat_rules
686
+                    ),
687
+                    'name'             => 'vat_rule',
688
+                    'id'               => 'vat_rule',
689
+                    'selected'         => in_array( $vat_rule, array_keys( $vat_rules ), true ) ? $vat_rule : '',
690
+                    'show_option_all'  => false,
691
+                    'show_option_none' => false,
692
+                )
693
+            );
694
+
695
+            // Filter by VAT class.
696
+
697
+            // Sanitize selected vat rule.
698
+            $vat_class   = '';
699
+            $vat_classes = getpaid_get_tax_classes();
700
+            if ( isset( $_GET['vat_class'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
701
+                $vat_class   = sanitize_text_field( $_GET['vat_class'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
702
+            }
703
+
704
+            wpinv_html_select(
705
+                array(
706
+                    'options'          => array_merge(
707
+                        array(
708
+                            '' => __( 'All Tax Classes', 'invoicing' ),
709
+                        ),
710
+                        $vat_classes
711
+                    ),
712
+                    'name'             => 'vat_class',
713
+                    'id'               => 'vat_class',
714
+                    'selected'         => in_array( $vat_class, array_keys( $vat_classes ), true ) ? $vat_class : '',
715
+                    'show_option_all'  => false,
716
+                    'show_option_none' => false,
717
+                )
718
+            );
719
+
720
+        }
721
+
722
+        // Filter by item type.
723
+        $type   = '';
724
+        if ( isset( $_GET['type'] ) ) {  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
725
+            $type   = sanitize_text_field( $_GET['type'] );  // phpcs:ignore WordPress.Security.NonceVerification.Recommended
726
+        }
727
+
728
+        wpinv_html_select(
729
+            array(
730
+                'options'          => array_merge(
731
+                    array(
732
+                        '' => __( 'All item types', 'invoicing' ),
733
+                    ),
734
+                    wpinv_get_item_types()
735
+                ),
736
+                'name'             => 'type',
737
+                'id'               => 'type',
738
+                'selected'         => in_array( $type, wpinv_item_types(), true ) ? $type : '',
739
+                'show_option_all'  => false,
740
+                'show_option_none' => false,
741
+            )
742
+        );
743
+
744
+    }
745
+
746
+    /**
747
+     * Filters the item query.
748
+     */
749
+    public static function filter_item_query( $query ) {
750
+
751
+        // modify the query only if it admin and main query.
752
+        if ( ! ( is_admin() && $query->is_main_query() ) ) {
753
+            return $query;
754
+        }
755
+
756
+        // we want to modify the query for our items.
757
+        if ( empty( $query->query['post_type'] ) || 'wpi_item' !== $query->query['post_type'] ) {
758
+            return $query;
759
+        }
760
+
761
+        if ( empty( $query->query_vars['meta_query'] ) ) {
762
+            $query->query_vars['meta_query'] = array();
763
+        }
764
+
765
+        // Filter vat rule type
766 766
         if ( ! empty( $_GET['vat_rule'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
767 767
             $query->query_vars['meta_query'][] = array(
768 768
                 'key'     => '_wpinv_vat_rule',
@@ -787,101 +787,101 @@  discard block
 block discarded – undo
787 787
                 'value'   => sanitize_text_field( $_GET['type'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
788 788
                 'compare' => '=',
789 789
             );
790
-		}
791
-
792
-		$query->query_vars['meta_query'][] = array(
793
-			'key'     => '_wpinv_one_time',
794
-			'compare' => 'NOT EXISTS',
795
-		);
796
-	}
797
-
798
-	/**
799
-	 * Reorders items.
800
-	 */
801
-	public static function reorder_items( $vars ) {
802
-		global $typenow;
803
-
804
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
805
-			return $vars;
806
-		}
807
-
808
-		// By item type.
809
-		if ( 'type' === $vars['orderby'] ) {
810
-			return array_merge(
811
-				$vars,
812
-				array(
813
-					'meta_key' => '_wpinv_type',
814
-					'orderby'  => 'meta_value',
815
-				)
816
-			);
817
-		}
818
-
819
-		// By vat class.
820
-		if ( 'vat_class' === $vars['orderby'] ) {
821
-			return array_merge(
822
-				$vars,
823
-				array(
824
-					'meta_key' => '_wpinv_vat_class',
825
-					'orderby'  => 'meta_value',
826
-				)
827
-			);
828
-		}
829
-
830
-		// By vat rule.
831
-		if ( 'vat_rule' === $vars['orderby'] ) {
832
-			return array_merge(
833
-				$vars,
834
-				array(
835
-					'meta_key' => '_wpinv_vat_rule',
836
-					'orderby'  => 'meta_value',
837
-				)
838
-			);
839
-		}
840
-
841
-		// By price.
842
-		if ( 'price' === $vars['orderby'] ) {
843
-			return array_merge(
844
-				$vars,
845
-				array(
846
-					'meta_key' => '_wpinv_price',
847
-					'orderby'  => 'meta_value_num',
848
-				)
849
-			);
850
-		}
851
-
852
-		return $vars;
853
-
854
-	}
855
-
856
-	/**
857
-	 * Fired when deleting a post.
858
-	 */
859
-	public static function delete_post( $post_id ) {
860
-
861
-		switch ( get_post_type( $post_id ) ) {
862
-
863
-			case 'wpi_item':
864
-				do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) );
865
-				break;
866
-
867
-			case 'wpi_payment_form':
868
-				do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) );
869
-				break;
870
-
871
-			case 'wpi_discount':
872
-				do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) );
873
-				break;
874
-
875
-			case 'wpi_invoice':
876
-				$invoice = new WPInv_Invoice( $post_id );
877
-				do_action( 'getpaid_before_delete_invoice', $invoice );
878
-				$invoice->get_data_store()->delete_items( $invoice );
879
-				$invoice->get_data_store()->delete_special_fields( $invoice );
880
-				break;
881
-		}
882
-	}
883
-
884
-	/**
790
+        }
791
+
792
+        $query->query_vars['meta_query'][] = array(
793
+            'key'     => '_wpinv_one_time',
794
+            'compare' => 'NOT EXISTS',
795
+        );
796
+    }
797
+
798
+    /**
799
+     * Reorders items.
800
+     */
801
+    public static function reorder_items( $vars ) {
802
+        global $typenow;
803
+
804
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
805
+            return $vars;
806
+        }
807
+
808
+        // By item type.
809
+        if ( 'type' === $vars['orderby'] ) {
810
+            return array_merge(
811
+                $vars,
812
+                array(
813
+                    'meta_key' => '_wpinv_type',
814
+                    'orderby'  => 'meta_value',
815
+                )
816
+            );
817
+        }
818
+
819
+        // By vat class.
820
+        if ( 'vat_class' === $vars['orderby'] ) {
821
+            return array_merge(
822
+                $vars,
823
+                array(
824
+                    'meta_key' => '_wpinv_vat_class',
825
+                    'orderby'  => 'meta_value',
826
+                )
827
+            );
828
+        }
829
+
830
+        // By vat rule.
831
+        if ( 'vat_rule' === $vars['orderby'] ) {
832
+            return array_merge(
833
+                $vars,
834
+                array(
835
+                    'meta_key' => '_wpinv_vat_rule',
836
+                    'orderby'  => 'meta_value',
837
+                )
838
+            );
839
+        }
840
+
841
+        // By price.
842
+        if ( 'price' === $vars['orderby'] ) {
843
+            return array_merge(
844
+                $vars,
845
+                array(
846
+                    'meta_key' => '_wpinv_price',
847
+                    'orderby'  => 'meta_value_num',
848
+                )
849
+            );
850
+        }
851
+
852
+        return $vars;
853
+
854
+    }
855
+
856
+    /**
857
+     * Fired when deleting a post.
858
+     */
859
+    public static function delete_post( $post_id ) {
860
+
861
+        switch ( get_post_type( $post_id ) ) {
862
+
863
+            case 'wpi_item':
864
+                do_action( 'getpaid_before_delete_item', new WPInv_Item( $post_id ) );
865
+                break;
866
+
867
+            case 'wpi_payment_form':
868
+                do_action( 'getpaid_before_delete_payment_form', new GetPaid_Payment_Form( $post_id ) );
869
+                break;
870
+
871
+            case 'wpi_discount':
872
+                do_action( 'getpaid_before_delete_discount', new WPInv_Discount( $post_id ) );
873
+                break;
874
+
875
+            case 'wpi_invoice':
876
+                $invoice = new WPInv_Invoice( $post_id );
877
+                do_action( 'getpaid_before_delete_invoice', $invoice );
878
+                $invoice->get_data_store()->delete_items( $invoice );
879
+                $invoice->get_data_store()->delete_special_fields( $invoice );
880
+                break;
881
+        }
882
+    }
883
+
884
+    /**
885 885
      * Add a post display state for special GetPaid pages in the page list table.
886 886
      *
887 887
      * @param array   $post_states An array of post display states.
@@ -895,21 +895,21 @@  discard block
 block discarded – undo
895 895
             $post_states['getpaid_success_page'] = __( 'GetPaid Receipt Page', 'invoicing' );
896 896
         }
897 897
 
898
-		foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
898
+        foreach ( getpaid_get_invoice_post_types() as $post_type => $label ) {
899 899
 
900
-			if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
901
-				$post_states[ "getpaid_{$post_type}_history_page" ] = sprintf(
902
-					__( 'GetPaid %s History Page', 'invoicing' ),
903
-					$label
904
-				);
905
-			}
900
+            if ( wpinv_get_option( "{$post_type}_history_page", 0 ) == $post->ID ) {
901
+                $post_states[ "getpaid_{$post_type}_history_page" ] = sprintf(
902
+                    __( 'GetPaid %s History Page', 'invoicing' ),
903
+                    $label
904
+                );
905
+            }
906 906
 }
907 907
 
908
-		if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
908
+        if ( wpinv_get_option( 'invoice_subscription_page', 0 ) == $post->ID ) {
909 909
             $post_states['getpaid_invoice_subscription_page'] = __( 'GetPaid Subscription Page', 'invoicing' );
910 910
         }
911 911
 
912
-		if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
912
+        if ( wpinv_get_option( 'checkout_page', 0 ) == $post->ID ) {
913 913
             $post_states['getpaid_checkout_page'] = __( 'GetPaid Checkout Page', 'invoicing' );
914 914
         }
915 915
 
Please login to merge, or discard this patch.