Support » Plugins » Hacks » how I remove user settings at the plugin uninstall process?

  • Hello,

    a plugin of mine stores user-specific settings in the usermeta table. If the plugin is uninstalled, I would like to delete this setting for all users. How is the right way to remove the settings for all users in the database? I found the function delete_usermeta, but this requires a UserID, so I would have to first determine all users and then go into a loop over it.
    What should I consider in the context of a MU installation?


Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    You could use $wpdb->query() to run a delete query of all records with your particular meta_key. I don’t know if this is the “right” way. It gets away from the need to loop through user IDs, but it can be very dangerous, there is no undo query. 🙂 If there is some accidental name collision, you could wreak havoc.

    There is no difference in usermeta tables between regular and MU versions, so there are no additional considerations I can see.

    You probably know this, but it’s worth noting, this should only be done on an uninstall hook, NOT the deactivation hook, and that it’s very clear to the user that uninstalling will forever delete these settings with no chance of recovery except by restoring the DB from an earlier backup.

    Yes, and uninstall is always system-wide. Then I can also delete a query and not all have to go in a loop over all users. So I’ll do it now 🙂

    Thank you


Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how I remove user settings at the plugin uninstall process?’ is closed to new replies.