Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years 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: feedmeastraycat's profile feedmeastraycat Owned by: nacin's profile nacin
Milestone: 3.6 Priority: normal
Severity: normal Version: 3.0
Component: Multisite Keywords: has-patch commit
Focuses: 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)

ms-functions.diff (579 bytes) - added by feedmeastraycat 12 years ago.
insert-blog-bug.php (1.7 KB) - added by feedmeastraycat 12 years ago.
Plugin that duplicates the error

Download all attachments as: .zip

Change History (8)

#1 @nacin
12 years ago

  • Keywords has-patch commit added
  • Milestone changed from Awaiting Review to 3.6

Looks proper to me.

#2 @SergeyBiryukov
12 years ago

  • Component changed from General to Multisite
  • Version changed from trunk to 3.0

@feedmeastraycat
12 years ago

Plugin that duplicates the error

#3 @feedmeastraycat
12 years 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.

#4 @dd32
12 years ago

  • Type changed from enhancement to defect (bug)

Looks proper from here too, and for what it's worth, definitely a bug.

#5 @nacin
12 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 23511:

In insert_blog(), make sure we retrieve the insertion ID from wpdb before calling a function that could invoke queries. props feedmeastraycat. fixes #23400.

#6 @SergeyBiryukov
12 years ago

#24697 was marked as a duplicate.

Note: See TracTickets for help on using tickets.