array key: process_link_actions
redirects and exits on execution
The process_link_actions
callable executes on list table construction and is designed to use query string values including a test value to invoke execution. If this test value is not set this callable should do nothing. If the test value is set the link action; usually delete, trash or edit, is executed and there is a redirect without this test value causing process_link_actions to then do nothing. On redirect usually some values, such as pagination or view should be specified. The sample code works from the query string so the test value that causes execution must be intentionally removed before redirect or the list table will redirect endlessly on construction. Note that this callable work directly from the links specified in the actions list table definition value.
$list_table_definitions['process_link_actions'] = 'saturn_tables_cars_process_link_actions';
function saturn_table_cars_process_link_actions() { global $wpdb; if ( (isset($_GET['delete_id']) && $delete_id = (int)$_GET['delete_id']) > 0) { $model = $wpdb->get_var("SELECT model FROM saturn_tables_cars WHERE id = $delete_id"); $wpdb->delete( 'saturn_tables_cars', array('id' => $delete_id), array('id' => '%d')); //redirect without delete_id parse_str($_SERVER['QUERY_STRING'], $query_string); unset($query_string['delete_id']); $query_string['delete'] = $model; $query_string['status'] = "trash"; $redirect = admin_url() . "?" . http_build_query($query_string); wp_redirect( $redirect ); exit; } elseif ( isset($_GET['trash_id']) && ($trash_id = (int)$_GET['trash_id']) > 0) { $model = $wpdb->get_var("SELECT model FROM saturn_tables_cars WHERE id = $trash_id"); $wpdb->update( 'saturn_tables_cars', array('status' => 1), array('id' => $trash_id), array('%d'), array('%d') ); //redirect without trash_id parse_str($_SERVER['QUERY_STRING'], $query_string); unset($query_string['trash_id']); $query_string['trash'] = $model; $redirect = admin_url() . "?" . http_build_query($query_string); wp_redirect( $redirect ); exit; } elseif ( isset($_GET['restore_id']) && ($restore_id = (int)$_GET['restore_id']) > 0) { $model = $wpdb->get_var("SELECT model FROM saturn_tables_cars WHERE id = $restore_id"); $wpdb->update( 'saturn_tables_cars', array('status' => 0), array('id' => $restore_id), array('%d'), array('%d') ); //redirect without trash_id parse_str($_SERVER['QUERY_STRING'], $query_string); unset($query_string['restore_id']); $query_string['restore'] = $model; $query_string['status'] = "trash"; $redirect = admin_url() . "?" . http_build_query($query_string); wp_redirect( $redirect ); exit; } }