From 421868670794d3292a7d27ca2938620ff0624638 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Wed, 8 Aug 2012 06:13:48 +0000 Subject: [PATCH] Introduce wpdb::get_charset_collate() to return the DEFAULT CHARACTER SET and COLLATE for use in table schemas. props simonwheatley, pento. fixes #18451. git-svn-id: https://develop.svn.wordpress.org/trunk@21471 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/schema.php | 7 +------ wp-includes/wp-db.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/wp-admin/includes/schema.php b/wp-admin/includes/schema.php index bba0871d63..9d33f0e009 100644 --- a/wp-admin/includes/schema.php +++ b/wp-admin/includes/schema.php @@ -17,12 +17,7 @@ global $wpdb, $wp_queries, $charset_collate; * @global string * @name $charset_collate */ -$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(); /** * Retrieve the SQL for creating database tables. diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index cc47d0fb9a..e74e4ebce2 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -1559,6 +1559,24 @@ class wpdb { return $this->has_cap( 'collation' ); } + /** + * The database character collate. + * + * @since 3.5.0 + * + * @return string The database character collate. + */ + public function get_charset_collate() { + $charset_collate = ''; + + if ( ! empty( $this->charset ) ) + $charset_collate = "DEFAULT CHARACTER SET $this->charset"; + if ( ! empty( $this->collate ) ) + $charset_collate .= " COLLATE $this->collate"; + + return $charset_collate; + } + /** * Determine if a database supports a particular feature *