From 78d729602e11dd251b434124969be8c6d6922c8f Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 4 Apr 2024 15:13:14 +0000 Subject: [PATCH] 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 --- wp-admin/includes/class-wp-site-health.php | 118 --------------------- wp-admin/setup-config.php | 2 +- wp-includes/class-wpdb.php | 34 +----- wp-includes/version.php | 2 +- 4 files changed, 5 insertions(+), 151 deletions(-) diff --git a/wp-admin/includes/class-wp-site-health.php b/wp-admin/includes/class-wp-site-health.php index d7728cd61f..c0516096ed 100644 --- a/wp-admin/includes/class-wp-site-health.php +++ b/wp-admin/includes/class-wp-site-health.php @@ -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( - '

%s

', - __( '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( - '

%s

', - 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( - '

%s

', - __( '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( - '

%s

', - 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( - '

%s

', - __( '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( - '

%s

', - 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( - '

%s

', - 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; - } - /** * 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', diff --git a/wp-admin/setup-config.php b/wp-admin/setup-config.php index 4f0833805c..b394de8679 100644 --- a/wp-admin/setup-config.php +++ b/wp-admin/setup-config.php @@ -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; diff --git a/wp-includes/class-wpdb.php b/wp-includes/class-wpdb.php index d9186b91f4..aeb9679937 100644 --- a/wp-includes/class-wpdb.php +++ b/wp-includes/class-wpdb.php @@ -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 diff --git a/wp-includes/version.php b/wp-includes/version.php index 701e4cc208..aa4bd68814 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.