Skip to main content

User

Access user data. The user root provider represents the currently logged-in visitor and is available on all pages.

The author variable uses the same provider but resolves to the post's author instead. See the overview for details.

user vs author

user and author expose the same fields listed below. The only difference is which person they point to: user is whoever is viewing the page, author is whoever wrote the post.

All Fields​

FieldArgumentsReturnsDescription
id—intUser ID
slug—stringUser slug (nicename)
user_email—stringEmail address (private)
display_name—stringDisplay name
name—stringDisplay name (alias of display_name)
user_url—stringWebsite URL
link—stringAuthor archive URL
path—stringAuthor archive path
edit_link—string | nullAdmin edit URL (null when not authorized)
profile_link—string | nullSame as edit_link
avatar{args}stringAvatar URL
roles—array | nullUser roles, null when no roles (private)
is_current—boolIs the current logged-in user
cancapability, ...argsboolCheck user capability (private on another user than the visitor)
can_edit—boolCan edit this user
metafield_namemixedUser meta value (also used for first_name, last_name, nickname, description); private except the names, nickname and bio
raw_metafield_namemixedMeta value, without plugins
has_fieldfield_nameboolCheck if field exists
Private fields

user_login, user_email, user_registered, roles, and user meta (except first_name, last_name, nickname and the bio, description) show nothing until the site opens them in Settings > Privacy, whoever wrote the expression. A logged-in visitor always reads their own. Users without a published post, such as customers, are private as a whole. See Private Data.

Raw Database Fields​

Direct read access to the underlying WP_User columns:

FieldReturnsDescription
IDintUser ID (alias of id)
user_loginstringUsername (private)
user_nicenamestringURL-friendly slug (alias of slug)
user_registeredstringRegistration date YYYY-MM-DD HH:MM:SS (private)

Profile​

Profile fields like first/last name, nickname, and biographical info are accessed through meta() (matching how WordPress stores them). These are public, as are the user fields made with ACF, Meta Box, Pods or JetEngine (password fields aside); other user meta is private until its key is opened in Settings > Privacy:

{{ user.display_name }}
{{ user.meta('first_name') }} {{ user.meta('last_name') }}
{{ user.meta('nickname') }}
{{ user.meta('description') }}
{{ user.user_url }}

Avatar​

The avatar field takes an options object, the arguments of get_avatar_url(), as in Timber:

{{ user.avatar }}                                       <!-- Default size (96px) -->
{{ user.avatar({size: 200}) }} <!-- 200px size -->
{{ user.avatar({size: 200, default: 'identicon'}) }} <!-- Custom options -->

Roles & Capabilities​

{{ user.roles|join(', ') }}
{{ user.is_current }}
{{ user.can('edit_posts') }}
{{ user.can('manage_options') }}
{{ user.can('edit_post', post.id) }} <!-- Variadic — pass extra args for meta-capabilities -->

To check whether a visitor is logged in, test user.id (it's empty for guests):

{{ user.id ? 'Welcome back!' : 'Please log in' }}

Custom Fields (Meta)​

{{ user.meta('phone') }}
{{ user.meta('company') }}
{{ user.meta('billing_address').city }}
{{ user.has_field('phone') }}
Plugin integration

meta('key') integrates with ACF, MetaBox, JetEngine, and Pods. User meta keys are private until opened in Settings > Privacy; keys starting with _ are always blocked.

Common Patterns​

Show content for logged-in users​

{{ user.id ? 'Welcome back!' : 'Please log in' }}

Display user greeting​

Hello, {{ user.name ?? 'Guest' }}

Check admin capability​

{{ user.can('manage_options') ? 'Admin Panel' : '' }}

Author bio​

{{ author.name }}
{{ author.meta('description') }}
{{ author.avatar({size: 96}) }}

"Posted by" line​

Posted by {{ author.name }} on {{ post.date('F j, Y') }}
<a href="{{ author.link }}">{{ author.name }}</a>