Fix wp core update-db --network to respect network ID in multinetwork installations#302
Open
Fix wp core update-db --network to respect network ID in multinetwork installations#302
wp core update-db --network to respect network ID in multinetwork installations#302Conversation
Add site_id filtering to ensure only sites from the current network are updated when using --network flag. This allows proper operation in multinetwork WordPress installations when combined with --url parameter. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Add a simple test to verify that SITE_ID_CURRENT_SITE is properly defined in multisite installations, which is used by the update-db command to filter sites by network. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix wp core update-db for multiple networks
Fix Nov 7, 2025
wp core update-db --network to respect network ID in multinetwork installations
swissspidy
reviewed
Nov 8, 2025
Include WordPress downgrade, database version downgrade, site creation, and verification of the actual update-db command execution and success. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Since all blogs are filtered by site_id = network_id, there's no need to collect and deduplicate site_ids. Directly use network_id for the metadata update. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
wp core update-db --network to respect network ID in multinetwork installationswp core update-db --network to respect network ID in multi-network installations
- Fix update_db to call get_current_network_id() first (WP 4.9+) so that the --url parameter actually determines the target network. Previously, SITE_ID_CURRENT_SITE (always 1 in wp-config.php) was checked first, making the fallback to get_current_network_id() unreachable. - Replace the simplistic scenario with a proper two-network setup: creates sites in both networks, verifies the primary network run only upgrades its 3 sites, then verifies --url targets network 2 and upgrades its 2 sites. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Copilot
AI
changed the title
Fix
Fix Mar 10, 2026
wp core update-db --network to respect network ID in multi-network installationswp core update-db --network to respect network ID in multinetwork installations
This comment was marked as resolved.
This comment was marked as resolved.
Two bugs in the previous test: 1. Wrong domain: network 2 was created with domain=localhost but the Behat test environment installs WordPress at https://example.com. 2. URL routing doesn't work: DOMAIN_CURRENT_SITE is a PHP constant hardcoded in wp-config.php, so WordPress skips the DB lookup entirely and get_current_network_id() always returns SITE_ID_CURRENT_SITE (1) regardless of --url. The --url=localhost/net2-site1/ approach could never route to network 2. Fix: create network 2 with domain=example.com, move 2 blogs to it, then swap SITE_ID_CURRENT_SITE from 1 to 2 in wp-config.php before the second run. This correctly puts WordPress into network 2 context so the command processes only the 2 network-2 sites. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Member
|
@copilot still failing, the update appears to be running on 3 sites, not 2. |
The wp-config.php SITE_ID_CURRENT_SITE swap approach cannot change the network context because WordPress also reads BLOG_ID_CURRENT_SITE=1 (hardcoded, can't be changed without knowing the network-2 blog ID), and since blog 1 belongs to network 1, WordPress overrides $current_site back to network 1 regardless of SITE_ID_CURRENT_SITE. Instead, verify the site_id filter works by: 1. Creating 5 active sites (3 in network 1, 2 in network 2) 2. Running wp core update-db --network and asserting "3/3 sites" not "5/5" 3. Asserting that net2-site1 URL is absent from output This is a true regression test: without the site_id filter the old code would have processed all 5 sites (5/5), and network-2 URLs would appear. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
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.
get_current_network_id()to be called firstRoot cause of the persistent CI failure
The
SITE_ID_CURRENT_SITEconstant swap inwp-config.phpcannot change the active network context becausewp-config.phpalso hardcodesBLOG_ID_CURRENT_SITE=1. During the WordPress multisite bootstrap,ms_load_current_site_and_network()detects that blog 1'ssite_id(1) does not match theSITE_ID_CURRENT_SITEvalue (2) and overrides$current_siteback to network 1.get_current_network_id()therefore always returns 1, regardless of theSITE_ID_CURRENT_SITEchange.New test strategy
Rather than switching network context (which requires changing both
SITE_ID_CURRENT_SITEandBLOG_ID_CURRENT_SITEto values we don't know statically), the test proves the filtering works by:3/3not5/5: Without thesite_idfilter, the old code would process all 5 active sites (5/5). Seeing3/3proves the filter is active.net2-site1absent from STDOUT: Explicitly proves the network-2 site was not touched.This is a valid regression test for the fix: it would fail on the un-patched code.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.