Delete data from database using row action
I have little problem how implement deleting data from database using row actions. I have my custom list which includes data from database table.
function column_name( $item ) {
$delete_nonce = wp_create_nonce();
$title = 'strong' . $item['article_name'] . '/strong';
$actions = [
'edit' = sprintf('a href=?page=%sid=%sEdit/a', 'edytuj-artykul', $item['article_id']),
'delete' = sprintf('a href=?page=%saction=%sarticle_id=%s_wpnonce=%sDelete/a', esc_attr( $_REQUEST['page'] ), 'delete', absint($item['article_id']), $delete_nonce)
];
return $title. $this-row_actions( $actions );
}
function delete_article($item){
$article_id = $item['article_id'];
global $wpdb;
$table = 'wp_copywriter_articles';
$wpdb-query(DELETE FROM $table WHERE article_id = %d, $article_id);
}
In the same file I added
add_action( 'admin_action_delete', 'delete_article' );
When I click Delete action, nothing happend. I got link http://localhost/wordpress/wp-admin/admin.php?page=Artykulyaction=deletearticle_id=26_wpnonce=60a01b82d7
but record is not deleted from database.
For testing, I added a specific ID number of article to the delete_article method in the SQL query but still not works, so this method is not used by WP, when I click delete button.
Someone can give me any tip what am I doing wrong, because I spent on this few few hours :)
Best Regards, Bartek
@EDIT
SOLVED
My mistake was put delete_article() method to my custom list class. When I put my method to functions.php, everything works! :)
Topic row-actions actions plugin-development database Wordpress
Category Web