Skip to content

Instantly share code, notes, and snippets.

@YuvrajKhavad
Last active October 24, 2020 12:17
Show Gist options
  • Save YuvrajKhavad/b7d778d73e7febbe33a0c01d566841be to your computer and use it in GitHub Desktop.
Save YuvrajKhavad/b7d778d73e7febbe33a0c01d566841be to your computer and use it in GitHub Desktop.
code to delete user data from custom table.
function zi_delete_user( $user_id )
{
global $wpdb;
// get user details base on user id
$user_obj = get_userdata( $user_id );
// Array of all tables
$tables = array('wp_zi_answer', 'wp_zi_answer_interventions_basic', 'wp_zi_daily_answer', 'wp_zi_goal_basic', 'wp_zi_lifestyle_answer', 'wp_zi_setting');
foreach($tables as $table)
{
// Delete all data have deleted user id
$query_zi_table = $wpdb->query("DELETE FROM `user_id` where `user_id` = ".$user_obj->ID."");
}
}
add_action( 'delete_user', 'zi_delete_user' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment