... | ... |
@@ -11,10 +11,10 @@ class admin_list_table extends WP_List_Table { |
11 | 11 |
'plural' => 'Customers', //plural name of the listed records |
12 | 12 |
'ajax' => false, //should this table support ajax? |
13 | 13 |
'screen' => null |
14 |
- )); |
|
14 |
+ )); |
|
15 | 15 |
} |
16 | 16 |
|
17 |
- public static function get_customers($per_page = 5, $page_number = 1) { |
|
17 |
+ public function get_customers($per_page = 5, $page_number = 1) { |
|
18 | 18 |
global $wpdb; |
19 | 19 |
|
20 | 20 |
$sql = "SELECT * FROM {$wpdb->prefix}customers"; |
... | ... |
@@ -32,17 +32,17 @@ class admin_list_table extends WP_List_Table { |
32 | 32 |
return $result; |
33 | 33 |
} |
34 | 34 |
|
35 |
- public static function delete_customer($id) { |
|
35 |
+ public function delete_customer($id) { |
|
36 | 36 |
global $wpdb; |
37 | 37 |
|
38 | 38 |
$wpdb->delete( |
39 | 39 |
"{$wpdb->prefix}customers", |
40 | 40 |
array('ID' => $id), |
41 | 41 |
array('%d') |
42 |
- ); |
|
42 |
+ ); |
|
43 | 43 |
} |
44 | 44 |
|
45 |
- public static function record_count() { |
|
45 |
+ public function record_count() { |
|
46 | 46 |
global $wpdb; |
47 | 47 |
|
48 | 48 |
$sql = "SELECT COUNT(*) FROM {$wpdb->prefix}customers"; |
... | ... |
@@ -62,7 +62,7 @@ class admin_list_table extends WP_List_Table { |
62 | 62 |
function column_cb($item) { |
63 | 63 |
return sprintf( |
64 | 64 |
'<input type="checkbox" name="bulk-delete[]" value="%s" />', $item['ID'] |
65 |
- ); |
|
65 |
+ ); |
|
66 | 66 |
} |
67 | 67 |
|
68 | 68 |
function column_name($item) { |
... | ... |
@@ -84,7 +84,7 @@ class admin_list_table extends WP_List_Table { |
84 | 84 |
'name' => 'Name', |
85 | 85 |
'address' => 'Address', |
86 | 86 |
'city' => 'City' |
87 |
- ); |
|
87 |
+ ); |
|
88 | 88 |
|
89 | 89 |
return $columns; |
90 | 90 |
} |
... | ... |
@@ -93,7 +93,7 @@ class admin_list_table extends WP_List_Table { |
93 | 93 |
$sortable_columns = array( |
94 | 94 |
'name' => array('name', true), |
95 | 95 |
'city' => array('city', true) |
96 |
- ); |
|
96 |
+ ); |
|
97 | 97 |
|
98 | 98 |
return $sortable_columns; |
99 | 99 |
} |
... | ... |
@@ -107,21 +107,39 @@ class admin_list_table extends WP_List_Table { |
107 | 107 |
public function prepare_items() { |
108 | 108 |
$this->_column_headers = $this->get_column_info(); |
109 | 109 |
|
110 |
- /** Process bulk action */ |
|
111 | 110 |
$this->process_bulk_action(); |
112 | 111 |
|
113 | 112 |
$per_page = $this->get_items_per_page('customers_per_page', 5); |
114 | 113 |
$current_page = $this->get_pagenum(); |
115 |
- $total_items = self::record_count(); |
|
114 |
+ $total_items = $this->record_count(); |
|
116 | 115 |
|
117 | 116 |
$this->set_pagination_args(array( |
118 | 117 |
'total_items' => $total_items, //WE have to calculate the total number of items |
119 | 118 |
'per_page' => $per_page //WE have to determine how many items to show on a page |
120 | 119 |
)); |
121 | 120 |
|
122 |
- $this->items = self::get_customers($per_page, $current_page); |
|
121 |
+ $this->items = $this->get_customers($per_page, $current_page); |
|
123 | 122 |
} |
124 | 123 |
|
125 | 124 |
public function process_bulk_action() { |
125 |
+ if ('delete' === $this->current_action()) { |
|
126 |
+ $nonce = esc_attr($_REQUEST['_wpnonce']); |
|
127 |
+ |
|
128 |
+ if (! wp_verify_nonce($nonce, 'delete_customer')) { |
|
129 |
+ die('Go get a life script kiddies'); |
|
130 |
+ } |
|
131 |
+ else { |
|
132 |
+ $this->delete_customer(absint($_GET['customer'])); |
|
133 |
+ } |
|
134 |
+ } |
|
135 |
+ |
|
136 |
+ if ((isset($_POST['action']) && $_POST['action'] == 'bulk-delete') |
|
137 |
+ || (isset($_POST['action2']) && $_POST['action2'] == 'bulk-delete')) { |
|
138 |
+ $delete_ids = esc_sql($_POST['bulk-delete']); |
|
139 |
+ |
|
140 |
+ foreach ($delete_ids as $id) { |
|
141 |
+ $this->delete_customer($id); |
|
142 |
+ } |
|
143 |
+ } |
|
126 | 144 |
} |
127 | 145 |
} |