Default avatar after signup
#4
If you have some patience I can try to do it tonight after dinner (it's 6:08 pm here now).

Here it is:

<?php
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
} 
$plugins->add_hook("member_do_register_end", "default_avatar");
function default_avatar_info()
{
    global $lang;
    return Array(
        'name'          => "default avatar",
        'description'   => "assigns a default avatar at registration depending on 1st letter of username", 
        'website'       => '',
        'author'        => 'Ad Bakker', 
        'authorsite'    => '',
        'version'       => '1.0',
        'guid'          => '',
        'compatibility' => '18*', 
    );
}

function default_avatar()
{
	global $user_info, $db;
	$file = "./default_avatars/image of ".strtoupper(substr($user_info['username'],0,1))." alphabet.jpg";
	if (!file_exists($file)) return;
	$size = getimagesize($file);
	$avatar_array = array(
		'avatar' => "{$file}",
		'avatardimensions' => "{$size[0]}|{$size[1]}",
		'avatartype' => "remote");
	$db->update_query("users", $avatar_array, "username = \"{$user_info['username']}\"");	
}
?>

Place your default avatars in a subdirectory of your home directory named "default_avatars".
I have tested it with a .jpg avatar, if you use .png or .gif files change this at the end of line 25.
The avatars must have exactly the name as you described, for instance for a user with a name starting with an "n" the avatar name must be "image of N alphabet.jpg" (or another extension). Note that the n is capitalized to N!!!

I tested it and it works. Big Grin 
Regards, Ad Bakker (NL)
Reply


Messages In This Thread
Default avatar after signup - by rajeevrrs55 - 2015-02-01, 07:14 AM
RE: Default avatar after signup - by Ad Bakker - 2015-02-01, 03:16 PM
RE: Default avatar after signup - by rajeevrrs55 - 2015-02-01, 04:44 PM
RE: Default avatar after signup - by Ad Bakker - 2015-02-01, 05:09 PM
RE: Default avatar after signup - by Dr_The_One - 2015-12-05, 06:37 PM
RE: Default avatar after signup - by rajeevrrs55 - 2015-02-02, 11:22 AM
RE: Default avatar after signup - by Hugop - 2015-12-09, 08:38 PM
RE: Default avatar after signup - by Andre R. - 2017-01-03, 04:05 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)