• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
  • This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Readily available $visitor variables (user info, user perms)

calorie

Active member
#1
Readily available $visitor variables in XF 1.0.0 Beta 1

Use in templates like this:
Code:
<xen:if is="{$visitor.user_id}">
    logged in, positive user id
<xen:else />
    guest, bot, or logged out
</xen:if>
Or like this:

Code:
<xen:if is="{$visitor.permissions.forum.viewAttachment}">
    can view attachments
<xen:else />
    cannot view attachments
</xen:if>
Or like this:

Code:
{xen:if {$visitor.trophy_points}, 'has trophy points'}
But remember variable scope: http://php.net/manual/en/language.variables.scope.php

Not every variable is available for use in every location.

Here is the $visitor list...

Code:
XenForo_Visitor Object
(
    [_user:protected] => Array
        (
            [user_id] => 1
            [username] => Admin
            [email] => email@domain.com
            [gender] => 
            [custom_title] => 
            [language_id] => 1
            [style_id] => 0
            [timezone] => Europe/London
            [visible] => 1
            [user_group_id] => 2
            [secondary_group_ids] => 3,4
            [display_style_group_id] => 3
            [permission_combination_id] => 7
            [message_count] => 2
            [conversations_unread] => 0
            [register_date] => 1286324538
            [last_activity] => 1286362240
            [trophy_points] => 1
            [alerts_unread] => 0
            [avatar_date] => 0
            [avatar_width] => 0
            [avatar_height] => 0
            [gravatar] => 
            [user_state] => valid
            [is_moderator] => 1
            [is_admin] => 1
            [is_banned] => 0
            [like_count] => 0
            [dob_day] => 0
            [dob_month] => 0
            [dob_year] => 0
            [status] => 
            [status_date] => 0
            [status_profile_post_id] => 0
            [signature] => 
            [homepage] => 
            [location] => 
            [occupation] => 
            [following] => 
            [identities] => 
            [csrf_token] => d7hw51kn8c0d6gjnw6x95fd8b109cbcd89ac5d30
            [avatar_crop_x] => 0
            [avatar_crop_y] => 0
            [about] => 
            [facebook_auth_id] => 0
            [show_dob_year] => 1
            [show_dob_date] => 1
            [content_show_signature] => 1
            [receive_admin_email] => 1
            [email_on_conversation] => 1
            [is_discouraged] => 0
            [default_watch_state] => 
            [alert_optout] => 
            [allow_view_profile] => everyone
            [allow_post_profile] => everyone
            [allow_send_personal_conversation] => everyone
            [allow_view_identities] => everyone
            [allow_receive_news_feed] => everyone
            [global_permission_cache] => <snipped this serialized array, over 10K char post limit>
            [csrf_token_page] => 1,1286366814,e9f3jvb0pwbf87djb9458f46d458a3e34418ec59
            [permissions] => Array
                (
                    [avatar] => Array
                        (
                            [allowed] => 1
                            [maxFileSize] => -1
                        )

                    [forum] => Array
                        (
                            [manageAnyThread] => 1
                            [stickUnstickThread] => 1
                            [postThread] => 1
                            [postReply] => 1
                            [editOwnPost] => 1
                            [deleteOwnThread] => 1
                            [deleteOwnPost] => 1
                            [viewAttachment] => 1
                            [uploadAttachment] => 1
                            [votePoll] => 1
                            [viewDeleted] => 1
                            [approveUnapprove] => 1
                            [viewModerated] => 1
                            [deleteAnyPost] => 1
                            [deleteAnyThread] => 1
                            [undelete] => 1
                            [editAnyPost] => 1
                            [hardDeleteAnyThread] => 1
                            [lockUnlockThread] => 1
                            [hardDeleteAnyPost] => 1
                        )

                    [profilePost] => Array
                        (
                            [editAny] => 1
                            [hardDeleteAny] => 1
                            [undelete] => 1
                            [deleteAny] => 1
                            [view] => 1
                            [viewDeleted] => 1
                            [approveUnapprove] => 1
                            [viewModerated] => 1
                            [manageOwn] => 1
                            [post] => 1
                            [editOwn] => 1
                            [deleteOwn] => 1
                        )

                    [general] => Array
                        (
                            [view] => 1
                            [viewNode] => 1
                            [bypassUserPrivacy] => 1
                            [viewProfile] => 1
                            [cleanSpam] => 1
                            [search] => 1
                            [editSignature] => 1
                            [editCustomTitle] => 1
                            [followModerationRules] => 1
                            [bypassFloodCheck] => 1
                        )

                    [conversation] => Array
                        (
                            [editAnyPost] => 1
                            [start] => 1
                            [maxRecipients] => -1
                            [alwaysInvite] => 1
                            [editOwnPost] => 1
                            [editOwnPostTimeLimit] => 5
                        )

                )

        )

    [_language:protected] => Array
        (
            [language_id] => 1
            [parent_id] => 0
            [parent_list] => 1,0
            [title] => English (US)
            [date_format] => M j, Y
            [time_format] => g:i A
            [decimal_point] => .
            [thousands_separator] => ,
            [phrase_cache] => <snipped this array, over 10K char post limit>
        )

    [_nodePermissions:protected] => Array
        (
        )

    [_adminPermissions:protected] => 
    [_isSuperAdmin:protected] => 
)
Any value that looks important is fake. ;)