Skip to content

Make "Delete subscribers" work on multisite - #229

Merged
cs1m0n merged 3 commits into
masterfrom
fix/delete-subscribers-multisite
Oct 14, 2026
Merged

cs1m0n merged 3 commits into
masterfrom
fix/delete-subscribers-multisite

Conversation

@cs1m0n

@cs1m0n cs1m0n commented Oct 14, 2026

Copy link
Copy Markdown
Member

Problem

"Delete subscribers" (Settings → BCC Login → Maintenance) built the users and usermeta table names from the site's table prefix. On a network those tables are shared by all sites:

  • On a subsite it queried wp_N_users, which doesn't exist, so nothing was deleted ("The subscribers could not be deleted").
  • On the main site it deleted every user whose only role on the main site was subscriber from the whole network, including users with roles on other sites.

Changes

It now uses $wpdb->users and $wpdb->usermeta, with this site's capabilities key.

  • Single site: unchanged, the subscribers' accounts are deleted.
  • Network:
    • Subscribers who have a role on another site, or are listed there without one, keep their account and only leave this site, as when WordPress removes a user from a site. The others are deleted.
    • Only network administrators can delete accounts on a network. When a site administrator presses the button, subscribers only leave the site.
    • Network administrators are left alone, whatever their role on the site.
    • With OIDC_CREATE_USERS on, nobody only leaves a site. The login can't add an existing account back to a site, so those users couldn't log in there again. They're kept until their account can be deleted, and the message says so.
  • If a lookup query fails, nothing is changed and the error notice is shown. Accounts are deleted before anyone leaves the site, so if deleting fails they're still subscribers and pressing again finds them.
  • A note under the button explains the network behaviour.

Testing

In throwaway WordPress 7.0.2 sites on PHP 7.4:

  • Single site: subscribers (including the plugin's own bcc-login-subscriber) are deleted with their meta. The administrator, the editor and bcc-login-member stay. The message is unchanged. When the lookup fails, nothing changes and the error is shown.
  • Network of two sites:
    • The site administrator of site two removed its subscribers from that site without deleting any account, and left a network administrator who was a subscriber there alone.
    • The network administrator on the main site deleted the subscribers with no other role. A user who is an editor on site two only left the main site.
    • With OIDC_CREATE_USERS on, the network administrator deleted the subscribers with no other site and kept the two who also belong to site two. The site administrator kept everyone.
    • When the membership query fails, nothing changes and the error is shown.

PHPStan with the CI config passes, and php -l passes on PHP 7.4 and 8.4.

🤖 Generated with Claude Code

It used the site's table prefix for the users and usermeta tables, which
on a network are shared: on a subsite the query failed, and on the main
site it deleted users who still had roles on other sites. Now subscribers
who belong to another site only leave this site, network administrators
are left alone, and only a network administrator deletes accounts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@cs1m0n
cs1m0n requested a balanced review from Copilot October 14, 2026 08:39
@cs1m0n cs1m0n self-assigned this Oct 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Raw database deletion bypasses WordPress user-removal lifecycles and can leave inconsistent metadata, content, caches, and integrations.

2 open findings
What changed in this PR

Updates subscriber maintenance for WordPress multisite installations.

Changes:

  • Uses shared network user tables and site-specific capabilities.
  • Distinguishes account deletion, site removal, and retained users.
  • Adds multisite-specific notices and reporting.
File Description
plugins/​bcc-login/​includes/​class-bcc-login-settings.php Implements multisite subscriber lookup, deletion, removal, and messaging.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread plugins/bcc-login/includes/class-bcc-login-settings.php
Comment thread plugins/bcc-login/includes/class-bcc-login-settings.php
cs1m0n and others added 2 commits October 14, 2026 12:00
- After deleting or removing subscribers, their id, login, slug, email and
  meta caches are cleared and cached user queries are invalidated, as
  clean_user_cache() does. Deleting stays in bulk, as before this change,
  and that choice is now documented on delete_users().
- With OIDC_CREATE_USERS on, the note under the button now says that
  subscribers who belong to another site are kept.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@cs1m0n
cs1m0n merged commit 579801a into master Oct 14, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants