MyBB Community Forums
Default Avatar url - 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 Development (https://community.mybb.com/forum-68.html)
+---- Thread: Default Avatar url (/thread-177009.html)



Default Avatar url - Leefish - 2015-08-31

I am working on a plugin, and I have this code to display avatars:

if (!empty($referral['avatar'])){
			
$avatar = htmlspecialchars_uni($referral['avatar']);
				
	} else {
			
$avatar= $mybb->settings['bburl'].'/images/default_avatar.png';
}

But if the default avatar path is different to default (or it isnt a png) then the image link will break. How would I make that default avatar link work with a custom path to a default avatar?


RE: Default Avatar url - Devilshakerz - 2015-08-31

You can use the actual default avatar path from settings:
$avatar = $mybb->settings['bburl'] . '/' . $mybb->settings['useravatar'];



RE: Default Avatar url - Leefish - 2015-08-31

Perfect, thank you very much Smile


RE: Default Avatar url - Euan T - 2015-08-31

Also, if you're using 1.8, you can make things even easier using MyBB::get_asset_url():

$avatar = htmlspecialchars_unj($mybb->get_asset_url($mybb->settings['useravatar']));

This will also take into account CDN settings and such.


RE: Default Avatar url - Destroy666 - 2015-09-02

Or, even simplier and properly scaled, use format_avatar() in 1.8 which was made exactly for this:
$avatar = format_avatar($referral['avatar'], $referral['avatardimensions']]); // also select avatardimensions column in your query, you can provide 3rd argument for max dimensions other than default
echo $avatar['image']; // src
echo $avatar['width_height']; // width and height attributes