wpdb::has_cap() WordPress Method

The wpdb::has_cap() method is used to check if a user has a certain capability. This is useful for checking if a user is allowed to perform an action, such as editing a post.

wpdb::has_cap( string $db_cap ) #

Determines if a database supports a particular feature.


Description

Top ↑

See also


Top ↑

Parameters

$db_cap

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


Top ↑

Return

(int|false) Whether the database feature is supported, false otherwise.


Top ↑

Source

File: wp-includes/wp-db.php

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

		switch ( strtolower( $db_cap ) ) {
			case 'collation':    // @since 2.5.0
			case 'group_concat': // @since 2.7.0
			case 'subqueries':   // @since 2.7.0
				return version_compare( $version, '4.1', '>=' );
			case 'set_charset':
				return version_compare( $version, '5.0.7', '>=' );
			case 'utf8mb4':      // @since 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 4.6.0
				return version_compare( $version, '5.6', '>=' );
		}

		return false;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.6.0Added support for the 'utf8mb4_520' feature.
4.1.0Added support for the 'utf8mb4' feature.
2.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.