MyBB Community Forums
Default avatar after signup - Printable Version

+- MyBB Community Forums (https://community.mybb.com)
+-- Forum: Extensions (https://community.mybb.com/forum-201.html)
+--- Forum: Plugins (https://community.mybb.com/forum-73.html)
+---- Forum: Plugin Requests (https://community.mybb.com/forum-65.html)
+---- Thread: Default avatar after signup (/thread-166447.html)



Default avatar after signup - rajeevrrs55 - 2015-02-01

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.


RE: Default avatar after signup - Ad Bakker - 2015-02-01

I think this can be done with a rather simple plugin. Perhaps ask in "plugin requests".


RE: Default avatar after signup - rajeevrrs55 - 2015-02-01

Is this possible, without any plugin with editing or any existing plugin.

Or move this thread to plugin request section.


RE: Default avatar after signup - Ad Bakker - 2015-02-01

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 


RE: Default avatar after signup - rajeevrrs55 - 2015-02-02

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.


RE: Default avatar after signup - Dr_The_One - 2015-12-05

(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?


RE: Default avatar after signup - Hugop - 2015-12-09

(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.


RE: Default avatar after signup - Andre R. - 2017-01-03

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?