Skip to:

Re: Plugin: Avatar Upload



@wilcosky and everyone else who’s asked here and on the other thread, having cracked it this afternoon with the aid of a couple of online code snippets and my limited PHP skills, here’s how to display your avatars from this plugin in WP if you have WP and bbPress integrated and sharing the same user table.

In your sidebar, or wherever you want to have them (or a “welcome, guest” message or whatever) appear, put this code snippet…

<?php global $user_login;

if ($user_login == '') {
echo('Welcome Guest');
} else {

$directory = '/your/DOCUMENT_ROOT/path/to/forum/avatars/';
$flag = false;
$ext = array( '.jpg' , '.gif' , '.png' );

for( $i = 0; count( $ext ) > $i; $i++ )
if( file_exists( $directory . $user_login . $ext[$i] ) )

$flag = true;
$name = $user_login . $ext[$i];
if( $flag == true )
echo "<img src="".$name."" />";

Note that the path for $directory is your DOCUMENT_ROOT one (you can use an ‘echo’ or ‘print’ PHP command to find it if you don’t know it, google for instructions; it’s usually something like ‘/home/user/public_html/’), while the later image source path is the standard http one. If your avatar directory is somewhere other than / then, obviously, you’ll need to edit accordingly.

If you use a different set of possible image file extensions than the usual .jpg, .gif and .png trio you’ll also need to edit the $ext array (so if you don’t allow .gifs, it’d be $ext = array( '.jpg' , '.png' ) for instance).

Skip to toolbar