wpdb::has_cap( string $db_cap )

Determines whether the database or WPDB supports a particular feature.


Description

Capability sniffs for the database server and current version of WPDB.

Database sniffs are based on the version of MySQL the site is using.

WPDB sniffs are added as new features are introduced to allow theme and plugin developers to determine feature support. This is to account for drop-ins which may introduce feature support at a different time to WordPress.

See also


Parameters

$db_cap

(Required) The feature to check for. Accepts 'collation', 'group_concat', 'subqueries', 'set_charset', 'utf8mb4', 'utf8mb4_520', or 'identifier_placeholders'.


Return

(bool) True when the database feature is supported, false otherwise.


Source

File: wp-includes/class-wpdb.php

	public function has_cap( $db_cap ) {
		$version = $this->db_version();

		switch ( strtolower( $db_cap ) ) {
			case 'collation' :    // @since WP-2.5.0
			case 'group_concat' : // @since WP-2.7.0
			case 'subqueries' :   // @since WP-2.7.0
				return version_compare( $version, '4.1', '>=' );
			case 'set_charset' :
				return version_compare( $version, '5.0.7', '>=' );
			case 'utf8mb4' :      // @since WP-4.1.0
				if ( version_compare( $version, '5.5.3', '<' ) ) {
					return false;
				}
				if ( $this->use_mysqli ) {
					$client_version = mysqli_get_client_info();
				} else {
					$client_version = mysql_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 ( 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', '>=' );
				}
			case 'utf8mb4_520' : // @since WP-4.6.0
				return version_compare( $version, '5.6', '>=' );
		}

		return false;
	}

Changelog

Changelog
Version Description
6.2.0 Added support for the 'identifier_placeholders' feature.
4.6.0 Added support for the 'utf8mb4_520' feature.
4.1.0 Added support for the 'utf8mb4' feature.
2.7.0 Introduced.