I am using the Custom List Table Example plugin as a basis to create my own custom list table. Everything is great, except one thorny point.
When I am processing bulk actions via the process_bulk_action()
method, I would like to redirect using wp_redirect()
. Here is an example:
function process_bulk_action() {
// Some security check code here
// Get the bulk action
$action = $this->current_action();
if ($action == 'bulk_trash') {
// Code for the "delete process"
// Assuming "delete process" is successful
wp_redirect("http://url/path.php?update=1&message=some_message");
exit;
}
}
Please note, in the call wp_redirect("http://url/path.php?update=1&message=some_message")
, I am trying to redirect to the same page that displays the list table in order to reload it with the result of the trash process. Also note that there is a message
in the path that allows me to display a notification to the user regarding the result of the bulk action.
The problem is, I get an error message Cannot modify header information - headers already sent by <file path>
.
I understand what the message means, and the reasons behind it (the page is already loaded and cannot be redirected). However, how do I redirect then if I would like to do that after I process the bulk action? If redirect is not the correct solution, what other options do I have that allow me to re-load the custom wp_list_table
again so that the listed records reflect items being deleted (i.e., less published items, and more items in trash)?
Thanks.