On this page
WP_User::__get( string $key ): mixed
Magic method for accessing custom fields.
Parameters
$keystring Required-
User meta key to retrieve.
Return
mixed Value of the given user meta key (if set). If $key is 'id', the user ID.
Source
File: wp-includes/class-wp-user.php. View all references
public function __get( $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>'
)
);
return $this->ID;
}
if ( isset( $this->data->$key ) ) {
$value = $this->data->$key;
} else {
if ( isset( self::$back_compat_keys[ $key ] ) ) {
$key = self::$back_compat_keys[ $key ];
}
$value = get_user_meta( $this->ID, $key, true );
}
if ( $this->filter ) {
$value = sanitize_user_field( $key, $value, $this->ID, $this->filter );
}
return $value;
}
Related
Uses
| Uses | Description |
|---|---|
| get_user_meta() wp-includes/user.php | Retrieves user meta field for a user. |
| sanitize_user_field() wp-includes/user.php | Sanitizes user field based on context. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| _deprecated_argument() wp-includes/functions.php | Marks a function argument as deprecated and inform when it has been used. |
Used By
| Used By | Description |
|---|---|
| WP_User::get() wp-includes/class-wp-user.php | Retrieves the value of a property or meta key. |
Changelog
| Version | Description |
|---|---|
| 3.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_user/__get