2015-12-05, 06:37 PM
(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.![]()
Where to add this code?