QUICK NEWS

{NEW} - A new css video is up.

{OLD} - New video courtesy of Skhilled, Thanks for posting it up.

Video of the moment:


Internal Links

SMF Sites

Quick Info

Default avatar

Started by lesmond, Nov 19, 2020, 12:22 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

lesmond

I want to be able to use my own default avatar on a custom theme, not the normal avatar that comes shipped with SMF.

this is the one I wanted to change, but only to show in a custom theme.


and use this instead


Is there an easy way to do this?

The only person who got all his work done by Friday was Robinson Crusoe

Bigguy

Edit that image and change the name on it and re-upload it.
"It's the American dream....cause ya have to be asleep to believe it." - George Carlin

lesmond

Quote from: Bigguy on Nov 19, 2020, 12:25 PMEdit that image and change the name on it and re-upload it.
But that will show on all themes, i only want it on a custom theme.

The only person who got all his work done by Friday was Robinson Crusoe

Bigguy

Make the custom theme and inside that you make the folder for the image, where ever that is, I think the avatars folder ? If you rename it to something else and then change change the name in the code then it will only show on the custom theme.
"It's the American dream....cause ya have to be asleep to believe it." - George Carlin

SychO

easiest way would be to use an integration function (hook)

so create a hooks.php file, put it inside a directory called "src" inside of your theme directory

<?php// has to be a unique function name to avoid conflicts with other mods// so something like authorName_themeName_somethingfunction authorName_themeName_something($image){    global $modSettings, $settings;    if ($image === $modSettings['avatar_url'] . '/default.png')    {        $image = $settings['images_url'] . '/default_avatar.png';    }}

and in index.template.php of the theme, at the end of the template_init function

require_once __DIR__.'/src/hooks.php';
add_integration_function('integrate_set_avatar_data', 'authorName_themeName_something', false);

Now you just have to add inside of the images folder, an image by the name of default_avatar.png

I haven't tested any of the code however so, expect potential syntax issues.

lesmond

Thanks SychO :rgton   Didn't work, knowing me I done it wrong :emb  :dontknow

This is what I added to index_template
function template_init()
{
global $settings, $txt;

/* $context, $options and $txt may be available for use, but may not be fully populated yet. */

require_once __DIR__.'/src/hooks.php';
add_integration_function('integrate_set_avatar_data', 'lesmond_christmas_default', false);

and the hooks.php I placed in a src directory
<?php// has to be a unique function name to avoid conflicts with other mods// so something like authorName_themeName_somethingfunction lesmond_christmas_default($image){    global $modSettings, $settings;    if ($image === $modSettings['avatar_url'] . '/default.png')    {        $image = $settings['images_url'] . '/default_avatar.png';    }}

And placed the image in images directory

The only person who got all his work done by Friday was Robinson Crusoe

SychO

do you get any errors at all ? does the forum work fine ?

lesmond

Quote from: SychO on Nov 19, 2020, 04:12 PMdo you get any errors at all ? does the forum work fine ?

No errors, forums working fine too.

This is a fresh SMF 2.1 RC3 from GH if that makes any difference.

The only person who got all his work done by Friday was Robinson Crusoe

SychO

yea then I need to test it, I must be missing something in the logic there.

SychO

right, looking at the code now, it unfortunately would not work, because the smf codebase is inconsistent and does not use a single function to get the avatar, there is code repetition.

too bad, wanted to do this in my themes as well.

lesmond

No worries @SychO thanks mate  :rgton

The only person who got all his work done by Friday was Robinson Crusoe

lesmond

It would only work until members changed there to own avatar anyway, would have been a nice touch.

The only person who got all his work done by Friday was Robinson Crusoe