1

Is it possible to remove an user from within the back-end including all data related to this user even from custom tables?

I used the add_action( 'delete_user', 'my_delete_user' ); hook and also execute a delete query to delete data from a custom table (related to that user) but only data from the user and user_meta table is deleted, not from the custom table.

I would like to be able to delete all data related to an user.

  • Could you add the function into your question so we get an idea. Maybe there is something else in the function which holds it back from doing what it should do? – Charles Oct 6 '16 at 10:16
  • @Charles: thanks for reply i have resolved this issue by same hook. – sameer sheikh Oct 6 '16 at 10:24
  • Hey thats great, could you add an answer include working code for later reference for other users? – Charles Oct 6 '16 at 10:27
  • @Charles : see my working code. – sameer sheikh Oct 6 '16 at 10:45
3

Hello guys!

i resolved this issue by using same hook add_action( 'delete_user', 'my_delete_user' );

here is my code

<?php

function my_delete_user( $user_id ) {
    global $wpdb;
    $user_obj = get_userdata( $user_id );

    $id_user = $user_obj->ID;
    $idsss = $user_obj->user_id;


    /*Delete Data from friend table*/  
    $query_friend= $wpdb->query("DELETE FROM `wp_user_friends` where `friend_id` = ".$user_obj->ID."");

    /*delete data from group*/
    $delete_group_table =$wpdb->query("DELETE FROM `wp_group` where `user_id` = ".$user_obj->ID."");


}
add_action( 'delete_user', 'my_delete_user' );
?>

Now it's working perfect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.