diff --git a/src/wp-includes/wp-db.php b/src/wp-includes/wp-db.php index 7a09d62a9e..7366172101 100644 --- a/src/wp-includes/wp-db.php +++ b/src/wp-includes/wp-db.php @@ -1785,7 +1785,9 @@ class wpdb { $wheres[] = "`$field` = {$form}"; } - $sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres ); + $wheres = empty( $where ) ? '' : ( ' WHERE ' . implode( ' AND ', $wheres ) ); + + $sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . $wheres; return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) ); } diff --git a/tests/phpunit/tests/db.php b/tests/phpunit/tests/db.php index 39a1f11339..19db983075 100644 --- a/tests/phpunit/tests/db.php +++ b/tests/phpunit/tests/db.php @@ -436,4 +436,21 @@ class Tests_DB extends WP_UnitTestCase { $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE ID = %d", $last ) ); $this->assertEquals( 'Walter Replace Sobchak', $row->display_name ); } + + /** + * + * @ticket 26106 + */ + function test_empty_where() { + global $wpdb; + $wpdb->update( $wpdb->posts, array( 'post_name' => 'burrito' ), array() ); + + $expected1 = "UPDATE `{$wpdb->posts}` SET `post_name` = 'burrito'"; + $this->assertEquals( $expected1, $wpdb->last_query ); + + $wpdb->update( $wpdb->posts, array( 'post_name' => 'burrito' ), array( 'post_status' => 'taco' ) ); + + $expected2 = "UPDATE `{$wpdb->posts}` SET `post_name` = 'burrito' WHERE `post_status` = 'taco'"; + $this->assertEquals( $expected2, $wpdb->last_query ); + } }