Repository navigation
Secondary networks: sunrise queries unregistered scoped tables, and wu_{N}_* tables are never created #2012
Description
Problem
On a multi-network install, Ultimate Multisite queries network-scoped tables ({base_prefix}wu_{network_id}_*) on secondary networks, but two paths leave those tables unusable:
-
Sunrise domain mapping queries tables that were never registered.
Sunrise::load_domain_mapping()(inc/class-sunrise.php:191-205) startsDomain_Mappingon every network. On a network where Ultimate Multisite returns beforesetup_tables()(inc/class-wp-ultimo.php, theRequirements::met() === false || Requirements::run_setup() === falseearly return;run_setup()reads the per-networkwu_setup_finishedoption), noTableobject is built for that network. The domainQuerystill applies the network prefix (Network_Prefix::update_prefix_with_network_id(),inc/database/engine/traits/trait-network-prefix.php:20-25), so it reads$wpdb->wu_{N}_domain_mappings. That property is unset, which gives an empty table name:Table '<db>.wu_5_d' doesn't exist for query SELECT wu_5_d.id FROM wu_5_d WHERE wu_5_d.blog_id = 323 AND wu_5_d.domain != ...Note the double space: the table name is empty and only the alias
wu_5_dremains. Production logged about 170 of these in 7 hours on one template network. -
Secondary-network tables are never created.
Table::is_upgradeable()(inc/database/engine/class-table.php:50-57) returns false unless the request is on the main network and main site, somaybe_upgrade()never installswp_wu_{N}_*. A network ends up with none of these tables, or with only the subset some one-off path created. One network had customers/memberships/payments but noposts,postmeta,webhooks,passkey_credentials,webauthn_challenges,email_otp_attemptsorsso_nonces. Addon tables that extend the coreTable(e.g. metered-plans'metered_usage) inherit the same gap. A missingpoststable also means a network has no system emails (payment_received_*,site_published_*, …).
Expected
- Every secondary network that Ultimate Multisite serves has its full set of scoped tables, created idempotently when the network is first used or created, and on upgrade.
- Domain mapping at sunrise never builds a query against an unregistered table. Either register the network's tables (e.g. build the needed
Tableobjects inSunrise::load_domain_mapping()beforeDomain_Mappingruns), or fall back to the main network's tables when Ultimate Multisite is not set up on the current network. - Default system emails get created for a network once its
poststable exists.
Workaround applied on one install (not a fix)
Ran in each affected network's --url context:
$t->install()for everyTable_Loader::get_instance()->get_tables()entry, plusMetered_Usage_Table, whereexists()was false.Email_Manager::get_instance()->create_all_system_emails().- For the template network, set the
wu_setup_finishednetwork option so Ultimate Multisite completes loading and registers its tables.
Note: Table::exists() caches its result, so in the same process it still reported false right after a successful install(). A fresh process or information_schema showed the tables were present.
Files to modify
inc/class-sunrise.php(load_domain_mapping)inc/database/engine/class-table.php(is_upgradeable, and possibly theexists()cache)inc/installers/class-core-installer.php(network-scoped install)inc/loaders/class-table-loader.phpinc/managers/class-email-manager.php(create_all_system_emailson new networks)
Verification
On a multi-network test install:
- Create a secondary network without running the setup wizard and request one of its mapped domains. There should be no
FROM wu_N_(empty table) errors. - Every
get_tables()entry shouldexists()for that network after creation or upgrade. wu_get_emails()should return the default system emails on that network.
Files Scope
inc/class-sunrise.phpinc/database/engine/class-table.phpinc/installers/class-core-installer.phpinc/loaders/class-table-loader.phpinc/managers/class-email-manager.phptests/WP_Ultimo/Database/Engine/Table_Test.phptests/WP_Ultimo/Managers/Email_Manager_Test.php
aidevops.sh v3.39.49 plugin for OpenCode
Activity
superdav42 commentedon Oct 21, 2026
DISPATCH_CLAIM nonce=a50fd5e1f314c84f826f2aa01722ab19 runner=superdav42 ts=2026-10-21T15:19:36Z max_age_s=1800 version=3.39.49 opencode_version=1.18.31 lease_token=a50fd5e1f314c84f826f2aa01722ab19 device=device-1783824528-2609248-26808 session=issue-2012 phase=prelaunch expires_at=1792596098
superdav42 commentedon Oct 21, 2026
DISPATCH_LEASE phase=prelaunch lease_token=a50fd5e1f314c84f826f2aa01722ab19 device=device-1783824528-2609248-26808 session=issue-2012 expires_at=1792596444 ts=2026-10-21T15:19:54Z attempt_id=attempt:5d33ba6b-18fb-48eb-87c5-0ddfb5206c88
superdav42 commentedon Oct 21, 2026
Dispatching worker (deterministic).
superdav42 commentedon Oct 21, 2026
DISPATCH_LEASE phase=ready lease_token=a50fd5e1f314c84f826f2aa01722ab19 device=device-1783824528-2609248-26808 session=issue-2012 expires_at=1792603240 ts=2026-10-21T15:20:40Z attempt_id=attempt:5d33ba6b-18fb-48eb-87c5-0ddfb5206c88
aidevops.sh v3.39.49 automated scan.
7 remaining items
superdav42 commentedon Oct 22, 2026
DISPATCH_CLAIM nonce=65099c0ff81aef1f1aa95b215fdb6324 runner=superdav42 ts=2026-10-22T16:22:58Z max_age_s=1800 version=3.39.49 opencode_version=1.18.31 lease_token=65099c0ff81aef1f1aa95b215fdb6324 device=device-1783824528-2609248-26808 session=issue-2012 phase=prelaunch expires_at=1792686301
superdav42 commentedon Oct 22, 2026
DISPATCH_LEASE phase=prelaunch lease_token=65099c0ff81aef1f1aa95b215fdb6324 device=device-1783824528-2609248-26808 session=issue-2012 expires_at=1792686648 ts=2026-10-22T16:23:18Z attempt_id=attempt:5f8ed951-2070-4737-baf3-5699fd22b715
superdav42 commentedon Oct 22, 2026
Dispatching worker (deterministic).
superdav42 commentedon Oct 22, 2026
DISPATCH_LEASE phase=ready lease_token=65099c0ff81aef1f1aa95b215fdb6324 device=device-1783824528-2609248-26808 session=issue-2012 expires_at=1792693444 ts=2026-10-22T16:24:04Z attempt_id=attempt:5f8ed951-2070-4737-baf3-5699fd22b715
aidevops.sh v3.39.49 automated scan.
superdav42 commentedon Oct 22, 2026
CLAIM_RELEASED reason=worker_complete runner=superdav42 ts=2026-10-22T16:33:23Z aidevops_version=3.39.49 opencode_version=1.18.31
aidevops.sh v3.39.49 plugin for OpenCode v1.18.31
superdav42 commentedon Oct 22, 2026
DISPATCH_LEASE phase=terminal lease_token=65099c0ff81aef1f1aa95b215fdb6324 device=device-1783824528-2609248-26808 session=issue-2012 expires_at=0 ts=2026-10-22T16:33:39Z attempt_id=attempt:5f8ed951-2070-4737-baf3-5699fd22b715
aidevops.sh v3.39.49 automated scan.