WP_Site_Health::get_test_utf8mb4_support() │ public │ WP 5.2.0
Tests if the database server is capable of using utf8mb4.
Method of the class: WP_Site_Health{}
No Hooks.
Return
Array
. The test results.
Usage
$WP_Site_Health = new WP_Site_Health(); $WP_Site_Health->get_test_utf8mb4_support();
Changelog
Since 5.2.0 | Introduced. |
WP_Site_Health::get_test_utf8mb4_support() WP Site Health::get test utf8mb4 support code WP 6.5.2
public function get_test_utf8mb4_support() { if ( ! $this->mysql_server_version ) { $this->prepare_sql_data(); } $result = array( 'label' => __( 'UTF8MB4 is supported' ), 'status' => 'good', 'badge' => array( 'label' => __( 'Performance' ), 'color' => 'blue', ), 'description' => sprintf( '<p>%s</p>', __( 'UTF8MB4 is the character set WordPress prefers for database storage because it safely supports the widest set of characters and encodings, including Emoji, enabling better support for non-English languages.' ) ), 'actions' => '', 'test' => 'utf8mb4_support', ); if ( ! $this->is_mariadb ) { if ( version_compare( $this->mysql_server_version, '5.5.3', '<' ) ) { $result['status'] = 'recommended'; $result['label'] = __( 'utf8mb4 requires a MySQL update' ); $result['description'] .= sprintf( '<p>%s</p>', sprintf( /* translators: %s: Version number. */ __( 'WordPress’ utf8mb4 support requires MySQL version %s or greater. Please contact your server administrator.' ), '5.5.3' ) ); } else { $result['description'] .= sprintf( '<p>%s</p>', __( 'Your MySQL version supports utf8mb4.' ) ); } } else { // MariaDB introduced utf8mb4 support in 5.5.0. if ( version_compare( $this->mysql_server_version, '5.5.0', '<' ) ) { $result['status'] = 'recommended'; $result['label'] = __( 'utf8mb4 requires a MariaDB update' ); $result['description'] .= sprintf( '<p>%s</p>', sprintf( /* translators: %s: Version number. */ __( 'WordPress’ utf8mb4 support requires MariaDB version %s or greater. Please contact your server administrator.' ), '5.5.0' ) ); } else { $result['description'] .= sprintf( '<p>%s</p>', __( 'Your MariaDB version supports utf8mb4.' ) ); } } // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysqli_get_client_info $mysql_client_version = mysqli_get_client_info(); /* * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server. * mysqlnd has supported utf8mb4 since 5.0.9. */ if ( str_contains( $mysql_client_version, 'mysqlnd' ) ) { $mysql_client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $mysql_client_version ); if ( version_compare( $mysql_client_version, '5.0.9', '<' ) ) { $result['status'] = 'recommended'; $result['label'] = __( 'utf8mb4 requires a newer client library' ); $result['description'] .= sprintf( '<p>%s</p>', sprintf( /* translators: 1: Name of the library, 2: Number of version. */ __( 'WordPress’ utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer. Please contact your server administrator.' ), 'mysqlnd', '5.0.9' ) ); } } else { if ( version_compare( $mysql_client_version, '5.5.3', '<' ) ) { $result['status'] = 'recommended'; $result['label'] = __( 'utf8mb4 requires a newer client library' ); $result['description'] .= sprintf( '<p>%s</p>', sprintf( /* translators: 1: Name of the library, 2: Number of version. */ __( 'WordPress’ utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer. Please contact your server administrator.' ), 'libmysql', '5.5.3' ) ); } } return $result; }