Facebook Twitter Pinterest Share

vBulletin 3.X Add-ons & Template Modifications All the latest vBulletin 3.X Add-ons & Template Modifications.


New Thread  Post Reply
xenoth's Avatar
xenoth : 50+
xenoth is a splendid one to beholdxenoth is a splendid one to beholdxenoth is a splendid one to beholdxenoth is a splendid one to beholdxenoth is a splendid one to beholdxenoth is a splendid one to beholdxenoth is a splendid one to behold
offline Joined: Dec 2007 Posts: 96 Thanked: 100
  #1  
Thread Starter Unread 01-09-08
How To: Display Avatar On USERCP (or anywhere)

This is not a hack you will find on vBulletin.org, i have this on my site (thanks DEViANT for helping) and though i'd share.

The typical way to display an avatar is by calling image.php? ... However on my site this started to have problems.

The problems were that the dateline didnt function correctly (yes when the correct syntax was used, this problem has been reported numerous times on vBulletin.org), leaving old images in the display.

Another problem was that predefined gallery images were not getting displayed.

By adding this plugin you eliminate these problems. You do add an extra query, for me this is no big deal.

#####################################################################
Here's how to make a plugin to display the logged in users avatar correctly:
#####################################################################

There are 2 things to do, add a new plugin, and call it within the template (we are using usercp as example):

Navigate to Products & Plugins -> Add New Plugin

Enter the following data:

Product: vBulletin
Hook Location: usercp_start
Title: Show Avatar In USERCP
Execution Order: *Dont enter a number here, leave at default value* (if this field is blank, you will need to add a number)

Next you will see the field called "Plugin PHP Code:"


enter the following code...

if ($vbulletin->userinfo['userid'] > 0 && $vbulletin->userinfo['userid'] != '' || !$vbulletin->userinfo['userid'])
{
	require_once(DIR . '/includes/functions_user.php');
	$vbulletin->userinfo['avatar_build'] = fetch_avatar_url($vbulletin->userinfo['userid']);

	if (empty($vbulletin->userinfo['avatar_build']) || !is_array($vbulletin->userinfo['avatar_build']))
	{
	$vbulletin->userinfo['avatar_build'] = array('noavatar.gif');
	}

	$vbulletin->userinfo['avatar_build'] = '<img src="' . $vbulletin->userinfo['avatar_build'][0] . '"'.iif($vbulletin->userinfo['avatar_build'][1],$vbulletin->userinfo['avatar_build'][1],'').'border="0" alt="Edit Your Avatar" />';
}
in the ablove code you will see "noavatar.gif" . This displays an image if the user doesnt have an avatar. By default this image is contained in your forums root directory.

Ok, now save.

The final thing to do is open your USERCP template. Choose where you want the avatar to display, and add the following:

$bbuserinfo[avatar_build]

You can wrap this in a link like so:

<a href="http://www.YOURSITE.com/forums/profile.php?do=editavatar" title="Click to change">$bbuserinfo[avatar_build]</a>

save and its done.



NOTE:
To make the avatar display elsewhere, change the plugin hook location to where you want it to show up, and add the $bbuserinfo[avatar_build] to the appropriate template.
New Thread  Post Reply

Thread Tools

Bookmarks
  • Submit Thread to Facebook
  • Submit Thread to Twitter
  • Submit Thread to Pinterest
  • Submit Thread to LinkedIn
  • Submit Thread to Reddit
Tags
usercp, avatar, display
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Powered by GYSN Underground 2021