WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] how I remove user settings at the plugin uninstall process? (3 posts)

  1. Frank Staude
    Member
    Posted 1 year ago #

    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?

    greetings
    frank

  2. bcworkz
    Member
    Posted 1 year ago #

    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.

  3. Frank Staude
    Member
    Posted 1 year ago #

    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

    greeting
    frank

Topic Closed

This topic has been closed to new replies.

About this Topic