Repository navigation
Clean up the user meta of deleted users daily - #225
Merged
Merged
Conversation
Older versions of "Delete subscribers" removed only the users row and the role row of each subscriber, so sites that used it still have the rest of those users' meta, including their names and session tokens. The daily cleanup task now also deletes the meta of users that no longer exist. It only deletes users that were already missing at its previous run, at least 12 hours earlier: a database import loads wp_usermeta before wp_users, so while one is running every user seems to be missing. The "Delete subscribers" button uses the same function and still deletes immediately. Its notice no longer reports success when deleting the subscribers failed. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Snapshot write failures and incomplete cache invalidation can leave cleanup state or deleted users stale.
2 open findings
What changed in this PR
Adds delayed daily cleanup of orphaned user metadata and reuses it for subscriber deletion.
Changes:
- Tracks missing users for at least 12 hours before cleanup.
- Deletes orphaned metadata in batches and clears caches.
- Improves maintenance-action failure notices.
| File | Description |
|---|---|
class-bcc-login-settings.php |
Reuses cleanup logic and improves notices. |
class-bcc-login-cleanup.php |
Adds delayed, batched orphan-meta cleanup. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- The daily cleanup only deletes once its list of missing users is saved, so the next run never compares against an older list. - "Delete subscribers" removes the deleted subscribers from the object cache directly. The leftover cleanup only finds users that still have meta, which isn't the case if the role was their only meta row. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Older versions of Delete subscribers removed only the users row and the role row (
wp_capabilities) of each subscriber. Sites that used it still have the rest of those users' meta: names, nicknames, session tokens, preferences and plugin data.Changes
BCC_Login_Cleanup, from Clean up data left behind by the old OpenID Connect Generic plugin #224) now also deletes the meta of users that no longer exist, through a newdelete_orphaned_user_meta().Why the task waits a day
A database import (restore, push between environments) loads
wp_usermetabeforewp_users, so while it runs, every user looks deleted. In tests, a version that deleted in a single run removed every user's meta, roles included, when it ran during an import without table locks.So the task only deletes the meta of users that were already missing at its previous run, at least 12 hours earlier. An import lasts minutes, and WP-Cron running the task twice in a row happens within seconds. Leftovers are removed on the second daily run after the update. The button still deletes immediately.
Notes for review
DELETE … LEFT JOINover the whole table.user_id 0rows are left alone, because WordPress never stores meta for user 0.bcc_login_missing_users, which isn't autoloaded.wp_usermetaandwp_usersloading, during an import of an older database in which yesterday's leftovers are still real users. Those users then lose their meta. Closing this would need a role-row check, which became very slow right after an import (a full scan per user while InnoDB statistics are empty).Testing
Throwaway WordPress 7.0.2 / PHP 7.4 / MariaDB 10.5 with 3,000 users and about 65,000 meta rows. The data included 500 users' leftovers, users without a role row, and users whose role row is stored last.
🤖 Generated with Claude Code