WP_User::__get
Magic method for accessing custom fields.
Метод класса: WP_User{}
Хуков нет.
Возвращает
Разное. Value of the given user meta key (if set). If $key is 'id', the user ID.
Использование
$WP_User = new WP_User(); $WP_User->__get( $key );
- $key(строка) (обязательный)
- User meta key to retrieve.
Список изменений
| С версии 3.3.0 | Введена. |
Код WP_User::__get() WP User:: get WP 7.0
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;
}