diff --git a/src/wp-admin/includes/upgrade.php b/src/wp-admin/includes/upgrade.php index 4c40a62538..589d294b02 100644 --- a/src/wp-admin/includes/upgrade.php +++ b/src/wp-admin/includes/upgrade.php @@ -2221,7 +2221,7 @@ function dbDelta( $queries = '', $execute = true ) { if ( array_key_exists( $tablefield_field_lowercased, $cfields ) ) { // Get the field type from the query. - preg_match("|".$tablefield->Field." ([^ ]*( unsigned)?)|i", $cfields[ $tablefield_field_lowercased ], $matches); + preg_match( '|`?' . $tablefield->Field . '`? ([^ ]*( unsigned)?)|i', $cfields[ $tablefield_field_lowercased ], $matches ); $fieldtype = $matches[1]; $fieldtype_lowercased = strtolower( $fieldtype ); diff --git a/tests/phpunit/tests/dbdelta.php b/tests/phpunit/tests/dbdelta.php index d6dc20ac72..426a702b6f 100644 --- a/tests/phpunit/tests/dbdelta.php +++ b/tests/phpunit/tests/dbdelta.php @@ -464,4 +464,28 @@ class Tests_dbDelta extends WP_UnitTestCase { => "Changed type of {$wpdb->prefix}dbdelta_test.column_3 from blob to mediumblob" ), $result ); } + + /** + * @ticket 20263 + */ + function test_query_with_backticks_does_not_throw_an_undefined_index_warning() { + global $wpdb; + + $schema = " + CREATE TABLE {$wpdb->prefix}dbdelta_test2 ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `column_1` varchar(255) NOT NULL, + PRIMARY KEY (id), + KEY compound_key (id,column_1) + ) + "; + + $wpdb->query( $schema ); + + $updates = dbDelta( $schema, false ); + + $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}dbdelta_test2" ); + + $this->assertEmpty( $updates ); + } }