WP_Site_Health::get_test_utf8mb4_support()publicWP 5.2.0

Tests if the database server is capable of using utf8mb4.

Метод класса: WP_Site_Health{}

Хуков нет.

Возвращает

Массив. The test results.

Использование

$WP_Site_Health = new WP_Site_Health();
$WP_Site_Health->get_test_utf8mb4_support();

Заметки

  • Global. wpdb. $wpdb WordPress database abstraction object.

Список изменений

С версии 5.2.0 Введена.

Код WP_Site_Health::get_test_utf8mb4_support() WP 6.4.3

public function get_test_utf8mb4_support() {
	global $wpdb;

	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;
}