wpdb::determine_charset()
Determines the best charset and collation to use given a charset and collation.
For example, when able, utf8mb4 should be used instead of utf8.
Method of the class: wpdb{}
No Hooks.
Return
Array
. The most appropriate character set and collation to use.
Usage
global $wpdb; $wpdb->determine_charset( $charset, $collate );
- $charset(string) (required)
- The character set to check.
- $collate(string) (required)
- The collation to check.
Changelog
Since 4.6.0 | Introduced. |
wpdb::determine_charset() wpdb::determine charset code WP 6.7.2
public function determine_charset( $charset, $collate ) { if ( ( ! ( $this->dbh instanceof mysqli ) ) || empty( $this->dbh ) ) { return compact( 'charset', 'collate' ); } if ( 'utf8' === $charset ) { $charset = 'utf8mb4'; } if ( 'utf8mb4' === $charset ) { // _general_ is outdated, so we can upgrade it to _unicode_, instead. if ( ! $collate || 'utf8_general_ci' === $collate ) { $collate = 'utf8mb4_unicode_ci'; } else { $collate = str_replace( 'utf8_', 'utf8mb4_', $collate ); } } // _unicode_520_ is a better collation, we should use that when it's available. if ( $this->has_cap( 'utf8mb4_520' ) && 'utf8mb4_unicode_ci' === $collate ) { $collate = 'utf8mb4_unicode_520_ci'; } return compact( 'charset', 'collate' ); }