#12028 closed defect (bug) (fixed)
wpmu_create_blog() breaks with multiple use
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | high | Milestone: | 3.3 |
| Component: | Multisite | Version: | |
| Severity: | normal | Keywords: | has-patch |
| Cc: | westi, zane@… |
Description
MU Trac Ticket: http://trac.mu.wordpress.org/ticket/394
When using wpmu_create_blog() in wpmu-functions.php it will only work once. If called additional times the blog will be added to the wp_blogs table but its tables will not be created, resulting in an invalid state. This is caused by $wp_queries being set in-line in upgrade-schema.php while it must be updated before the second call to wpmu_create_blog(). This is solved by moving the initialization of $wp_queries into a function and calling it just before the tables are created (diff file attached).
Attachments (5)
Change History (21)
jpotkanski — 3 years ago
comment:2
jpotkanski — 3 years ago
I reviewed the original patch, which was a significant architecture change. Our patch can be use in the interim as a workable hack.
- Cc westi added
- Keywords needs-patch added
- Priority changed from normal to high
Neither of the attached patches is a good idea.
Better to wrap the query generation in a function so it can be called more than once and preserve the setting of the global.
comment:5
zaneselvans — 2 years ago
- Cc zane@… added
I think I ran into this same issue recently when attempting to create new blogs in a network installation. I don't know why $wp_queries wasn't getting updated to reflect the new blog_id and table prefixes... the values inside $wpdb were correct. I ended up temporarily creating a wrapper function around a copy of the table creation statements from schema.php so I could get the new blogs set up, but it wasn't something I wanted to leave that way. Notes from the experience are visible in the multi-site support forum: https://wordpress.org/support/topic/db-tables-for-new-subdomain-site-fail-to-get-created?replies=29
Renamed the function to wp_get_db_schema() per IRC discussion. Added a scope arg which is very similar to the one for wpdb::tables(). Grouped table SQL by scope. Changed install_blog() to pass a scope of 'blog' so that it no longer uselessly and dangerously sends user and usermeta tables through dbDelta() for every blog created.
comment:10
ryan — 20 months ago
Renames WP_NETWORK_ADMIN_PAGE to WP_INSTALLING_NETWORK and uses that to reliably determine if multisite in wp_get_db_schema(). This allows more exactly copying the wpdb:tables() API. Switched to a switch as seen in tables() for readability.
comment:11
nacin — 20 months ago
A quick grep of the plugins directory reveals 1588 references to $charset_collate. While many of these are surely going to be plugin-defined local variables, I found it specifically globalized in 3 different plugins. I imagine a number may also be using it in procedural, globally scoped code.
comment:12
nacin — 20 months ago
dbDelta()'s repetitive statements could probably be simplified to:
if ( in_array( $queries, array( '', 'all', 'blog', 'global', 'ms' ), true ) )
$queries = wp_get_db_schema( $queries );
comment:13
ryan — 20 months ago
In [18899]:
comment:14
ryan — 20 months ago
The commit incorporates nacin's last two comments.
comment:15
ryan — 20 months ago
- Resolution set to fixed
- Status changed from new to closed
comment:16
dd32 — 19 months ago
In [18986]:

Patch for wpmu-functions.php