Passed
Push — master ( 3b6696...7383db )
by Brian
04:13
created
includes/admin/class-wpinv-subscriptions-list-table.php 2 patches
Indentation   +383 added lines, -383 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 if ( ! defined( 'ABSPATH' ) ) exit;
7 7
 
8 8
 if ( ! class_exists( 'WP_List_Table' ) ) {
9
-	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
9
+    include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10 10
 }
11 11
 
12 12
 /**
@@ -14,387 +14,387 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Subscriptions_List_Table extends WP_List_Table {
16 16
 
17
-	/**
18
-	 * URL of this page
19
-	 *
20
-	 * @var   string
21
-	 * @since 1.0.19
22
-	 */
23
-	public $base_url;
24
-
25
-	/**
26
-	 * Query
27
-	 *
28
-	 * @var   GetPaid_Subscriptions_Query
29
-	 * @since 1.0.19
30
-	 */
31
-	public $query;
32
-
33
-	/**
34
-	 * Total subscriptions
35
-	 *
36
-	 * @var   string
37
-	 * @since 1.0.0
38
-	 */
39
-	public $total_count;
40
-
41
-	/**
42
-	 * Current status subscriptions
43
-	 *
44
-	 * @var   string
45
-	 * @since 1.0.0
46
-	 */
47
-	public $current_total_count;
48
-
49
-	/**
50
-	 * Status counts
51
-	 *
52
-	 * @var   array
53
-	 * @since 1.0.19
54
-	 */
55
-	public $status_counts;
56
-
57
-	/**
58
-	 * Number of results to show per page
59
-	 *
60
-	 * @var   int
61
-	 * @since 1.0.0
62
-	 */
63
-	public $per_page = 10;
64
-
65
-	/**
66
-	 *  Constructor function.
67
-	 */
68
-	public function __construct() {
69
-
70
-		parent::__construct(
71
-			array(
72
-				'singular' => 'subscription',
73
-				'plural'   => 'subscriptions',
74
-			)
75
-		);
76
-
77
-		$this->process_bulk_action();
78
-
79
-		$this->prepare_query();
80
-
81
-		$this->base_url = remove_query_arg( 'status' );
82
-
83
-	}
84
-
85
-	/**
86
-	 *  Prepares the display query
87
-	 */
88
-	public function prepare_query() {
89
-
90
-		// Prepare query args.
91
-		$query = array(
92
-			'number'  => $this->per_page,
93
-			'paged'   => $this->get_paged(),
94
-			'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
-			'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
-			'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
-		);
98
-
99
-		// Prepare class properties.
100
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
101
-		$this->total_count         = $this->query->get_total();
102
-		$this->current_total_count = $this->query->get_total();
103
-		$this->items               = $this->query->get_results();
104
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
-
106
-		if ( 'all' != $query['status'] ) {
107
-			unset( $query['status'] );
108
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
-		}
110
-
111
-	}
112
-
113
-	/**
114
-	 * Gets the list of views available on this table.
115
-	 *
116
-	 * The format is an associative array:
117
-	 * - `'id' => 'link'`
118
-	 *
119
-	 * @since 1.0.0
120
-	 *
121
-	 * @return array
122
-	 */
123
-	public function get_views() {
124
-
125
-		$current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
-		$views    = array(
127
-
128
-			'all' => sprintf(
129
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
-				$current === 'all' ? ' class="current"' : '',
132
-				__('All','invoicing' ),
133
-				$this->total_count
134
-			)
135
-
136
-		);
137
-
138
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
-
140
-			$views[ $status ] = sprintf(
141
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
-				$current === $status ? ' class="current"' : '',
144
-				sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
-				$count
146
-			);
147
-
148
-		}
149
-
150
-		return $views;
151
-
152
-	}
153
-
154
-	/**
155
-	 * Render most columns
156
-	 *
157
-	 * @access      private
158
-	 * @since       1.0.0
159
-	 * @return      string
160
-	 */
161
-	public function column_default( $item, $column_name ) {
162
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
-	}
164
-
165
-	/**
166
-	 * This is how checkbox column renders.
167
-	 *
168
-	 * @param WPInv_Subscription $item
169
-	 * @return string
170
-	 */
171
-	public function column_cb( $item ) {
172
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
-	}
174
-
175
-	/**
176
-	 * Status column
177
-	 *
178
-	 * @param WPInv_Subscription $item
179
-	 * @since       1.0.0
180
-	 * @return      string
181
-	 */
182
-	public function column_status( $item ) {
183
-		return $item->get_status_label_html();
184
-	}
185
-
186
-	/**
187
-	 * Subscription column
188
-	 *
189
-	 * @param WPInv_Subscription $item
190
-	 * @since       1.0.0
191
-	 * @return      string
192
-	 */
193
-	public function column_subscription( $item ) {
194
-
195
-		$username = __( '(Missing User)', 'invoicing' );
196
-
197
-		$user = get_userdata( $item->get_customer_id() );
198
-		if ( $user ) {
199
-
200
-			$username = sprintf(
201
-				'<a href="user-edit.php?user_id=%s">%s</a>',
202
-				absint( $user->ID ),
203
-				! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
-			);
205
-
206
-		}
207
-
208
-		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
-		$column_content = sprintf(
210
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
-			$username
214
-		);
215
-
216
-		$row_actions = array();
217
-
218
-		// View subscription.
219
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
-
222
-		// View invoice.
223
-		$invoice = get_post( $item->get_parent_invoice_id() );
224
-
225
-		if ( ! empty( $invoice ) ) {
226
-			$invoice_url            = get_edit_post_link( $invoice );
227
-			$row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
-		}
229
-
230
-		$delete_url            = esc_url(
231
-			wp_nonce_url(
232
-				add_query_arg(
233
-					array(
234
-						'getpaid-admin-action' => 'subscription_manual_delete',
235
-						'id'                   => $item->get_id(),
236
-					)
237
-				),
238
-				'getpaid-nonce',
239
-				'getpaid-nonce'
240
-			)
241
-		);
242
-		$row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
243
-
244
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
245
-
246
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
247
-	}
248
-
249
-	/**
250
-	 * Renewal date column
251
-	 *
252
-	 * @param WPInv_Subscription $item
253
-	 * @since       1.0.0
254
-	 * @return      string
255
-	 */
256
-	public function column_renewal_date( $item ) {
257
-		return getpaid_format_date_value( $item->get_expiration() );
258
-	}
259
-
260
-	/**
261
-	 * Start date column
262
-	 *
263
-	 * @param WPInv_Subscription $item
264
-	 * @since       1.0.0
265
-	 * @return      string
266
-	 */
267
-	public function column_start_date( $item ) {
268
-		return getpaid_format_date_value( $item->get_date_created() );
269
-	}
270
-
271
-	/**
272
-	 * Amount column
273
-	 *
274
-	 * @param WPInv_Subscription $item
275
-	 * @since       1.0.19
276
-	 * @return      string
277
-	 */
278
-	public function column_amount( $item ) {
279
-		$amount = getpaid_get_formatted_subscription_amount( $item );
280
-		return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
281
-	}
282
-
283
-	/**
284
-	 * Billing Times column
285
-	 *
286
-	 * @param WPInv_Subscription $item
287
-	 * @since       1.0.0
288
-	 * @return      string
289
-	 */
290
-	public function column_renewals( $item ) {
291
-		$max_bills = $item->get_bill_times();
292
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
293
-	}
294
-
295
-	/**
296
-	 * Product ID column
297
-	 *
298
-	 * @param WPInv_Subscription $item
299
-	 * @since       1.0.0
300
-	 * @return      string
301
-	 */
302
-	public function column_item( $item ) {
303
-		$_item = get_post( $item->get_product_id() );
304
-
305
-		if ( ! empty( $_item ) ) {
306
-			$link = get_edit_post_link( $_item );
307
-			$link = esc_url( $link );
308
-			$name = esc_html( get_the_title( $_item ) );
309
-			return "<a href='$link'>$name</a>";
310
-		} else {
311
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
312
-		}
313
-
314
-	}
315
-
316
-	/**
317
-	 * Retrieve the current page number
318
-	 *
319
-	 * @return      int
320
-	 */
321
-	public function get_paged() {
322
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
323
-	}
324
-
325
-	/**
326
-	 * Setup the final data for the table
327
-	 *
328
-	 */
329
-	public function prepare_items() {
330
-
331
-		$columns  = $this->get_columns();
332
-		$hidden   = array();
333
-		$sortable = $this->get_sortable_columns();
334
-
335
-		$this->_column_headers = array( $columns, $hidden, $sortable );
336
-
337
-		$this->set_pagination_args(
338
-			array(
339
-			'total_items' => $this->current_total_count,
340
-			'per_page'    => $this->per_page,
341
-			'total_pages' => ceil( $this->current_total_count / $this->per_page )
342
-			)
343
-		);
344
-	}
345
-
346
-	/**
347
-	 * Table columns
348
-	 *
349
-	 * @return array
350
-	 */
351
-	public function get_columns(){
352
-		$columns = array(
353
-			'cb'                => '<input type="checkbox" />',
354
-			'subscription'      => __( 'Subscription', 'invoicing' ),
355
-			'start_date'        => __( 'Start Date', 'invoicing' ),
356
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
357
-			'renewals'          => __( 'Payments', 'invoicing' ),
358
-			'item'              => __( 'Item', 'invoicing' ),
359
-			'status'            => __( 'Status', 'invoicing' ),
360
-		);
361
-
362
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
363
-	}
364
-
365
-	/**
366
-	 * Sortable table columns.
367
-	 *
368
-	 * @return array
369
-	 */
370
-	public function get_sortable_columns() {
371
-		$sortable = array(
372
-			'subscription' => array( 'id', true ),
373
-			'start_date'   => array( 'created', true ),
374
-			'renewal_date' => array( 'expiration', true ),
375
-			'renewals'     => array( 'bill_times', true ),
376
-			'item'         => array( 'product_id', true ),
377
-			'status'       => array( 'status', true ),
378
-		);
379
-
380
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
381
-	}
382
-
383
-	/**
384
-	 * Whether the table has items to display or not
385
-	 *
386
-	 * @return bool
387
-	 */
388
-	public function has_items() {
389
-		return ! empty( $this->current_total_count );
390
-	}
391
-
392
-	/**
393
-	 * Processes bulk actions.
394
-	 *
395
-	 */
396
-	public function process_bulk_action() {
397
-
398
-	}
17
+    /**
18
+     * URL of this page
19
+     *
20
+     * @var   string
21
+     * @since 1.0.19
22
+     */
23
+    public $base_url;
24
+
25
+    /**
26
+     * Query
27
+     *
28
+     * @var   GetPaid_Subscriptions_Query
29
+     * @since 1.0.19
30
+     */
31
+    public $query;
32
+
33
+    /**
34
+     * Total subscriptions
35
+     *
36
+     * @var   string
37
+     * @since 1.0.0
38
+     */
39
+    public $total_count;
40
+
41
+    /**
42
+     * Current status subscriptions
43
+     *
44
+     * @var   string
45
+     * @since 1.0.0
46
+     */
47
+    public $current_total_count;
48
+
49
+    /**
50
+     * Status counts
51
+     *
52
+     * @var   array
53
+     * @since 1.0.19
54
+     */
55
+    public $status_counts;
56
+
57
+    /**
58
+     * Number of results to show per page
59
+     *
60
+     * @var   int
61
+     * @since 1.0.0
62
+     */
63
+    public $per_page = 10;
64
+
65
+    /**
66
+     *  Constructor function.
67
+     */
68
+    public function __construct() {
69
+
70
+        parent::__construct(
71
+            array(
72
+                'singular' => 'subscription',
73
+                'plural'   => 'subscriptions',
74
+            )
75
+        );
76
+
77
+        $this->process_bulk_action();
78
+
79
+        $this->prepare_query();
80
+
81
+        $this->base_url = remove_query_arg( 'status' );
82
+
83
+    }
84
+
85
+    /**
86
+     *  Prepares the display query
87
+     */
88
+    public function prepare_query() {
89
+
90
+        // Prepare query args.
91
+        $query = array(
92
+            'number'  => $this->per_page,
93
+            'paged'   => $this->get_paged(),
94
+            'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
+            'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
+            'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
+        );
98
+
99
+        // Prepare class properties.
100
+        $this->query               = new GetPaid_Subscriptions_Query( $query );
101
+        $this->total_count         = $this->query->get_total();
102
+        $this->current_total_count = $this->query->get_total();
103
+        $this->items               = $this->query->get_results();
104
+        $this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
+
106
+        if ( 'all' != $query['status'] ) {
107
+            unset( $query['status'] );
108
+            $this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
+        }
110
+
111
+    }
112
+
113
+    /**
114
+     * Gets the list of views available on this table.
115
+     *
116
+     * The format is an associative array:
117
+     * - `'id' => 'link'`
118
+     *
119
+     * @since 1.0.0
120
+     *
121
+     * @return array
122
+     */
123
+    public function get_views() {
124
+
125
+        $current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
+        $views    = array(
127
+
128
+            'all' => sprintf(
129
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
+                esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
+                $current === 'all' ? ' class="current"' : '',
132
+                __('All','invoicing' ),
133
+                $this->total_count
134
+            )
135
+
136
+        );
137
+
138
+        foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
+
140
+            $views[ $status ] = sprintf(
141
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
+                esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
+                $current === $status ? ' class="current"' : '',
144
+                sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
+                $count
146
+            );
147
+
148
+        }
149
+
150
+        return $views;
151
+
152
+    }
153
+
154
+    /**
155
+     * Render most columns
156
+     *
157
+     * @access      private
158
+     * @since       1.0.0
159
+     * @return      string
160
+     */
161
+    public function column_default( $item, $column_name ) {
162
+        return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
+    }
164
+
165
+    /**
166
+     * This is how checkbox column renders.
167
+     *
168
+     * @param WPInv_Subscription $item
169
+     * @return string
170
+     */
171
+    public function column_cb( $item ) {
172
+        return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
+    }
174
+
175
+    /**
176
+     * Status column
177
+     *
178
+     * @param WPInv_Subscription $item
179
+     * @since       1.0.0
180
+     * @return      string
181
+     */
182
+    public function column_status( $item ) {
183
+        return $item->get_status_label_html();
184
+    }
185
+
186
+    /**
187
+     * Subscription column
188
+     *
189
+     * @param WPInv_Subscription $item
190
+     * @since       1.0.0
191
+     * @return      string
192
+     */
193
+    public function column_subscription( $item ) {
194
+
195
+        $username = __( '(Missing User)', 'invoicing' );
196
+
197
+        $user = get_userdata( $item->get_customer_id() );
198
+        if ( $user ) {
199
+
200
+            $username = sprintf(
201
+                '<a href="user-edit.php?user_id=%s">%s</a>',
202
+                absint( $user->ID ),
203
+                ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
+            );
205
+
206
+        }
207
+
208
+        // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
+        $column_content = sprintf(
210
+            _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
+            '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
+            '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
+            $username
214
+        );
215
+
216
+        $row_actions = array();
217
+
218
+        // View subscription.
219
+        $view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
+        $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
+
222
+        // View invoice.
223
+        $invoice = get_post( $item->get_parent_invoice_id() );
224
+
225
+        if ( ! empty( $invoice ) ) {
226
+            $invoice_url            = get_edit_post_link( $invoice );
227
+            $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
+        }
229
+
230
+        $delete_url            = esc_url(
231
+            wp_nonce_url(
232
+                add_query_arg(
233
+                    array(
234
+                        'getpaid-admin-action' => 'subscription_manual_delete',
235
+                        'id'                   => $item->get_id(),
236
+                    )
237
+                ),
238
+                'getpaid-nonce',
239
+                'getpaid-nonce'
240
+            )
241
+        );
242
+        $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
243
+
244
+        $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
245
+
246
+        return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
247
+    }
248
+
249
+    /**
250
+     * Renewal date column
251
+     *
252
+     * @param WPInv_Subscription $item
253
+     * @since       1.0.0
254
+     * @return      string
255
+     */
256
+    public function column_renewal_date( $item ) {
257
+        return getpaid_format_date_value( $item->get_expiration() );
258
+    }
259
+
260
+    /**
261
+     * Start date column
262
+     *
263
+     * @param WPInv_Subscription $item
264
+     * @since       1.0.0
265
+     * @return      string
266
+     */
267
+    public function column_start_date( $item ) {
268
+        return getpaid_format_date_value( $item->get_date_created() );
269
+    }
270
+
271
+    /**
272
+     * Amount column
273
+     *
274
+     * @param WPInv_Subscription $item
275
+     * @since       1.0.19
276
+     * @return      string
277
+     */
278
+    public function column_amount( $item ) {
279
+        $amount = getpaid_get_formatted_subscription_amount( $item );
280
+        return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
281
+    }
282
+
283
+    /**
284
+     * Billing Times column
285
+     *
286
+     * @param WPInv_Subscription $item
287
+     * @since       1.0.0
288
+     * @return      string
289
+     */
290
+    public function column_renewals( $item ) {
291
+        $max_bills = $item->get_bill_times();
292
+        return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
293
+    }
294
+
295
+    /**
296
+     * Product ID column
297
+     *
298
+     * @param WPInv_Subscription $item
299
+     * @since       1.0.0
300
+     * @return      string
301
+     */
302
+    public function column_item( $item ) {
303
+        $_item = get_post( $item->get_product_id() );
304
+
305
+        if ( ! empty( $_item ) ) {
306
+            $link = get_edit_post_link( $_item );
307
+            $link = esc_url( $link );
308
+            $name = esc_html( get_the_title( $_item ) );
309
+            return "<a href='$link'>$name</a>";
310
+        } else {
311
+            return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
312
+        }
313
+
314
+    }
315
+
316
+    /**
317
+     * Retrieve the current page number
318
+     *
319
+     * @return      int
320
+     */
321
+    public function get_paged() {
322
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
323
+    }
324
+
325
+    /**
326
+     * Setup the final data for the table
327
+     *
328
+     */
329
+    public function prepare_items() {
330
+
331
+        $columns  = $this->get_columns();
332
+        $hidden   = array();
333
+        $sortable = $this->get_sortable_columns();
334
+
335
+        $this->_column_headers = array( $columns, $hidden, $sortable );
336
+
337
+        $this->set_pagination_args(
338
+            array(
339
+            'total_items' => $this->current_total_count,
340
+            'per_page'    => $this->per_page,
341
+            'total_pages' => ceil( $this->current_total_count / $this->per_page )
342
+            )
343
+        );
344
+    }
345
+
346
+    /**
347
+     * Table columns
348
+     *
349
+     * @return array
350
+     */
351
+    public function get_columns(){
352
+        $columns = array(
353
+            'cb'                => '<input type="checkbox" />',
354
+            'subscription'      => __( 'Subscription', 'invoicing' ),
355
+            'start_date'        => __( 'Start Date', 'invoicing' ),
356
+            'renewal_date'      => __( 'Next Payment', 'invoicing' ),
357
+            'renewals'          => __( 'Payments', 'invoicing' ),
358
+            'item'              => __( 'Item', 'invoicing' ),
359
+            'status'            => __( 'Status', 'invoicing' ),
360
+        );
361
+
362
+        return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
363
+    }
364
+
365
+    /**
366
+     * Sortable table columns.
367
+     *
368
+     * @return array
369
+     */
370
+    public function get_sortable_columns() {
371
+        $sortable = array(
372
+            'subscription' => array( 'id', true ),
373
+            'start_date'   => array( 'created', true ),
374
+            'renewal_date' => array( 'expiration', true ),
375
+            'renewals'     => array( 'bill_times', true ),
376
+            'item'         => array( 'product_id', true ),
377
+            'status'       => array( 'status', true ),
378
+        );
379
+
380
+        return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
381
+    }
382
+
383
+    /**
384
+     * Whether the table has items to display or not
385
+     *
386
+     * @return bool
387
+     */
388
+    public function has_items() {
389
+        return ! empty( $this->current_total_count );
390
+    }
391
+
392
+    /**
393
+     * Processes bulk actions.
394
+     *
395
+     */
396
+    public function process_bulk_action() {
397
+
398
+    }
399 399
 
400 400
 }
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -3,9 +3,9 @@  discard block
 block discarded – undo
3 3
  * Displays a list of all subscriptions rules
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) exit;
6
+if (!defined('ABSPATH')) exit;
7 7
 
8
-if ( ! class_exists( 'WP_List_Table' ) ) {
8
+if (!class_exists('WP_List_Table')) {
9 9
 	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10 10
 }
11 11
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
 		$this->prepare_query();
80 80
 
81
-		$this->base_url = remove_query_arg( 'status' );
81
+		$this->base_url = remove_query_arg('status');
82 82
 
83 83
 	}
84 84
 
@@ -91,21 +91,21 @@  discard block
 block discarded – undo
91 91
 		$query = array(
92 92
 			'number'  => $this->per_page,
93 93
 			'paged'   => $this->get_paged(),
94
-			'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
-			'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
-			'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
94
+			'status'  => (isset($_GET['status']) && array_key_exists($_GET['status'], getpaid_get_subscription_statuses())) ? $_GET['status'] : 'all',
95
+			'orderby' => (isset($_GET['orderby'])) ? $_GET['orderby'] : 'id',
96
+			'order'   => (isset($_GET['order'])) ? $_GET['order'] : 'DESC',
97 97
 		);
98 98
 
99 99
 		// Prepare class properties.
100
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
100
+		$this->query               = new GetPaid_Subscriptions_Query($query);
101 101
 		$this->total_count         = $this->query->get_total();
102 102
 		$this->current_total_count = $this->query->get_total();
103 103
 		$this->items               = $this->query->get_results();
104
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
104
+		$this->status_counts       = getpaid_get_subscription_status_counts($query);
105 105
 
106
-		if ( 'all' != $query['status'] ) {
107
-			unset( $query['status'] );
108
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
106
+		if ('all' != $query['status']) {
107
+			unset($query['status']);
108
+			$this->total_count = getpaid_get_subscriptions($query, 'count');
109 109
 		}
110 110
 
111 111
 	}
@@ -122,26 +122,26 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function get_views() {
124 124
 
125
-		$current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
125
+		$current  = isset($_GET['status']) ? $_GET['status'] : 'all';
126 126
 		$views    = array(
127 127
 
128 128
 			'all' => sprintf(
129 129
 				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
130
+				esc_url(add_query_arg('status', false, $this->base_url)),
131 131
 				$current === 'all' ? ' class="current"' : '',
132
-				__('All','invoicing' ),
132
+				__('All', 'invoicing'),
133 133
 				$this->total_count
134 134
 			)
135 135
 
136 136
 		);
137 137
 
138
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
138
+		foreach (array_filter($this->status_counts) as $status => $count) {
139 139
 
140
-			$views[ $status ] = sprintf(
140
+			$views[$status] = sprintf(
141 141
 				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
142
+				esc_url(add_query_arg('status', urlencode($status), $this->base_url)),
143 143
 				$current === $status ? ' class="current"' : '',
144
-				sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
144
+				sanitize_text_field(getpaid_get_subscription_status_label($status)),
145 145
 				$count
146 146
 			);
147 147
 
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @since       1.0.0
159 159
 	 * @return      string
160 160
 	 */
161
-	public function column_default( $item, $column_name ) {
162
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
161
+	public function column_default($item, $column_name) {
162
+		return apply_filters("getpaid_subscriptions_table_column_$column_name", $item->$column_name);
163 163
 	}
164 164
 
165 165
 	/**
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 	 * @param WPInv_Subscription $item
169 169
 	 * @return string
170 170
 	 */
171
-	public function column_cb( $item ) {
172
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
171
+	public function column_cb($item) {
172
+		return sprintf('<input type="checkbox" name="id[]" value="%s" />', esc_html($item->get_id()));
173 173
 	}
174 174
 
175 175
 	/**
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @since       1.0.0
180 180
 	 * @return      string
181 181
 	 */
182
-	public function column_status( $item ) {
182
+	public function column_status($item) {
183 183
 		return $item->get_status_label_html();
184 184
 	}
185 185
 
@@ -190,44 +190,44 @@  discard block
 block discarded – undo
190 190
 	 * @since       1.0.0
191 191
 	 * @return      string
192 192
 	 */
193
-	public function column_subscription( $item ) {
193
+	public function column_subscription($item) {
194 194
 
195
-		$username = __( '(Missing User)', 'invoicing' );
195
+		$username = __('(Missing User)', 'invoicing');
196 196
 
197
-		$user = get_userdata( $item->get_customer_id() );
198
-		if ( $user ) {
197
+		$user = get_userdata($item->get_customer_id());
198
+		if ($user) {
199 199
 
200 200
 			$username = sprintf(
201 201
 				'<a href="user-edit.php?user_id=%s">%s</a>',
202
-				absint( $user->ID ),
203
-				! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
202
+				absint($user->ID),
203
+				!empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email)
204 204
 			);
205 205
 
206 206
 		}
207 207
 
208 208
 		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209 209
 		$column_content = sprintf(
210
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
210
+			_x('%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing'),
211
+			'<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($item->get_id()))) . '">',
212
+			'<strong>' . esc_attr($item->get_id()) . '</strong>', '</a>',
213 213
 			$username
214 214
 		);
215 215
 
216 216
 		$row_actions = array();
217 217
 
218 218
 		// View subscription.
219
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
219
+		$view_url    = esc_url(add_query_arg('id', $item->get_id(), admin_url('admin.php?page=wpinv-subscriptions')));
220
+		$row_actions['view'] = '<a href="' . $view_url . '">' . __('View Subscription', 'invoicing') . '</a>';
221 221
 
222 222
 		// View invoice.
223
-		$invoice = get_post( $item->get_parent_invoice_id() );
223
+		$invoice = get_post($item->get_parent_invoice_id());
224 224
 
225
-		if ( ! empty( $invoice ) ) {
226
-			$invoice_url            = get_edit_post_link( $invoice );
227
-			$row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
225
+		if (!empty($invoice)) {
226
+			$invoice_url            = get_edit_post_link($invoice);
227
+			$row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __('View Invoice', 'invoicing') . '</a>';
228 228
 		}
229 229
 
230
-		$delete_url            = esc_url(
230
+		$delete_url = esc_url(
231 231
 			wp_nonce_url(
232 232
 				add_query_arg(
233 233
 					array(
@@ -239,11 +239,11 @@  discard block
 block discarded – undo
239 239
 				'getpaid-nonce'
240 240
 			)
241 241
 		);
242
-		$row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>';
242
+		$row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __('Delete Subscription', 'invoicing') . '</a>';
243 243
 
244
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
244
+		$row_actions = $this->row_actions(apply_filters('getpaid_subscription_table_row_actions', $row_actions, $item));
245 245
 
246
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
246
+		return "<strong>$column_content</strong>" . $this->column_amount($item) . $row_actions;
247 247
 	}
248 248
 
249 249
 	/**
@@ -253,8 +253,8 @@  discard block
 block discarded – undo
253 253
 	 * @since       1.0.0
254 254
 	 * @return      string
255 255
 	 */
256
-	public function column_renewal_date( $item ) {
257
-		return getpaid_format_date_value( $item->get_expiration() );
256
+	public function column_renewal_date($item) {
257
+		return getpaid_format_date_value($item->get_expiration());
258 258
 	}
259 259
 
260 260
 	/**
@@ -264,8 +264,8 @@  discard block
 block discarded – undo
264 264
 	 * @since       1.0.0
265 265
 	 * @return      string
266 266
 	 */
267
-	public function column_start_date( $item ) {
268
-		return getpaid_format_date_value( $item->get_date_created() );
267
+	public function column_start_date($item) {
268
+		return getpaid_format_date_value($item->get_date_created());
269 269
 	}
270 270
 
271 271
 	/**
@@ -275,8 +275,8 @@  discard block
 block discarded – undo
275 275
 	 * @since       1.0.19
276 276
 	 * @return      string
277 277
 	 */
278
-	public function column_amount( $item ) {
279
-		$amount = getpaid_get_formatted_subscription_amount( $item );
278
+	public function column_amount($item) {
279
+		$amount = getpaid_get_formatted_subscription_amount($item);
280 280
 		return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
281 281
 	}
282 282
 
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
 	 * @since       1.0.0
288 288
 	 * @return      string
289 289
 	 */
290
-	public function column_renewals( $item ) {
290
+	public function column_renewals($item) {
291 291
 		$max_bills = $item->get_bill_times();
292
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
292
+		return $item->get_times_billed() . ' / ' . (empty($max_bills) ? "&infin;" : $max_bills);
293 293
 	}
294 294
 
295 295
 	/**
@@ -299,16 +299,16 @@  discard block
 block discarded – undo
299 299
 	 * @since       1.0.0
300 300
 	 * @return      string
301 301
 	 */
302
-	public function column_item( $item ) {
303
-		$_item = get_post( $item->get_product_id() );
302
+	public function column_item($item) {
303
+		$_item = get_post($item->get_product_id());
304 304
 
305
-		if ( ! empty( $_item ) ) {
306
-			$link = get_edit_post_link( $_item );
307
-			$link = esc_url( $link );
308
-			$name = esc_html( get_the_title( $_item ) );
305
+		if (!empty($_item)) {
306
+			$link = get_edit_post_link($_item);
307
+			$link = esc_url($link);
308
+			$name = esc_html(get_the_title($_item));
309 309
 			return "<a href='$link'>$name</a>";
310 310
 		} else {
311
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
311
+			return sprintf(__('Item #%s', 'invoicing'), $item->get_product_id());
312 312
 		}
313 313
 
314 314
 	}
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 	 * @return      int
320 320
 	 */
321 321
 	public function get_paged() {
322
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
322
+		return isset($_GET['paged']) ? absint($_GET['paged']) : 1;
323 323
 	}
324 324
 
325 325
 	/**
@@ -332,13 +332,13 @@  discard block
 block discarded – undo
332 332
 		$hidden   = array();
333 333
 		$sortable = $this->get_sortable_columns();
334 334
 
335
-		$this->_column_headers = array( $columns, $hidden, $sortable );
335
+		$this->_column_headers = array($columns, $hidden, $sortable);
336 336
 
337 337
 		$this->set_pagination_args(
338 338
 			array(
339 339
 			'total_items' => $this->current_total_count,
340 340
 			'per_page'    => $this->per_page,
341
-			'total_pages' => ceil( $this->current_total_count / $this->per_page )
341
+			'total_pages' => ceil($this->current_total_count / $this->per_page)
342 342
 			)
343 343
 		);
344 344
 	}
@@ -348,18 +348,18 @@  discard block
 block discarded – undo
348 348
 	 *
349 349
 	 * @return array
350 350
 	 */
351
-	public function get_columns(){
351
+	public function get_columns() {
352 352
 		$columns = array(
353 353
 			'cb'                => '<input type="checkbox" />',
354
-			'subscription'      => __( 'Subscription', 'invoicing' ),
355
-			'start_date'        => __( 'Start Date', 'invoicing' ),
356
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
357
-			'renewals'          => __( 'Payments', 'invoicing' ),
358
-			'item'              => __( 'Item', 'invoicing' ),
359
-			'status'            => __( 'Status', 'invoicing' ),
354
+			'subscription'      => __('Subscription', 'invoicing'),
355
+			'start_date'        => __('Start Date', 'invoicing'),
356
+			'renewal_date'      => __('Next Payment', 'invoicing'),
357
+			'renewals'          => __('Payments', 'invoicing'),
358
+			'item'              => __('Item', 'invoicing'),
359
+			'status'            => __('Status', 'invoicing'),
360 360
 		);
361 361
 
362
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
362
+		return apply_filters('manage_getpaid_subscriptions_table_columns', $columns);
363 363
 	}
364 364
 
365 365
 	/**
@@ -369,15 +369,15 @@  discard block
 block discarded – undo
369 369
 	 */
370 370
 	public function get_sortable_columns() {
371 371
 		$sortable = array(
372
-			'subscription' => array( 'id', true ),
373
-			'start_date'   => array( 'created', true ),
374
-			'renewal_date' => array( 'expiration', true ),
375
-			'renewals'     => array( 'bill_times', true ),
376
-			'item'         => array( 'product_id', true ),
377
-			'status'       => array( 'status', true ),
372
+			'subscription' => array('id', true),
373
+			'start_date'   => array('created', true),
374
+			'renewal_date' => array('expiration', true),
375
+			'renewals'     => array('bill_times', true),
376
+			'item'         => array('product_id', true),
377
+			'status'       => array('status', true),
378 378
 		);
379 379
 
380
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
380
+		return apply_filters('manage_getpaid_subscriptions_sortable_table_columns', $sortable);
381 381
 	}
382 382
 
383 383
 	/**
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 	 * @return bool
387 387
 	 */
388 388
 	public function has_items() {
389
-		return ! empty( $this->current_total_count );
389
+		return !empty($this->current_total_count);
390 390
 	}
391 391
 
392 392
 	/**
Please login to merge, or discard this patch.