From 16adf7644ba659ebcbbc6f0c8e35152bbf20d042 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 29 Jul 2013 18:14:05 +0000 Subject: [PATCH] Reset $wpdb->insert_id on a failed INSERT or REPLACE. See [24459] [24494]. git-svn-id: https://develop.svn.wordpress.org/trunk@24872 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/wp-db.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index 4f5a97eb47..2398002e32 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -1204,6 +1204,10 @@ class wpdb { // If there is an error then take note of it.. if ( $this->last_error = mysql_error( $this->dbh ) ) { + // Clear insert_id on a subsequent failed insert. + if ( $this->insert_id && preg_match( '/^\s*(insert|replace)\s/i', $query ) ) + $this->insert_id = 0; + $this->print_error(); return false; }