WP_Site_Health::get_test_sql_server(): array

In this article

Tests if the SQL server is up to date.

Return

array The test results.

Source

public function get_test_sql_server() {
	if ( ! $this->mysql_server_version ) {
		$this->prepare_sql_data();
	}

	$result = array(
		'label'       => __( 'SQL server is up to date' ),
		'status'      => 'good',
		'badge'       => array(
			'label' => __( 'Performance' ),
			'color' => 'blue',
		),
		'description' => sprintf(
			'<p>%s</p>',
			__( 'The SQL server is a required piece of software for the database WordPress uses to store all your site&#8217;s content and settings.' )
		),
		'actions'     => sprintf(
			'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
			/* translators: Localized version of WordPress requirements if one exists. */
			esc_url( __( 'https://wordpress.org/about/requirements/' ) ),
			__( 'Learn more about what WordPress requires to run.' ),
			/* translators: Hidden accessibility text. */
			__( '(opens in a new tab)' )
		),
		'test'        => 'sql_server',
	);

	$db_dropin = file_exists( WP_CONTENT_DIR . '/db.php' );

	if ( ! $this->is_recommended_mysql_version ) {
		$result['status'] = 'recommended';

		$result['label'] = __( 'Outdated SQL server' );

		$result['description'] .= sprintf(
			'<p>%s</p>',
			sprintf(
				/* translators: 1: The database engine in use (MySQL or MariaDB). 2: Database server recommended version number. */
				__( 'For optimal performance and security reasons, you should consider running %1$s version %2$s or higher. Contact your web hosting company to correct this.' ),
				( $this->is_mariadb ? 'MariaDB' : 'MySQL' ),
				$this->mysql_recommended_version
			)
		);
	}

	if ( ! $this->is_acceptable_mysql_version ) {
		$result['status'] = 'critical';

		$result['label']          = __( 'Severely outdated SQL server' );
		$result['badge']['label'] = __( 'Security' );

		$result['description'] .= sprintf(
			'<p>%s</p>',
			sprintf(
				/* translators: 1: The database engine in use (MySQL or MariaDB). 2: Database server minimum version number. */
				__( 'WordPress requires %1$s version %2$s or higher. Contact your web hosting company to correct this.' ),
				( $this->is_mariadb ? 'MariaDB' : 'MySQL' ),
				$this->mysql_required_version
			)
		);
	}

	if ( $db_dropin ) {
		$result['description'] .= sprintf(
			'<p>%s</p>',
			wp_kses(
				sprintf(
					/* translators: 1: The name of the drop-in. 2: The name of the database engine. */
					__( 'You are using a %1$s drop-in which might mean that a %2$s database is not being used.' ),
					'<code>wp-content/db.php</code>',
					( $this->is_mariadb ? 'MariaDB' : 'MySQL' )
				),
				array(
					'code' => true,
				)
			)
		);
	}

	return $result;
}

Changelog

VersionDescription
5.2.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.