Repository navigation
Make Two-Factor provider settings network-wide on Multisite - #1024
masteradhoc wants to merge 5 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 |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @Copilot. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@copilot resolve the merge conflicts in this pull request |
…k-provider-settings # Conflicts: # settings/class-two-factor-settings.php # two-factor.php Co-authored-by: masteradhoc <6242098+masteradhoc@users.noreply.github.com>
Resolved the merge conflicts and published the merge commit |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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