@@ -14,8 +14,8 @@ discard block |
||
14 | 14 | if ( ! class_exists( 'Table' ) ) { |
15 | 15 | |
16 | 16 | if ( ! class_exists( 'WP_List_Table' ) ) { |
17 | - require_once( ABSPATH . 'wp-admin/includes/screen.php' ); |
|
18 | - require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); |
|
17 | + require_once( ABSPATH . 'wp-admin/includes/screen.php' ); |
|
18 | + require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | final class Table extends WP_List_Table { |
@@ -230,10 +230,10 @@ discard block |
||
230 | 230 | $current_page = $this->get_pagenum(); |
231 | 231 | $total_items = self::record_count(); |
232 | 232 | $this->_column_headers = [ |
233 | - $this->get_columns(), |
|
234 | - [], // hidden columns |
|
235 | - $this->get_sortable_columns(), |
|
236 | - $this->get_primary_column_name(), |
|
233 | + $this->get_columns(), |
|
234 | + [], // hidden columns |
|
235 | + $this->get_sortable_columns(), |
|
236 | + $this->get_primary_column_name(), |
|
237 | 237 | ]; |
238 | 238 | $this->set_pagination_args( array( |
239 | 239 | 'total_items' => $total_items, |
@@ -11,11 +11,11 @@ discard block |
||
11 | 11 | * @author Nirjhar Lo |
12 | 12 | * @package wp-plugin-framework |
13 | 13 | */ |
14 | -if ( ! class_exists( 'Table' ) ) { |
|
14 | +if ( ! class_exists('Table')) { |
|
15 | 15 | |
16 | - if ( ! class_exists( 'WP_List_Table' ) ) { |
|
17 | - require_once( ABSPATH . 'wp-admin/includes/screen.php' ); |
|
18 | - require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); |
|
16 | + if ( ! class_exists('WP_List_Table')) { |
|
17 | + require_once(ABSPATH . 'wp-admin/includes/screen.php'); |
|
18 | + require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | final class Table extends WP_List_Table { |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function __construct() { |
30 | 30 | |
31 | - parent::__construct( [ |
|
32 | - 'singular' => __( 'Name', 'textdomain' ), |
|
33 | - 'plural' => __( 'Names', 'textdomain' ), |
|
31 | + parent::__construct([ |
|
32 | + 'singular' => __('Name', 'textdomain'), |
|
33 | + 'plural' => __('Names', 'textdomain'), |
|
34 | 34 | 'ajax' => false, |
35 | - ] ); |
|
35 | + ]); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | |
@@ -41,27 +41,27 @@ discard block |
||
41 | 41 | * |
42 | 42 | * @return Array |
43 | 43 | */ |
44 | - public static function get_Table( $per_page = 5, $page_number = 1 ) { |
|
44 | + public static function get_Table($per_page = 5, $page_number = 1) { |
|
45 | 45 | |
46 | 46 | global $wpdb; |
47 | 47 | |
48 | 48 | //Take pivotal from URL |
49 | - $link = ( isset( $_GET['link'] ) ? $_GET['link'] : 'link' ); |
|
49 | + $link = (isset($_GET['link']) ? $_GET['link'] : 'link'); |
|
50 | 50 | |
51 | 51 | //Build the db query base |
52 | 52 | $sql = "SELECT * FROM {$wpdb->prefix}wordpress_table"; |
53 | 53 | $sql .= " QUERIES with $link'"; |
54 | 54 | |
55 | 55 | //Set filters in the query using $_REQUEST |
56 | - if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
57 | - $sql .= ' ORDER BY ' . esc_sql( $_REQUEST['orderby'] ); |
|
58 | - $sql .= ! empty( $_REQUEST['order'] ) ? ' ' . esc_sql( $_REQUEST['order'] ) : ' ASC'; |
|
56 | + if ( ! empty($_REQUEST['orderby'])) { |
|
57 | + $sql .= ' ORDER BY ' . esc_sql($_REQUEST['orderby']); |
|
58 | + $sql .= ! empty($_REQUEST['order']) ? ' ' . esc_sql($_REQUEST['order']) : ' ASC'; |
|
59 | 59 | } |
60 | 60 | $sql .= " LIMIT $per_page"; |
61 | - $sql .= ' OFFSET ' . ( $page_number - 1 ) * $per_page; |
|
61 | + $sql .= ' OFFSET ' . ($page_number - 1) * $per_page; |
|
62 | 62 | |
63 | 63 | //get the data from database |
64 | - $result = $wpdb->get_results( $sql, 'ARRAY_A' ); |
|
64 | + $result = $wpdb->get_results($sql, 'ARRAY_A'); |
|
65 | 65 | |
66 | 66 | return $result; |
67 | 67 | } |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return Void |
74 | 74 | */ |
75 | - public static function delete_url( $id ) { |
|
75 | + public static function delete_url($id) { |
|
76 | 76 | |
77 | 77 | global $wpdb; |
78 | 78 | |
79 | - $wpdb->delete( "{$wpdb->prefix}wordpress_table", array( 'ID' => $id ), array( '%s' ) ); |
|
79 | + $wpdb->delete("{$wpdb->prefix}wordpress_table", array('ID' => $id), array('%s')); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function no_items() { |
89 | 89 | |
90 | - _e( 'No Items Added yet.', 'textDomain' ); |
|
90 | + _e('No Items Added yet.', 'textDomain'); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | |
@@ -101,13 +101,13 @@ discard block |
||
101 | 101 | global $wpdb; |
102 | 102 | |
103 | 103 | //Take pivotal from URL |
104 | - $link = ( isset( $_GET['link'] ) ? $_GET['link'] : 'link' ); |
|
104 | + $link = (isset($_GET['link']) ? $_GET['link'] : 'link'); |
|
105 | 105 | |
106 | 106 | //Build the db query base |
107 | 107 | $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}wordpress_table"; |
108 | 108 | $sql .= " QUERIES with $link'"; |
109 | 109 | |
110 | - return $wpdb->get_var( $sql ); |
|
110 | + return $wpdb->get_var($sql); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | |
@@ -116,17 +116,17 @@ discard block |
||
116 | 116 | * |
117 | 117 | * @return Html |
118 | 118 | */ |
119 | - public function column_name( $item ) { |
|
119 | + public function column_name($item) { |
|
120 | 120 | |
121 | - $delete_nonce = wp_create_nonce( 'delete_url' ); |
|
122 | - $title = sprintf( '<strong>%s</strong>', $item['item_name'] ); |
|
121 | + $delete_nonce = wp_create_nonce('delete_url'); |
|
122 | + $title = sprintf('<strong>%s</strong>', $item['item_name']); |
|
123 | 123 | |
124 | 124 | //Change the page instruction where you want to show it |
125 | 125 | $actions = array( |
126 | - 'delete' => sprintf( '<a href="?page=%s&action=%s&instruction=%s&_wpnonce=%s">%s</a>', esc_attr( $_REQUEST['page'] ), 'delete', absint( $item['ID'] ), $delete_nonce, __( 'Delete', 'textdomain' ) ) |
|
126 | + 'delete' => sprintf('<a href="?page=%s&action=%s&instruction=%s&_wpnonce=%s">%s</a>', esc_attr($_REQUEST['page']), 'delete', absint($item['ID']), $delete_nonce, __('Delete', 'textdomain')) |
|
127 | 127 | ); |
128 | 128 | |
129 | - return $title . $this->row_actions( $actions ); |
|
129 | + return $title . $this->row_actions($actions); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | |
@@ -135,22 +135,22 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return Html |
137 | 137 | */ |
138 | - public function column_default( $item, $column_name ) { |
|
138 | + public function column_default($item, $column_name) { |
|
139 | 139 | |
140 | - switch ( $column_name ) { |
|
140 | + switch ($column_name) { |
|
141 | 141 | |
142 | 142 | case 'name': |
143 | 143 | //This is the first column |
144 | - return $this->column_name( $item ); |
|
144 | + return $this->column_name($item); |
|
145 | 145 | case 'caseOne': |
146 | 146 | case 'caseTwo': |
147 | 147 | case 'caseThree': |
148 | - return $item[ $column_name ]; |
|
148 | + return $item[$column_name]; |
|
149 | 149 | |
150 | 150 | default: |
151 | 151 | |
152 | 152 | //Show the whole array for troubleshooting purposes |
153 | - return print_r( $item, true ); |
|
153 | + return print_r($item, true); |
|
154 | 154 | } |
155 | 155 | } |
156 | 156 | |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @return Html |
162 | 162 | */ |
163 | - public function column_cb( $item ) { |
|
163 | + public function column_cb($item) { |
|
164 | 164 | |
165 | - return sprintf( '<input type="checkbox" name="bulk-select[]" value="%s" />', $item['ID'] ); |
|
165 | + return sprintf('<input type="checkbox" name="bulk-select[]" value="%s" />', $item['ID']); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | |
@@ -175,10 +175,10 @@ discard block |
||
175 | 175 | |
176 | 176 | $columns = array( |
177 | 177 | 'cb' => '<input type="checkbox" />', |
178 | - 'name' => __( 'Name', 'textdomain' ), |
|
179 | - 'caseOne' => __( 'Case One', 'textdomain' ), |
|
180 | - 'caseTwo' => __( 'Case Two', 'textdomain' ), |
|
181 | - 'caseThree' => __( 'Case Three', 'textdomain' ), |
|
178 | + 'name' => __('Name', 'textdomain'), |
|
179 | + 'caseOne' => __('Case One', 'textdomain'), |
|
180 | + 'caseTwo' => __('Case Two', 'textdomain'), |
|
181 | + 'caseThree' => __('Case Three', 'textdomain'), |
|
182 | 182 | ); |
183 | 183 | |
184 | 184 | return $columns; |
@@ -193,9 +193,9 @@ discard block |
||
193 | 193 | public function get_sortable_columns() { |
194 | 194 | |
195 | 195 | $sortable_columns = array( |
196 | - 'name' => array( 'name', true ), |
|
197 | - 'caseOne' => array( 'caseOne', false ), |
|
198 | - 'caseTwo' => array( 'caseTwo', false ), |
|
196 | + 'name' => array('name', true), |
|
197 | + 'caseOne' => array('caseOne', false), |
|
198 | + 'caseTwo' => array('caseTwo', false), |
|
199 | 199 | ); |
200 | 200 | |
201 | 201 | return $sortable_columns; |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function get_bulk_actions() { |
211 | 211 | |
212 | - $actions = array( 'bulk-delete' => 'Delete' ); |
|
212 | + $actions = array('bulk-delete' => 'Delete'); |
|
213 | 213 | |
214 | 214 | return $actions; |
215 | 215 | } |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | |
227 | 227 | /** Process bulk action */ |
228 | 228 | $this->process_bulk_action(); |
229 | - $per_page = $this->get_items_per_page( 'option_name_per_page', 5 ); |
|
229 | + $per_page = $this->get_items_per_page('option_name_per_page', 5); |
|
230 | 230 | $current_page = $this->get_pagenum(); |
231 | 231 | $total_items = self::record_count(); |
232 | 232 | $this->_column_headers = [ |
@@ -235,12 +235,12 @@ discard block |
||
235 | 235 | $this->get_sortable_columns(), |
236 | 236 | $this->get_primary_column_name(), |
237 | 237 | ]; |
238 | - $this->set_pagination_args( array( |
|
238 | + $this->set_pagination_args(array( |
|
239 | 239 | 'total_items' => $total_items, |
240 | 240 | 'per_page' => $per_page, |
241 | - ) ); |
|
241 | + )); |
|
242 | 242 | |
243 | - $this->items = self::get_Table( $per_page, $current_page ); |
|
243 | + $this->items = self::get_Table($per_page, $current_page); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | |
@@ -252,24 +252,24 @@ discard block |
||
252 | 252 | public function process_bulk_action() { |
253 | 253 | |
254 | 254 | //Detect when a bulk action is being triggered... |
255 | - if ( 'delete' === $this->current_action() ) { |
|
255 | + if ('delete' === $this->current_action()) { |
|
256 | 256 | |
257 | 257 | //In our file that handles the request, verify the nonce. |
258 | - $nonce = esc_attr( $_REQUEST['_wpnonce'] ); |
|
258 | + $nonce = esc_attr($_REQUEST['_wpnonce']); |
|
259 | 259 | |
260 | - if ( ! wp_verify_nonce( $nonce, 'delete_url' ) ) { |
|
261 | - die( 'Go get a live script kiddies' ); |
|
260 | + if ( ! wp_verify_nonce($nonce, 'delete_url')) { |
|
261 | + die('Go get a live script kiddies'); |
|
262 | 262 | } else { |
263 | - self::delete_url( absint( $_GET['instruction'] ) ); //Remember the instruction param from column_name method |
|
263 | + self::delete_url(absint($_GET['instruction'])); //Remember the instruction param from column_name method |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | |
267 | 267 | //If the delete bulk action is triggered |
268 | - if ( isset( $_POST['action'] ) ) { |
|
269 | - if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' ) ) { |
|
270 | - $delete_ids = esc_sql( $_POST['bulk-select'] ); |
|
271 | - foreach ( $delete_ids as $id ) { |
|
272 | - self::delete_url( $id ); |
|
268 | + if (isset($_POST['action'])) { |
|
269 | + if ((isset($_POST['action']) && $_POST['action'] == 'bulk-delete')) { |
|
270 | + $delete_ids = esc_sql($_POST['bulk-select']); |
|
271 | + foreach ($delete_ids as $id) { |
|
272 | + self::delete_url($id); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | } |