1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Changing Avatar Urls

Discussion in 'XenForo Development Discussions' started by pldcanfly, Oct 7, 2013.

  1. pldcanfly

    pldcanfly Member


    for a heavily bridged forum I need to replace the avatars with ones I fetch from our login-service.

    We want to keep the standart Xen-Foro-Avatars (custom, gravatar) and just replace the default one with the corresponding avatar for the user.

    My main problem is that I can't manage to find the function to extend/override that handles <xen:avatar>.

    Could you please give me a hint at this?


    PS: XenForo: 1.2.1
  2. Chris D

    Chris D XenForo Developer Staff Member

    You'll probably need to override it as it is a static function...

    But check out: XenForo/Template/Helper/Core.php

    There's a function pertaining to custom avatars, gravatar avatars and I believe default avatars.
    pldcanfly likes this.
  3. pldcanfly

    pldcanfly Member

    I feel silly now... I wondered why my listener on load_class didn't work and your mentioning of "static" triggered my brain to work properly.

    Thanks. You were right.

    ( XenForo/Template/Helper/Core.php => _getDefaultAvatarUrl() )
    Chris D likes this.
  4. Nobita.Kun

    Nobita.Kun Well-Known Member

    For Template_Helper_Core You must using init_dependencies for extending ;)
  5. Chris D

    Chris D XenForo Developer Staff Member

    You still cannot extend existing functions in that class.

    You can override helper functions in init_dependencies because you can modify the XenForo_Template_Helper_Core::$helpers array to replace the existing functions (or add new ones).

    Furthermore, you can't override or extend a function such as _getDefaultAvatarUrl because that is just a static function called by the helper function.
    Marcus and pldcanfly like this.
  6. pldcanfly

    pldcanfly Member

    That means the best solution will to override it in $helpers and use the original source code to maintain the standart-behaviour. At least it is a lot cleaner then hacking it in the core itself.
    Chris D likes this.
  7. Slind

    Slind Active Member

    @pldcanfly Could you make your code public, please? I would like to use it too. :)
  8. pldcanfly

    pldcanfly Member

    I went with hacking it (_getDefaultAvatar() -> library/xenforo/templates/helper/core.php) since time was an issue.
  9. Slind

    Slind Active Member

    So you changed the core.php and didn't created a external change?
  10. pldcanfly

    pldcanfly Member

    Yes, but I will start working today or tomorrow on making this properly since the "hack" was just to cut time :). I will post how I did it when i'm finished.
  11. Slind

    Slind Active Member

    Okay, thanks.
  12. Slind

    Slind Active Member

  13. creativeforge

    creativeforge Active Member

    Sometimes we find the answer to our questions in an oblique way! I created my own "default avatar" images, but saved them in jpg, as for some reason the pngs were too heavy. I just didn't know how to change the link to them, but found in the core.php file the png extension, which I changed to jpg, and bingo!

    Thanks Chris!

Share This Page