fix: repair site_admins after enabling multisite - #2512
Merged
Merged
Conversation
Playground's enableMultisite step leaves site_admins as an empty string
rather than the array( $admin_login ) core's populate_network() writes.
admin_user_id and admin_email come out correct, so the network install only
partially succeeds.
An empty value is worse than a missing one. Core falls back to a sane
default only when the option is absent:
get_site_option( 'site_admins', array( 'admin' ) )
Because the row exists as '', the default never applies and the empty string
reaches in_array():
TypeError: in_array(): Argument #2 ($haystack) must be of type array,
string given (wp-includes/capabilities.php)
That fatals is_super_admin(), grant_super_admin() and every manage_network_*
capability check, so any multisite suite touching network capabilities dies
inside core instead of failing usefully. Observed while getting
Extra-Chill/extrachill-network onto the managed harness; sitemeta showed
admin_user_id=1 and user 'admin' present alongside site_admins=''.
Adds a runPHP repair immediately after enableMultisite, mirroring the
existing enableMultisite + runPHP pattern in site-seed-multisite.ts. It is
idempotent and conservative: writes only when the value is not already a
non-empty array, and derives the login from admin_user_id rather than
assuming 'admin', falling back to the lowest-ID user.
Single-site recipes are unchanged.
The existing deepEqual asserted the exact two-step blueprint and so failed once the repair step was inserted. Rewritten to assert the contract rather than the literal array: enableMultisite first, the site_admins repair immediately after, and caller-supplied steps preserved in order behind them.
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.
Fixes #2511.
Problem
Playground's
enableMultisitestep leavessite_adminsas an empty string rather than thearray( $admin_login )core'spopulate_network()writes. Probed from inside the PHPUnit sandbox:The install only partially succeeds —
admin_user_idandadmin_emailare correct and the user exists.Why an empty value is worse than a missing one
Core falls back to a sane default only when the option is absent:
Because the row exists as
'', the default never applies. The empty string reachesin_array():This fatals
is_super_admin(),grant_super_admin(),revoke_super_admin()and everymanage_network_*capability check — so any multisite suite touching network capabilities dies inside core rather than failing usefully, which reads as harness breakage.Fix
A
runPHPrepair immediately afterenableMultisite, mirroring the existingenableMultisite+runPHPpattern already used insite-seed-multisite.ts.Idempotent and conservative:
admin_user_idrather than assuming'admin', falling back to the lowest-ID userTests
tests/playground-multisite-site-admins.test.tsasserts the repair step exists, runs afterenableMultisite, guards onis_array, derives fromadmin_user_id, and that single-site recipes carry no multisite steps.Existing
playground-runtime-multisiteandsite-seed-multisitesuites pass;npm run buildclean.Found via
Extra-Chill/extrachill-networkPR #217, which worked around it by setting\$GLOBALS['super_admins']in the affected test. That workaround can be removed once this ships.