WP_User::__isset() WordPress Method

The WP_User::__isset() magic method is used to check whether a property of a WP_User object is set. If the property is set, the method returns true, otherwise false. This magic method can be handy when you need to check if a certain property of a WP_User object is set before using it.

WP_User::__isset( string $key ) #

Magic method for checking the existence of a certain custom field.


Parameters

$key

(string)(Required)User meta key to check if set.


Top ↑

Return

(bool) Whether the given user meta key is set.


Top ↑

Source

File: wp-includes/class-wp-user.php

	public function __isset( $key ) {
		if ( 'id' === $key ) {
			_deprecated_argument(
				'WP_User->id',
				'2.1.0',
				sprintf(
					/* translators: %s: WP_User->ID */
					__( 'Use %s instead.' ),
					'<code>WP_User->ID</code>'
				)
			);
			$key = 'ID';
		}

		if ( isset( $this->data->$key ) ) {
			return true;
		}

		if ( isset( self::$back_compat_keys[ $key ] ) ) {
			$key = self::$back_compat_keys[ $key ];
		}

		return metadata_exists( 'user', $this->ID, $key );
	}


Top ↑

Changelog

Changelog
VersionDescription
3.3.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.