XF 1.2 Conditional to say "if default avatar"

jdeg

Active member
Is there a conditional that I can use everywhere an avatar is displayed to say if default (or if custom) avatar, do this....
 
This is how I would write that function:
PHP:
    protected static function _getDefaultAvatarUrl(array $user, $size)
    {
/*
        if (!isset($user['gender']))
        {
            $user['gender'] = '';
        }

        switch ($user['gender'])
        {
            case 'male':
            case 'female':
                $gender = $user['gender'] . '_';
                break;

            default:
                $gender = '';
                break;
        }
*/
// custom
        if (!isset($user['customFields']['gender']))
        {
            $user = self::_getModelFromCache('XenForo_Model_User')->getFullUserById($user['user_id']);
            $user['customFields'] = (!empty($user['custom_fields']) ? @unserialize($user['custom_fields']) : array());
        }

        $gender = '';
        $customFields = $user['customFields'];
        if (key_exists('gender', $customFields))
                $gender = strtolower($customFields['gender']);
       
        if ($gender)
             $gender .= '_';
// end custom

        if (!$imagePath = self::styleProperty('imagePath'))
        {
            $imagePath = 'styles/default';
        }

        return "{$imagePath}/xenforo/avatars/avatar_{$gender}{$size}.png";
    }
 
still the same, very strange

would it have something to do with the line in thread_list_item being <xen:avatar user="$thread" size="s" img="true" />
 
Regarding $thread, that is why you check for and if necessary fetch the user's custom fields.
It works for me so perhaps I just don't understand what it is you are trying to achieve.
What avatar should that user in the thread list have?

Is the following correct?

- This only applies to users with no custom avatar.
- You wish to ignore the default gender avatars and instead display your own according to the gender custom user field.
- If the gender custom field was never set (user never selected an option) you wish to display the usual default avatar (Question mark one).

If the above is correct and it still does not work for you I will require exact information on how to replicate your custom user field that you created, as well as, the exact names and extensions of your custom avatars.
 
Top Bottom