Skip to content

Commit

Permalink
Use the ->get_charset_collate() function for retrieving the database …
Browse files Browse the repository at this point in the history
…charset and collate
  • Loading branch information
sheabunge committed Sep 19, 2017
1 parent 0ae4c7a commit fc78751
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions php/class-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,11 @@ function create_tables( $upgrade = false ) {
* @uses dbDelta() to apply the SQL code
*
* @param string $table_name The name of the table to create
* @return bool whether the table creation was successful
*/
function create_table( $table_name ) {
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';

/* Set the database charset */
$charset_collate = '';

if ( ! empty( $wpdb->charset ) ) {
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
}

if ( ! empty( $wpdb->collate ) ) {
$charset_collate .= " COLLATE $wpdb->collate";
}
$charset_collate = $wpdb->get_charset_collate();

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

require_once ABSPATH . 'wp-admin/includes/upgrade.php';
dbDelta( $sql );
do_action( 'code_snippets/create_table', $table_name );
}
Expand Down

0 comments on commit fc78751

Please sign in to comment.