Skip to main content

User & Author

Access user data. UnBlock provides two root variables that share the same fields:

  • user — The currently logged-in visitor
  • author — The author of the current post
info

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

All Fields

FieldArgumentsReturnsDescription
idintUser ID
namestringDisplay name
loginstringUsername
slugstringUser slug (nicename)
emailstringEmail address
display_namestringDisplay name
first_namestringFirst name
last_namestringLast name
nicknamestringNickname
descriptionstringBiographical info
urlstringWebsite URL
linkstringAuthor archive URL
pathstringAuthor archive path
edit_linkstringAdmin edit URL
profile_linkstringProfile page URL
avatarsizestringAvatar URL
rolesarrayUser roles
logged_inboolIs user logged in
is_currentboolIs the current logged-in user
cancapabilityboolCheck user capability
can_editboolCan edit this user
metafield_namemixedUser meta value
raw_metafield_namemixedUnescaped meta value
has_fieldfield_nameboolCheck if field exists

Basic Fields

{{ user.id }}
{{ user.name }}
{{ user.login }}
{{ user.email }}

Profile

{{ user.display_name }}
{{ user.first_name }} {{ user.last_name }}
{{ user.nickname }}
{{ user.description }}
{{ user.url }}

URLs

{{ user.link }}
{{ user.path }}
{{ user.edit_link }}
{{ user.profile_link }}

Avatar

{{ user.avatar }}              <!-- Default size -->
{{ user.avatar(96) }} <!-- 96px size -->
{{ user.avatar(200) }} <!-- 200px size -->

Roles & Capabilities

{{ user.roles|join(', ') }}
{{ user.logged_in }}
{{ user.is_current }}
{{ user.can('edit_posts') }}
{{ user.can('manage_options') }}

Custom Fields (Meta)

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

Common Patterns

Show content for logged-in users

{{ user.logged_in ? '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.description }}
{{ author.avatar(96) }}

"Posted by" line

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