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