Skip to content

Commit fc78751

Browse files
committed
Use the ->get_charset_collate() function for retrieving the database charset and collate
1 parent 0ae4c7a commit fc78751

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

Diff for: php/class-db.php

+3-12
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,11 @@ function create_tables( $upgrade = false ) {
115115
* @uses dbDelta() to apply the SQL code
116116
*
117117
* @param string $table_name The name of the table to create
118+
* @return bool whether the table creation was successful
118119
*/
119120
function create_table( $table_name ) {
120121
global $wpdb;
121-
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
122-
123-
/* Set the database charset */
124-
$charset_collate = '';
125-
126-
if ( ! empty( $wpdb->charset ) ) {
127-
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
128-
}
129-
130-
if ( ! empty( $wpdb->collate ) ) {
131-
$charset_collate .= " COLLATE $wpdb->collate";
132-
}
122+
$charset_collate = $wpdb->get_charset_collate();
133123

134124
/* Create the database table */
135125
$sql = "CREATE TABLE $table_name (
@@ -143,6 +133,7 @@ function create_table( $table_name ) {
143133
PRIMARY KEY (id)
144134
) $charset_collate;";
145135

136+
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
146137
dbDelta( $sql );
147138
do_action( 'code_snippets/create_table', $table_name );
148139
}

0 commit comments

Comments
 (0)