MyBB Community Forums

Full Version: Default avatar after signup
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I need some features in my forum. is this possible.

if any anyone signup in my forum if his/her is name is "user1" his/her avatar automatically set "image of U alphabet"

the first letter of username will be default avatar of user. user can change later with his own avatar.

some example :

if username is "demo" avatar will we "image of D alphabet"
if username is "mybb" then avatar will we " image of M alphabet"


Example sites :
http://community.sitepoint.com/

hello, anybody there.
I think this can be done with a rather simple plugin. Perhaps ask in "plugin requests".
Is this possible, without any plugin with editing or any existing plugin.

Or move this thread to plugin request section.
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 
Thanks you.

let me try.

great it works.

make a plugin and publish in all mods of mybb so every one get a benefit of this.
(2015-02-01, 05:09 PM)Ad Bakker Wrote: [ -> ]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 

Where to add this code?
(2015-12-05, 06:37 PM)Dr_The_One Wrote: [ -> ]
(2015-02-01, 05:09 PM)Ad Bakker Wrote: [ -> ]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 

Where to add this code?

Make a php file in the plugin folder.

default_avatar.php should work.
Apologies in advanced for bumping a rather old thread, but is there a way to run this plugin across already registered users who haven't changed their default avatar?