wp_list_table bulk action not working
-
Hi,
I’m trying to do a plugin which uses custom table and custom post type with custom taxonomies. To show the data from the custom table I’m extending the wp_list_table class. The data is shown correctly, but my trouble starts when I want to delete the record or do anything on that page. I’m trying to implement the bulk delete and also the mouse over delete but it’s just not working. The mouse over delete “button” is not appearing at all and when I click the apply button for the bulk delete it just redirects me to a You do not have sufficient permissions to access this page. I don’t know what I’m doing wrong. Any ideas?
The code for the delete:function column_name( $item ) { $delete_nonce = wp_create_nonce( 'bsp_delete_student' ); $title = '<strong>' . $item['students_name'] . '</strong>'; $actions = [ 'delete'=>sprintf('<a href="?post_type=%s&page=%s&action=%s&student=%s">Delete</a>', $_REQUEST['post_type'], $_REQUEST['page'], 'delete', $item->students_id) ]; return $title . $this->row_actions( $actions ); } function get_bulk_actions(){ $actions=array( 'delete'=>__( 'Delete' ) ); return $actions; } public function process_bulk_action() { //Detect when a bulk action is being triggered... if ( 'delete' === $this->current_action() ) { // In our file that handles the request, verify the nonce. $nonce = esc_attr( $_REQUEST['_wpnonce'] ); if ( ! wp_verify_nonce( $nonce, 'bsp_delete_student' ) ) { die( 'Go get a life script kiddies' ); } else { self::delete_student( absint( $_GET['student'] ) ); wp_redirect( esc_url( add_query_arg() ) ); exit; } } // If the delete bulk action is triggered if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'delete' ) || ( isset( $_POST['action2'] ) && $_POST['action2'] == 'delete' ) ) { $delete_ids = esc_sql( $_POST['delete'] ); // loop over the array of record IDs and delete them foreach ( $delete_ids as $id ) { self::delete_student( $id ); } wp_redirect( esc_url( add_query_arg() ) ); exit; } } public static function bsp_delete_student($id){ global $wpdb; $wpdb->delete( "{$wpdb->prefix}students", [ 'students_id' => $id ], [ '%d' ] ); }
I’ve changed the code a couple of times for the delete function but I always get the same error message. Any help would be greatly appreciated.
- The topic ‘wp_list_table bulk action not working’ is closed to new replies.