Last active
October 24, 2020 12:17
-
-
Save YuvrajKhavad/b7d778d73e7febbe33a0c01d566841be to your computer and use it in GitHub Desktop.
code to delete user data from custom table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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