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