• I’m creating a system with data in non-wp tables linked to a user. Is there a way I can prevent (through use of a hook maybe) a user from being deleted if data exists in these tables for a given user?

    I saw there was a delete_user hook, but I’m not user it will accomplish what I’m after.

    Will something like this work?

    function foo($user_id) {
      if (user_has_data($user_id))
        return false; //i.e. prevent user deletion
      return true;
    }
    
    add_action('delete_user', 'foo');
Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Spencer,

    What are you trying to accomplish exactly? Are you trying to repopulate WP user data with a non-WP user DB? If so, does each WP user need to be logged in for the data to be retrieved or are you doing it globally?
    Please provide me with a little more information about what you’re trying to accomplish, and I’ll try to give you a hand.

    Thread Starter spencersokol

    (@spencersokol)

    Basically, I’m building a plugin. I want to use WP for all user management. However, I have data in other tables in the WP database that I want linked to specific users (i.e. the WP user id is a foreign key for some of these tables) and I don’t want users deleted who have data in these extra tables. I have an interface for users with a custom WP capability to manage this data from within the WP admin area.

    So, basically, I need a way to stop WP from deleting a user if data exists in my external tables.

    In my case, it doesn’t make sense to attribute this data to another user upon deletion of a user, nor does it make sense to simply delete the data associated with a given user.

    Hopefully that helps explain it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Prevent the deletion of a user’ is closed to new replies.