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