Purging Inactive Users

Hello,
I hope you are doing well and that you can help me with this issue. My community site swirlonthru.com is fast approaching 10,000 users. I know for a fact that at least 3,000 of those users were auto generated from a mailing list and have never logged in. I would like to go back a year and delete all users that show up as never having logged in. What is the best way to do this. Is there a msql query that could acheive this without tearing the site in two. As it stands the site is impossible to move. I tried exporting one of my backups and only half of the database made it.

This brings me to step 2 of my goal. We'd like to upgrade the theme, Is there a way we could reset wordpress except for the users, images, and buddypress. Wipe the slate clean and install the completed theme on a fresh install?
I dont know the best way to proceed. The other thought I had was take advatage of the new buddypress restful api and get someone to programatically get all the data. But whatever I do I feel like it will be out of our budget, or out of my skillset.

:slight_frown: Thanks in advance.

  • Adam Czajczyk
    • Support Gorilla

    Hello KeepitFabulous

    II hope you're well today!

    WordPress doesn't store anything like "last login" or similar information about users by default. In theory, some sort of indication could be the value of activation code stored in database but that's unreliable because

    - user might have been added manually to the site or in some way (e.g. via some plugin) that this activation code wasn't ever reset
    - user might have actually activated account and even use the site for some time but then stopped

    Unless user logins are specifically tracked, on purpose, there's no reliable way for such "automated" clean-up.

    However, you're running BuddyPress on site so that is a good news because BuddyPress does log "latest activity". This would be useful.

    That said, I'm not that good with complex SQL queries (and it would be quite complex) so I'd rather go for PHP with this. There's a nice piece of code to "check with BuddyPress if user is online" that could be a good foundation:

    https://tannermoushey.com/2015/05/determine-if-a-user-is-online-in-buddypress/

    I'd look into doing this:
    - setting the timeframe in that code to much longer period (e.g. entire year)
    - looping through all users in DB, checking with this or similar function if they were "active" within that timeframe
    - if it shows they were not active - either delete them or mark them somehow for deletion (add some _usermeta value that could later be used to cycle through users again to delete them; that's just for safety as deletion is irreversible without db backup).

    This seems doable and shouldn't even be that complex "code wise" except for one additional thing. From what you said, I understand that there's a problem with creating full backup and there's a huge amount of user accounts. In such case such code wouldn't work well if it was just a PHP loop but it rather should be something run either using AJAX or even based on WP cron.

    Using some SQL query might be much faster but with that amount of users it still might not be fast enough and it doesn't leave ANY "safe space" for any errors. So, in the end, I'd rather go the "code way" though I'm afraid it goes a bit too far into custom development and providing such code would be outside the scope of this support.

    However, I believe this way it would be doable.

    As for your second goal. By "reset" you mean like - "fresh install" (so no content, no plugins, default configuration etc) but with all the user accounts, including BuddyPress data, and with all the images?

    it's not that simple, I'm afraid. I'd try one of these things though: setup a clean WordPress separately to the current site and do theme (and other plugins') install and configuration there and then try export users from original site and import them to the new one.

    There's a set of plugins for that that could help (export and import):

    https://wordpress.org/plugins/members-import/

    though I admit I never tested them. But export is a "non-destructive" process and testing import on a fresh, separate site would be rather safe so I think it's worth giving a try. Other than this, the API would be probably the best way to go - though it would require custom coding as well.

    As for media (images) - those can be exported/imported using standard WP import/export tools.

    Best regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.