Opened 4 months ago
Closed 4 months ago
#23400 closed defect (bug) (fixed)
insert_blog() can possible return the wrong blog id when plugin/theme uses refresh_blog_details action
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.6 |
| Component: | Multisite | Version: | 3.0 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: |
Description
The function insert_blog() returns $wpdb->insert_id after calling refresh_blog_details(). So if a plugin or theme is using the refresh_blog_details action and does something that changed $wpdb, the returned blog id will be wrong and WordPress creates table names with the wrong id in their name.
I understand if this isn't considered a bug. But I've attached a suggested patch anyway. I think it would be good.
Attachments (2)
Change History (7)
feedmeastraycat
— 4 months ago
comment:1
nacin
— 4 months ago
- Keywords has-patch commit added
- Milestone changed from Awaiting Review to 3.6
comment:2
SergeyBiryukov
— 4 months ago
- Component changed from General to Multisite
- Version changed from trunk to 3.0
comment:3
feedmeastraycat
— 4 months ago
I uploaded insert-blog-bug.php that is a plugin that duplicates the error.
Warning
Only run this on a clean install. To duplicate the error I truncate wp_posts and then changes the auto increment value to 100. This way, when a post is inserted it gets id 100 and the error is shown with insert_blog() returning 100 instead of the newly created actual blog id 2.
Test it by creating a multi site install and then visiting http://your-test-site.com/?action=testbug - It will output "Created blog id: 100" if the bug was visible. If there is an error the WP_Error object us output using var_dump().
This is a screenshot of my tables after running the plugin.
This is a screenshot of the Sites panel in network admin.
Running it will my patch creates everything ok.
Looks proper to me.