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