#12028 closed defect (bug) (fixed)
wpmu_create_blog() breaks with multiple use
Reported by: | wpmuguru | Owned by: | |
---|---|---|---|
Milestone: | 3.3 | Priority: | high |
Severity: | normal | Version: | |
Component: | Multisite | Keywords: | has-patch |
Focuses: | Cc: |
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)
#2
@
15 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.
#4
@
14 years ago
- 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.
#5
@
13 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
#7
@
13 years ago
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.
#10
@
13 years 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.
#11
@
13 years 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.
Patch for wpmu-functions.php