1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Table to show cron list. |
4
|
|
|
* |
5
|
|
|
* @author Sudar |
6
|
|
|
* |
7
|
|
|
* @package BulkDelete\Cron |
8
|
|
|
*/ |
9
|
|
|
defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
10
|
|
|
|
11
|
|
|
class Cron_List_Table extends WP_List_Table { |
12
|
|
|
/** |
13
|
|
|
* Constructor, we override the parent to pass our own arguments |
14
|
|
|
* We usually focus on three parameters: singular and plural labels, as well as whether the class supports AJAX. |
15
|
|
|
*/ |
16
|
|
|
public function __construct() { |
17
|
|
|
parent::__construct( array( |
18
|
|
|
'singular' => 'cron_list', //Singular label |
19
|
|
|
'plural' => 'cron_lists', //plural label, also this well be one of the table css class |
20
|
|
|
'ajax' => false, //We won't support Ajax for this table |
21
|
|
|
) ); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Add extra markup in the toolbars before or after the list. |
26
|
|
|
* |
27
|
|
|
* @param string $which Whether the markup should appear after (bottom) or before (top) the list |
28
|
|
|
*/ |
29
|
|
|
public function extra_tablenav( $which ) { |
30
|
|
|
if ( 'top' == $which ) { |
31
|
|
|
//The code that goes before the table is here |
32
|
|
|
echo '<p>'; |
33
|
|
|
_e( 'This is the list of jobs that are currently scheduled for auto deleting posts in Bulk Delete Plugin.', 'bulk-delete' ); |
34
|
|
|
echo ' <strong>'; |
35
|
|
|
_e( 'Note: ', 'bulk-delete' ); |
36
|
|
|
echo '</strong>'; |
37
|
|
|
_e( 'Scheduling auto post or user deletion is available only when you buy pro addons.', 'bulk-delete' ); |
38
|
|
|
echo '</p>'; |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Define the columns that are going to be used in the table. |
44
|
|
|
* |
45
|
|
|
* @return array Array of columns to use with the table |
46
|
|
|
*/ |
47
|
|
|
public function get_columns() { |
48
|
|
|
return array( |
49
|
|
|
'col_cron_due' => __( 'Next Due', 'bulk-delete' ), |
50
|
|
|
'col_cron_schedule' => __( 'Schedule', 'bulk-delete' ), |
51
|
|
|
'col_cron_type' => __( 'Type', 'bulk-delete' ), |
52
|
|
|
'col_cron_options' => __( 'Options', 'bulk-delete' ), |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Decide which columns to activate the sorting functionality on. |
58
|
|
|
* |
59
|
|
|
* @return array Array of columns that can be sorted by the user |
60
|
|
|
*/ |
61
|
|
|
public function get_sortable_columns() { |
62
|
|
|
return array( |
63
|
|
|
'col_cron_type' => array( 'cron_type', true ), |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Prepare the table with different parameters, pagination, columns and table elements. |
69
|
|
|
*/ |
70
|
|
|
public function prepare_items() { |
71
|
|
|
$cron_items = BD_Util::get_cron_schedules(); |
72
|
|
|
$totalitems = count( $cron_items ); |
73
|
|
|
|
74
|
|
|
//How many to display per page? |
75
|
|
|
$perpage = 50; |
76
|
|
|
|
77
|
|
|
//How many pages do we have in total? |
78
|
|
|
$totalpages = ceil( $totalitems / $perpage ); |
79
|
|
|
|
80
|
|
|
/* -- Register the pagination -- */ |
81
|
|
|
$this->set_pagination_args( array( |
82
|
|
|
'total_items' => $totalitems, |
83
|
|
|
'total_pages' => $totalpages, |
84
|
|
|
'per_page' => $perpage, |
85
|
|
|
) ); |
86
|
|
|
|
87
|
|
|
//The pagination links are automatically built according to those parameters |
88
|
|
|
|
89
|
|
|
/* — Register the Columns — */ |
90
|
|
|
$columns = $this->get_columns(); |
91
|
|
|
$hidden = array(); |
92
|
|
|
$sortable = $this->get_sortable_columns(); |
93
|
|
|
$this->_column_headers = array( $columns, $hidden, $sortable ); |
94
|
|
|
|
95
|
|
|
$this->items = $cron_items; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Display cron due date column. |
100
|
|
|
* |
101
|
|
|
* @param array $item |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function column_col_cron_due( $item ) { |
106
|
|
|
//Build row actions |
107
|
|
|
$actions = array( |
108
|
|
|
'delete' => sprintf( '<a href="?page=%s&bd_action=%s&cron_id=%s&%s=%s">%s</a>', |
109
|
|
|
$_REQUEST['page'], |
110
|
|
|
'delete_cron', |
111
|
|
|
$item['id'], |
112
|
|
|
'bd-delete_cron-nonce', |
113
|
|
|
wp_create_nonce( 'bd-delete_cron' ), |
114
|
|
|
__( 'Delete', 'bulk-delete' ) |
115
|
|
|
), |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
//Return the title contents |
119
|
|
|
return sprintf( '%1$s <span style="color:silver">(%2$s)</span>%3$s', |
120
|
|
|
/*$1%s*/ $item['due'], |
121
|
|
|
/*$2%s*/ ( $item['timestamp'] + get_option( 'gmt_offset' ) * 60 * 60 ), |
122
|
|
|
/*$3%s*/ $this->row_actions( $actions ) |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Display cron schedule column. |
128
|
|
|
* |
129
|
|
|
* @param array $item |
130
|
|
|
*/ |
131
|
|
|
public function column_col_cron_schedule( $item ) { |
132
|
|
|
echo $item['schedule']; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Display cron type column. |
137
|
|
|
* |
138
|
|
|
* @param array $item |
139
|
|
|
*/ |
140
|
|
|
public function column_col_cron_type( $item ) { |
141
|
|
|
echo $item['type']; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Display cron options column. |
146
|
|
|
* |
147
|
|
|
* @param array $item |
148
|
|
|
*/ |
149
|
|
|
public function column_col_cron_options( $item ) { |
150
|
|
|
// TODO: Make it pretty |
151
|
|
|
print_r( $item['args'] ); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function no_items() { |
155
|
|
|
_e( 'You have not scheduled any bulk delete jobs.', 'bulk-delete' ); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|