Repository navigation
Make Two-Factor provider settings network-wide on Multisite - #1024
Draft
masteradhoc wants to merge 2 commits into
Draft
masteradhoc wants to merge 2 commits into
masteradhoc wants to merge 2 commits into
Conversation
On Multisite, the enabled providers are now a network option managed by super admins under Network Admin → Settings → Two-Factor, and they apply to every site. Sites show the selection read-only. The main site's saved selection is carried over once; values saved on other sites are ignored. Single site installs are unchanged.
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
Closed
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.
What?
On Multisite, the "Enabled Providers" setting becomes network-wide and can only be changed by super admins, under Network Admin → Settings → Two-Factor. Each site's Settings → Two-Factor shows the network selection read-only. Single site installs are unchanged.
Fixes #894
Supersedes #915
Why?
A user's two-factor configuration is network-wide (user meta), and signing in through any site of a network gives a session that is valid across the network. The enabled-providers setting, however, was stored per site and could be changed by each site's administrators. On Multisite this made the providers that count for an account depend on the site it signs in through, and a per-site restriction didn't really restrict anything, since the user could sign in through another site.
This is how we want to solve #894, so this PR supersedes #915. #915 keeps the per-site settings in effect until a network selection is saved, and offers an optional "subsites may narrow the list" override; both keep the per-site dependency described above. Here the setting is network-only: there is no per-site override, and per-site values are ignored on Multisite. Requiring two-factor for roles (also suggested in #894) isn't part of this PR; that's tracked in #255.
Thanks to @faisalahammad for #915: the empty-selection guard, the validation of submitted provider keys and the read-only view for sites are adapted from it.
How?
Two_Factor_Core::get_enabled_providers_policy(),update_enabled_providers_policy()andpolicy_capability(): a network option (two_factor_enabled_providersin sitemeta) andmanage_network_optionson Multisite; the regular option andmanage_optionson single site, as before.two_factor_get_enabled_providers_option()stays as a thin wrapper for existing callers.two_factor_add_network_settings_page()), saved throughedit.php?action=two_factor_settingsbyTwo_Factor_Settings::save_network_settings(): capability and nonce checks; only registered providers are kept, including ones the current selection disables; an empty selection is refused, since it would lock every user with two-factor out of the whole network.manage_options, but on Multisite it is read-only (Two_Factor_Settings::render_network_managed_page()), with a link to the network page for super admins. It never saves.two_factor_enabled_providers_migratednetwork option. Selections saved on other sites don't carry over and no longer apply.AGENTS.md,TESTS.md.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5 Max
Used for: implementing the change, the tests and the docs from my specification; I reviewed the changes and made the design decisions.
Testing Instructions
Multisite (plugin network-activated)
master, save one selection on the main site's Settings → Two-Factor and a different one on a subsite. Switch to this branch: the network page shows the main site's selection, and the subsite's selection has no effect anymore (its page and the providers offered when signing in through it match the network selection).Single site (no multisite)
6. Settings → Two-Factor works as before.
Screenshots or screencast
Changelog Entry