Database: Remove back-compat for database servers that don't support utf8mb4.

Since WordPress 6.5, the minimum supported version of MySQL and MariaDB is 5.5.5. This means all supported database servers now support the `utf8mb4` character set and therefore the conditional logic for this is no longer necessary.

Props l1nuxjedi, craigfrancis, OllieJones, johnbillion

Fixes #60096

Built from https://develop.svn.wordpress.org/trunk@57926


git-svn-id: http://core.svn.wordpress.org/trunk@57427 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
John Blackbourn 2024-04-04 15:13:14 +00:00
parent 1c8b25a7a5
commit 78d729602e
4 changed files with 5 additions and 151 deletions

View File

@ -1283,120 +1283,6 @@ class WP_Site_Health {
return $result;
}
/**
* Tests if the database server is capable of using utf8mb4.
*
* @since 5.2.0
*
* @return array The test results.
*/
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&#8217; 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&#8217; 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&#8217; 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&#8217; utf8mb4 support requires MySQL client library (%1$s) version %2$s or newer. Please contact your server administrator.' ),
'libmysql',
'5.5.3'
)
);
}
}
return $result;
}
/**
* Tests if the site can communicate with WordPress.org.
*
@ -2739,10 +2625,6 @@ class WP_Site_Health {
'label' => __( 'Database Server version' ),
'test' => 'sql_server',
),
'utf8mb4_support' => array(
'label' => __( 'MySQL utf8mb4 support' ),
'test' => 'utf8mb4_support',
),
'ssl_support' => array(
'label' => __( 'Secure communication' ),
'test' => 'ssl_support',

View File

@ -396,7 +396,7 @@ switch ( $step ) {
$config_file[ $line_num ] = "define( '" . $constant . "'," . $padding . "'" . addcslashes( constant( $constant ), "\\'" ) . "' );\r\n";
break;
case 'DB_CHARSET':
if ( 'utf8mb4' === $wpdb->charset || ( ! $wpdb->charset && $wpdb->has_cap( 'utf8mb4' ) ) ) {
if ( 'utf8mb4' === $wpdb->charset || ( ! $wpdb->charset ) ) {
$config_file[ $line_num ] = "define( '" . $constant . "'," . $padding . "'utf8mb4' );\r\n";
}
break;

View File

@ -878,15 +878,10 @@ class wpdb {
return compact( 'charset', 'collate' );
}
if ( 'utf8' === $charset && $this->has_cap( 'utf8mb4' ) ) {
if ( 'utf8' === $charset ) {
$charset = 'utf8mb4';
}
if ( 'utf8mb4' === $charset && ! $this->has_cap( 'utf8mb4' ) ) {
$charset = 'utf8';
$collate = str_replace( 'utf8mb4_', 'utf8_', $collate );
}
if ( 'utf8mb4' === $charset ) {
// _general_ is outdated, so we can upgrade it to _unicode_, instead.
if ( ! $collate || 'utf8_general_ci' === $collate ) {
@ -3242,11 +3237,6 @@ class wpdb {
if ( ! empty( $column->Collation ) ) {
list( $charset ) = explode( '_', $column->Collation );
// If the current connection can't support utf8mb4 characters, let's only send 3-byte utf8 characters.
if ( 'utf8mb4' === $charset && ! $this->has_cap( 'utf8mb4' ) ) {
$charset = 'utf8';
}
$charsets[ strtolower( $charset ) ] = true;
}
@ -4057,6 +4047,7 @@ class wpdb {
* @since 4.1.0 Added support for the 'utf8mb4' feature.
* @since 4.6.0 Added support for the 'utf8mb4_520' feature.
* @since 6.2.0 Added support for the 'identifier_placeholders' feature.
* @since 6.6.0 The `utf8mb4` feature now always returns true.
*
* @see wpdb::db_version()
*
@ -4092,26 +4083,7 @@ class wpdb {
case 'set_charset':
return version_compare( $db_version, '5.0.7', '>=' );
case 'utf8mb4': // @since 4.1.0
if ( version_compare( $db_version, '5.5.3', '<' ) ) {
return false;
}
$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.
*
* Note: str_contains() is not used here, as this file can be included
* directly outside of WordPress core, e.g. by HyperDB, in which case
* the polyfills from wp-includes/compat.php are not loaded.
*/
if ( false !== strpos( $client_version, 'mysqlnd' ) ) {
$client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $client_version );
return version_compare( $client_version, '5.0.9', '>=' );
} else {
return version_compare( $client_version, '5.5.3', '>=' );
}
return true;
case 'utf8mb4_520': // @since 4.6.0
return version_compare( $db_version, '5.6', '>=' );
case 'identifier_placeholders': // @since 6.2.0

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.6-alpha-57925';
$wp_version = '6.6-alpha-57926';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.